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/07/29 21:08:51 UTC

svn commit: r1614460 - /pdfbox/trunk/preflight/src/main/java/org/apache/pdfbox/preflight/content/PreflightStreamEngine.java

Author: tilman
Date: Tue Jul 29 19:08:51 2014
New Revision: 1614460

URL: http://svn.apache.org/r1614460
Log:
PDFBOX-2020: avoid NPE if there is no colorspaces resource; minor code cleanup

Modified:
    pdfbox/trunk/preflight/src/main/java/org/apache/pdfbox/preflight/content/PreflightStreamEngine.java

Modified: pdfbox/trunk/preflight/src/main/java/org/apache/pdfbox/preflight/content/PreflightStreamEngine.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/preflight/src/main/java/org/apache/pdfbox/preflight/content/PreflightStreamEngine.java?rev=1614460&r1=1614459&r2=1614460&view=diff
==============================================================================
--- pdfbox/trunk/preflight/src/main/java/org/apache/pdfbox/preflight/content/PreflightStreamEngine.java (original)
+++ pdfbox/trunk/preflight/src/main/java/org/apache/pdfbox/preflight/content/PreflightStreamEngine.java Tue Jul 29 19:08:51 2014
@@ -213,6 +213,7 @@ public abstract class PreflightStreamEng
         registerOperatorProcessor("sh", stubOp);
     }
 
+    @Override
     public final void registerOperatorProcessor(String operator, OperatorProcessor op)
     {
         super.registerOperatorProcessor(operator, op);
@@ -248,7 +249,6 @@ public abstract class PreflightStreamEng
             {
                 registerError("Unexpected value '" + arguments.get(0) + "' for ri operand. ",
                         ERROR_GRAPHIC_UNEXPECTED_VALUE_FOR_KEY);
-                return;
             }
         }
     }
@@ -267,7 +267,6 @@ public abstract class PreflightStreamEng
             if (numberOfGraphicStates > MAX_GRAPHIC_STATES)
             {
                 registerError("Too many graphic states", ERROR_GRAPHIC_TOO_MANY_GRAPHIC_STATES);
-                return;
             }
         }
     }
@@ -319,13 +318,17 @@ public abstract class PreflightStreamEng
                 {
                     // The color space is unknown. Try to access the resources dictionary,
                     // the color space can be a reference.
-                    PDColorSpace pdCS = (PDColorSpace) this.getResources().getColorSpaces().get(colorSpace);
-                    if (pdCS != null)
+                    Map<String, PDColorSpace> colorSpaces = this.getResources().getColorSpaces();
+                    if (colorSpaces != null)
                     {
-                        cs = ColorSpaces.valueOf(pdCS.getName());
-                        PreflightConfiguration cfg = context.getConfig();
-                        ColorSpaceHelperFactory csFact = cfg.getColorSpaceHelperFact();
-                        csHelper = csFact.getColorSpaceHelper(context, pdCS, ColorSpaceRestriction.ONLY_DEVICE);
+                        PDColorSpace pdCS = colorSpaces.get(colorSpace);
+                        if (pdCS != null)
+                        {
+                            cs = ColorSpaces.valueOf(pdCS.getName());
+                            PreflightConfiguration cfg = context.getConfig();
+                            ColorSpaceHelperFactory csFact = cfg.getColorSpaceHelperFact();
+                            csHelper = csFact.getColorSpaceHelper(context, pdCS, ColorSpaceRestriction.ONLY_DEVICE);
+                        }
                     }
                 }
 
@@ -397,7 +400,6 @@ public abstract class PreflightStreamEng
                 // The default fill color needs an OutputIntent
                 registerError("The operator \"" + operation + "\" can't be used without Color Profile",
                         ERROR_GRAPHIC_INVALID_COLOR_SPACE_MISSING);
-                return;
             }
         }
     }
@@ -514,7 +516,7 @@ public abstract class PreflightStreamEng
             return;
         }
 
-        String colorSpaceName = null;
+        String colorSpaceName;
         if (arguments.get(0) instanceof String)
         {
             colorSpaceName = (String) arguments.get(0);