You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pdfbox.apache.org by ti...@apache.org on 2014/11/06 22:40:31 UTC

svn commit: r1637228 - /pdfbox/branches/1.8/preflight/src/main/java/org/apache/pdfbox/preflight/parser/PreflightParser.java

Author: tilman
Date: Thu Nov  6 21:40:30 2014
New Revision: 1637228

URL: http://svn.apache.org/r1637228
Log:
PDFBOX-2173: Nullpointer when validating empty file, by John Hewson

Modified:
    pdfbox/branches/1.8/preflight/src/main/java/org/apache/pdfbox/preflight/parser/PreflightParser.java

Modified: pdfbox/branches/1.8/preflight/src/main/java/org/apache/pdfbox/preflight/parser/PreflightParser.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/1.8/preflight/src/main/java/org/apache/pdfbox/preflight/parser/PreflightParser.java?rev=1637228&r1=1637227&r2=1637228&view=diff
==============================================================================
--- pdfbox/branches/1.8/preflight/src/main/java/org/apache/pdfbox/preflight/parser/PreflightParser.java (original)
+++ pdfbox/branches/1.8/preflight/src/main/java/org/apache/pdfbox/preflight/parser/PreflightParser.java Thu Nov  6 21:40:30 2014
@@ -294,32 +294,34 @@ public class PreflightParser extends Non
             }
 
             String secondLine = reader.readLine();
-            byte[] secondLineAsBytes = secondLine.getBytes(encoding.name());
-            if (secondLine != null && secondLineAsBytes.length >= 5)
+            if (secondLine != null)
             {
-                for (int i = 0; i < secondLineAsBytes.length; ++i)
+                byte[] secondLineAsBytes = secondLine.getBytes(encoding.name());
+                if (secondLineAsBytes.length >= 5)
                 {
-                    byte b = secondLineAsBytes[i];
-                    if (i == 0 && ((char) b != '%'))
+                    for (int i = 0; i < secondLineAsBytes.length; ++i)
                     {
-                        addValidationError(new ValidationError(PreflightConstants.ERROR_SYNTAX_HEADER,
-                                "Second line must contains at least 4 bytes greater than 127"));
-                        break;
-                    }
-                    else if (i > 0 && ((b & 0xFF) < 0x80))
-                    {
-                        addValidationError(new ValidationError(PreflightConstants.ERROR_SYNTAX_HEADER,
-                                "Second line must contains at least 4 bytes greater than 127"));
-                        break;
+                        byte b = secondLineAsBytes[i];
+                        if (i == 0 && ((char) b != '%'))
+                        {
+                            addValidationError(new ValidationError(PreflightConstants.ERROR_SYNTAX_HEADER,
+                                    "Second line must contains at least 4 bytes greater than 127"));
+                            break;
+                        }
+                        else if (i > 0 && ((b & 0xFF) < 0x80))
+                        {
+                            addValidationError(new ValidationError(PreflightConstants.ERROR_SYNTAX_HEADER,
+                                    "Second line must contains at least 4 bytes greater than 127"));
+                            break;
+                        }
                     }
                 }
+                else
+                {
+                    addValidationError(new ValidationError(PreflightConstants.ERROR_SYNTAX_HEADER,
+                            "Second line must contains at least 4 bytes greater than 127"));
+                }
             }
-            else
-            {
-                addValidationError(new ValidationError(PreflightConstants.ERROR_SYNTAX_HEADER,
-                        "Second line must contains at least 4 bytes greater than 127"));
-            }
-
         }
         catch (IOException e)
         {