Author: vhennebert
Date: Tue Sep  4 22:25:49 2012
New Revision: 1380923

URL: http://svn.apache.org/viewvc?rev=1380923&view=rev
Log:
Bugzilla #53598: avoid IllegalArgumentException by setting the breakClass field 
in BreakElement to a legal default value
Patch by Robert Meyer, applied with some modifications

Added:
    
xmlgraphics/fop/trunk/test/java/org/apache/fop/layoutmgr/BreakElementTestCase.java
   (with props)
Modified:
    xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/BreakElement.java
    xmlgraphics/fop/trunk/status.xml

Modified: 
xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/BreakElement.java
URL: 
http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/BreakElement.java?rev=1380923&r1=1380922&r2=1380923&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/BreakElement.java 
(original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/BreakElement.java 
Tue Sep  4 22:25:49 2012
@@ -21,6 +21,8 @@ package org.apache.fop.layoutmgr;
 
 import java.util.List;
 
+import org.apache.fop.fo.Constants;
+
 /**
  * This class represents an unresolved break possibility.
  */
@@ -28,7 +30,7 @@ public class BreakElement extends Unreso
 
     private int penaltyWidth;
     private int penaltyValue;
-    private int breakClass = -1;
+    private int breakClass;
     private List pendingBeforeMarks;
     private List pendingAfterMarks;
 
@@ -39,7 +41,7 @@ public class BreakElement extends Unreso
      * @param context the layout context which contains the pending 
conditional elements
      */
     public BreakElement(Position position, int penaltyValue, LayoutContext 
context) {
-        this(position, penaltyValue, -1, context);
+        this(position, penaltyValue, Constants.EN_AUTO, context);
     }
 
     /**
@@ -80,7 +82,7 @@ public class BreakElement extends Unreso
         super(position);
         this.penaltyWidth = penaltyWidth;
         this.penaltyValue = penaltyValue;
-        this.breakClass = breakClass;
+        setBreakClass(breakClass);
         this.pendingBeforeMarks = context.getPendingBeforeMarks();
         this.pendingAfterMarks = context.getPendingAfterMarks();
     }
@@ -142,13 +144,24 @@ public class BreakElement extends Unreso
      *
      * @param breakClass one of
      *   {@link org.apache.fop.fo.Constants#EN_AUTO},
+     *   {@link org.apache.fop.fo.Constants#EN_LINE},
      *   {@link org.apache.fop.fo.Constants#EN_COLUMN},
      *   {@link org.apache.fop.fo.Constants#EN_PAGE},
      *   {@link org.apache.fop.fo.Constants#EN_EVEN_PAGE},
      *   {@link org.apache.fop.fo.Constants#EN_ODD_PAGE}.
      */
     public void setBreakClass(int breakClass) {
-        this.breakClass = breakClass;
+        switch (breakClass) {
+        case Constants.EN_AUTO:
+        case Constants.EN_LINE:
+        case Constants.EN_COLUMN:
+        case Constants.EN_PAGE:
+        case Constants.EN_EVEN_PAGE:
+        case Constants.EN_ODD_PAGE:
+            this.breakClass = breakClass;
+            break;
+        default: throw new IllegalArgumentException("Illegal value for break 
class: " + breakClass);
+        }
     }
 
     /** @return the pending border and padding elements at the before edge */

Modified: xmlgraphics/fop/trunk/status.xml
URL: 
http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/status.xml?rev=1380923&r1=1380922&r2=1380923&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/status.xml (original)
+++ xmlgraphics/fop/trunk/status.xml Tue Sep  4 22:25:49 2012
@@ -62,6 +62,10 @@
       documents. Example: the fix of marks layering will be such a case when 
it's done.
     -->
     <release version="FOP Trunk" date="TBD">
+      <action context="Layout" dev="VH" type="fix" fixes-bug="53598" 
due-to="Robert Meyer">
+        Always set the breakClass field to a legal value in BreakElement, so 
as to avoid 
+        IllegalArgumentExceptions in other parts of the code.
+      </action>
       <action context="Layout" dev="VH" type="fix" fixes-bug="45715" 
due-to="Luis Bernardo">
         Restored support for break-before on fo:table.
       </action>

Added: 
xmlgraphics/fop/trunk/test/java/org/apache/fop/layoutmgr/BreakElementTestCase.java
URL: 
http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/test/java/org/apache/fop/layoutmgr/BreakElementTestCase.java?rev=1380923&view=auto
==============================================================================
--- 
xmlgraphics/fop/trunk/test/java/org/apache/fop/layoutmgr/BreakElementTestCase.java
 (added)
+++ 
xmlgraphics/fop/trunk/test/java/org/apache/fop/layoutmgr/BreakElementTestCase.java
 Tue Sep  4 22:25:49 2012
@@ -0,0 +1,37 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.fop.layoutmgr;
+
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+
+import org.apache.fop.fo.Constants;
+
+public class BreakElementTestCase {
+
+    /**
+     * Tests that the constructor sets the break class to a valid default 
value.
+     */
+    @Test
+    public void breakClassMustBeValid() {
+        LayoutContext context = LayoutContext.newInstance();
+        BreakElement breakElement = new BreakElement(new Position(null), 0, 
context);
+        assertEquals(Constants.EN_AUTO, breakElement.getBreakClass());
+    }
+}

Propchange: 
xmlgraphics/fop/trunk/test/java/org/apache/fop/layoutmgr/BreakElementTestCase.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
xmlgraphics/fop/trunk/test/java/org/apache/fop/layoutmgr/BreakElementTestCase.java
------------------------------------------------------------------------------
    svn:keywords = Revision Id



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to