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/18 19:27:51 UTC

svn commit: r1640405 - /pdfbox/branches/1.8/preflight/src/main/java/org/apache/pdfbox/preflight/process/AcroFormValidationProcess.java

Author: tilman
Date: Tue Nov 18 18:27:51 2014
New Revision: 1640405

URL: http://svn.apache.org/r1640405
Log:
PDFBOX-2504: Fix ClassCastException when field children include widget annotations

Modified:
    pdfbox/branches/1.8/preflight/src/main/java/org/apache/pdfbox/preflight/process/AcroFormValidationProcess.java

Modified: pdfbox/branches/1.8/preflight/src/main/java/org/apache/pdfbox/preflight/process/AcroFormValidationProcess.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/1.8/preflight/src/main/java/org/apache/pdfbox/preflight/process/AcroFormValidationProcess.java?rev=1640405&r1=1640404&r2=1640405&view=diff
==============================================================================
--- pdfbox/branches/1.8/preflight/src/main/java/org/apache/pdfbox/preflight/process/AcroFormValidationProcess.java (original)
+++ pdfbox/branches/1.8/preflight/src/main/java/org/apache/pdfbox/preflight/process/AcroFormValidationProcess.java Tue Nov 18 18:27:51 2014
@@ -38,6 +38,8 @@ import org.apache.pdfbox.pdmodel.interac
 import org.apache.pdfbox.pdmodel.interactive.annotation.PDAnnotationWidget;
 import org.apache.pdfbox.pdmodel.interactive.form.PDAcroForm;
 import org.apache.pdfbox.pdmodel.interactive.form.PDField;
+import static org.apache.pdfbox.preflight.PreflightConfiguration.ANNOTATIONS_PROCESS;
+import static org.apache.pdfbox.preflight.PreflightConstants.ERROR_SYNTAX_BODY;
 import org.apache.pdfbox.preflight.PreflightContext;
 import org.apache.pdfbox.preflight.ValidationResult.ValidationError;
 import org.apache.pdfbox.preflight.exception.ValidationException;
@@ -90,7 +92,7 @@ public class AcroFormValidationProcess e
     }
 
     /**
-     * This function explores all fields and their children to check if the A or AA entry is present.
+     * This function explores all fields and their children to validate them.
      * 
      * @param ctx
      * @param acroForm
@@ -100,12 +102,26 @@ public class AcroFormValidationProcess e
     protected boolean exploreFields(PreflightContext ctx, List<?> lFields) throws IOException
     {
         if (lFields != null)
-        { // the list can be null is the Field doesn't have child
+        {
+            // the list can be null if the Field doesn't have children
             for (Object obj : lFields)
             {
-                if (!valideField(ctx, (PDField) obj))
+                if (obj instanceof PDField)
+                {
+                    if (!valideField(ctx, (PDField) obj))
+                    {
+                        return false;
+                    }
+                }
+                else if (obj instanceof PDAnnotationWidget)
+                {
+                    // "A field's children in the hierarchy may also include widget annotations"
+                    ContextHelper.validateElement(ctx, ((PDAnnotationWidget) obj).getDictionary(), ANNOTATIONS_PROCESS);
+                }
+                else
                 {
-                    return false;
+                    addValidationError(ctx, new ValidationError(ERROR_SYNTAX_BODY,
+                            "Field can only have fields or widget annotations as KIDS"));
                 }
             }
         }