[ 
https://issues.apache.org/jira/browse/PDFBOX-2834?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

John Hewson updated PDFBOX-2834:
--------------------------------
    Description: 
Inside this method an Object (the result of 
dictionary.getItem(COSName.DEST_OUTPUT_PROFILE) method call) is casted to 
COSStream, but it can be also a COSObject containing COSStream which leads to 
class cast exception.

{code}
public COSStream getDestOutputIntent()
{
     return (COSStream) dictionary.getItem(COSName.DEST_OUTPUT_PROFILE);
}
{code}

Possible solutions :
1) Check class instance and handle them in proper way*
2) Usage of visitor pattern

*{code}
public COSStream getDestOutputIntent()
{
        final COSBase item = dictionary.getItem(COSName.DEST_OUTPUT_PROFILE);
        return getDestOutputIntent(item);
}

private COSStream getDestOutputIntent(COSBase object) {
        if (object instanceof COSStream) {
            return (COSStream) object;
        } else if (object instanceof COSObject) {
            return getDestOutputIntent(((COSObject) object).getObject());
        } else {
            return null;
        }
}
{code}

  was:
Inside this method an Object (the result of 
dictionary.getItem(COSName.DEST_OUTPUT_PROFILE) method call) is casted to 
COSStream, but it can be also a COSObject containing COSStream which leads to 
class cast exception.

public COSStream getDestOutputIntent()
{
     return (COSStream) dictionary.getItem(COSName.DEST_OUTPUT_PROFILE);
}

Possible solutions :
1) Check class instance and handle them in proper way*
2) Usage of visitor pattern

*public COSStream getDestOutputIntent()
{
        final COSBase item = dictionary.getItem(COSName.DEST_OUTPUT_PROFILE);
        return getDestOutputIntent(item);
}


private COSStream getDestOutputIntent(COSBase object) {
        if (object instanceof COSStream) {
            return (COSStream) object;
        } else if (object instanceof COSObject) {
            return getDestOutputIntent(((COSObject) object).getObject());
        } else {
            return null;
        }
}


> Violation in PDOutputIntent.getDestOutputProfile() method
> ---------------------------------------------------------
>
>                 Key: PDFBOX-2834
>                 URL: https://issues.apache.org/jira/browse/PDFBOX-2834
>             Project: PDFBox
>          Issue Type: Bug
>          Components: PDModel
>    Affects Versions: 2.0.0
>         Environment: Windows 7, jdk 1.7.0_51
>            Reporter: Evgeniy Muravitskiy
>            Assignee: Andreas Lehmkühler
>             Fix For: 2.0.0
>
>         Attachments: OutputIntentTest.pdf
>
>
> Inside this method an Object (the result of 
> dictionary.getItem(COSName.DEST_OUTPUT_PROFILE) method call) is casted to 
> COSStream, but it can be also a COSObject containing COSStream which leads to 
> class cast exception.
> {code}
> public COSStream getDestOutputIntent()
> {
>      return (COSStream) dictionary.getItem(COSName.DEST_OUTPUT_PROFILE);
> }
> {code}
> Possible solutions :
> 1) Check class instance and handle them in proper way*
> 2) Usage of visitor pattern
> *{code}
> public COSStream getDestOutputIntent()
> {
>         final COSBase item = dictionary.getItem(COSName.DEST_OUTPUT_PROFILE);
>         return getDestOutputIntent(item);
> }
> private COSStream getDestOutputIntent(COSBase object) {
>         if (object instanceof COSStream) {
>             return (COSStream) object;
>         } else if (object instanceof COSObject) {
>             return getDestOutputIntent(((COSObject) object).getObject());
>         } else {
>             return null;
>         }
> }
> {code}



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to