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

Tilman Hausherr commented on PDFBOX-1756:
-----------------------------------------

I looked at one of the files, 436857.pdf, because it is small.
{code}
24.05.2014 14:07:50.169 WARN  [main] org.apache.pdfbox.cos.COSDocument:258 - 
java.lang.ClassCastException: org.apache.pdfbox.cos.COSString cannot be cast to 
org.apache.pdfbox.cos.COSName
java.lang.ClassCastException: org.apache.pdfbox.cos.COSString cannot be cast to 
org.apache.pdfbox.cos.COSName
        at 
org.apache.pdfbox.cos.COSDocument.getObjectByType(COSDocument.java:250)
        at org.apache.pdfbox.cos.COSDocument.getCatalog(COSDocument.java:506)
        at 
org.apache.pdfbox.pdfparser.NonSequentialPDFParser.initialParse(NonSequentialPDFParser.java:476)
        at 
org.apache.pdfbox.pdfparser.NonSequentialPDFParser.parse(NonSequentialPDFParser.java:751)
        at org.apache.pdfbox.pdmodel.PDDocument.loadNonSeq(PDDocument.java:1161)
        at org.apache.pdfbox.pdmodel.PDDocument.loadNonSeq(PDDocument.java:1144)
{code}
The cause of the exception is this:
{code}
/Type(General Information)
{code}
PDFBox expects a Name object, i.e. something that starts with "/", like this:
{code}
/Type/Catalog
{code}
IMHO, writing a stack trace results in fear and panic on the user side. We 
ignore the "wrong" object the search goes on, this is not even worth a warning. 
I've replaced this with a debug log instead.

It is similar for writing. doWriteObject() looks whether it reaches the 
signature. If the object isn't the wanted one, I don't see a reason to abort. 
So I inserted an instanceof check instead.

Done in the trunk in rev 1597284.

> ClassCastException CosString cannot be cast to COSName
> ------------------------------------------------------
>
>                 Key: PDFBOX-1756
>                 URL: https://issues.apache.org/jira/browse/PDFBOX-1756
>             Project: PDFBox
>          Issue Type: Bug
>          Components: Parsing
>    Affects Versions: 1.8.2
>         Environment: Ubuntu Linux & Windows 7 (both JDK6)
>            Reporter: William Palmer
>            Priority: Minor
>         Attachments: testPDF_twoAuthors.pdf
>
>
> Opening and saving a PDF causes this exception in 1.8.2:
> Exception in thread "main" java.lang.ClassCastException: 
> org.apache.pdfbox.cos.COSString cannot be cast to 
> org.apache.pdfbox.cos.COSName
>       at 
> org.apache.pdfbox.pdfwriter.COSWriter.doWriteObject(COSWriter.java:507)
>       at org.apache.pdfbox.pdfwriter.COSWriter.doWriteBody(COSWriter.java:435)
>       at 
> org.apache.pdfbox.pdfwriter.COSWriter.visitFromDocument(COSWriter.java:1122)
>       at org.apache.pdfbox.cos.COSDocument.accept(COSDocument.java:552)
>       at org.apache.pdfbox.pdfwriter.COSWriter.write(COSWriter.java:1501)
>       at org.apache.pdfbox.pdmodel.PDDocument.save(PDDocument.java:1324)
>       at org.apache.pdfbox.pdmodel.PDDocument.save(PDDocument.java:1305)
> The PDF is here: 
> http://digitalcorpora.org/corp/nps/files/govdocs1/008/008677.pdf
> Code to reproduce the exception:
> PDFParser parser = new PDFParser(new FileInputStream(new File("008677.pdf")));
> parser.parse();
> File temp = File.createTempFile("temp-", ".pdf");
> parser.getPDDocument().save(temp);
> parser.getDocument().close();



--
This message was sent by Atlassian JIRA
(v6.2#6252)

Reply via email to