[ https://issues.apache.org/jira/browse/PDFBOX-2173?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14200983#comment-14200983 ]
ASF subversion and git services commented on PDFBOX-2173: --------------------------------------------------------- Commit 1637228 from [~tilman] in branch 'pdfbox/branches/1.8' [ https://svn.apache.org/r1637228 ] PDFBOX-2173: Nullpointer when validating empty file, by John Hewson > Nullpointer when validating empty file > -------------------------------------- > > Key: PDFBOX-2173 > URL: https://issues.apache.org/jira/browse/PDFBOX-2173 > Project: PDFBox > Issue Type: Bug > Components: Preflight > Affects Versions: 1.8.6 > Reporter: Per-Olof Widström > Priority: Minor > Fix For: 2.0.0 > > > I am validating a PDF and I am getting a NullpointerException when the > filesize is 0 bytes. I looked at the code and saw a small misstake, and > therefore I am reporting this. I use version 1.8.6 > {code:java|title=PreflightParser.java} > protected void checkPdfHeader() > { > //[snip] > String secondLine = reader.readLine(); > byte[] secondLineAsBytes = secondLine.getBytes(encoding.name()); > if (secondLine != null && secondLineAsBytes.length >= 5) > //[snip] > } > {code} > As you can see {{secondLineAsBytes}} is checked for null value, but only > after being called once. > {code} > java.lang.NullPointerException > at > org.apache.pdfbox.preflight.parser.PreflightParser.checkPdfHeader(PreflightParser.java:297) > at > org.apache.pdfbox.preflight.parser.PreflightParser.parse(PreflightParser.java:195) > at > org.apache.pdfbox.preflight.parser.PreflightParser.parse(PreflightParser.java:180) > at > org.apache.pdfbox.preflight.parser.PreflightParser.parse(PreflightParser.java:168) > {code} > h4. Workaround > Before validating, check the filesize, if it is larger than 0. > h4. How to reproduce > Try to validate with an empty file. -- This message was sent by Atlassian JIRA (v6.3.4#6332)