You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@pdfbox.apache.org by "Tilman Hausherr (Jira)" <ji...@apache.org> on 2020/03/28 13:09:00 UTC

[jira] [Commented] (PDFBOX-4803) XMPSchema#getUnqualifiedArrayList throws a different exception

    [ https://issues.apache.org/jira/browse/PDFBOX-4803?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17069439#comment-17069439 ] 

Tilman Hausherr commented on PDFBOX-4803:
-----------------------------------------

I think you're right. The logic should be like this:

- programming error (passing bad parameter): IllegalArgumentException
- bad luck with data: BadFieldValueException

Sadly we can't change this in the 2.0 branch because this is a breaking change. This can only be changed for the trunk, so you'll still have to catch both, sorry about that :-(

> XMPSchema#getUnqualifiedArrayList throws a different exception
> --------------------------------------------------------------
>
>                 Key: PDFBOX-4803
>                 URL: https://issues.apache.org/jira/browse/PDFBOX-4803
>             Project: PDFBox
>          Issue Type: Bug
>            Reporter: Hao Zhong
>            Priority: Major
>
> When a property is illegal, most methods of pdfbox throw IllegalArgumentException:
> org.apache.xmpbox.schema.XMPSchema#getUnqualifiedTextProperty
> org.apache.xmpbox.schema.XMPSchema#getDateProperty
> org.apache.xmpbox.schema.XMPSchema#getBooleanProperty
> org.apache.xmpbox.schema.XMPSchema#getIntegerPropertyValue
>  
> However, the following method throws a different exception:
> org.apache.xmpbox.schema.XMPSchema#getUnqualifiedArrayList:
> {code:java}
>   public List<AbstractField> getUnqualifiedArrayList(String name) throws BadFieldValueException
>     {
>         ArrayProperty array = null;
>         for (AbstractField child : getAllProperties())
>         {
>             if (child.getPropertyName().equals(name))
>             {
>                 if (child instanceof ArrayProperty)
>                 {
>                     array = (ArrayProperty) child;
>                     break;
>                 }
>                 throw new BadFieldValueException("Property asked is not an array");
>             }
>         }
>         if (array != null)
>         {
>             return new ArrayList<>(array.getContainer().getAllProperties());
>         }
>         return null;
>     }
> {code}
> As a result, my code fails to catch its exception. Shall the methods throw the same exception for the same reason? For me, BadFieldValueException is even more informative than IllegalArgumentException.



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@pdfbox.apache.org
For additional commands, e-mail: dev-help@pdfbox.apache.org