From: Vincent Hennebert Date: Tue, 4 Sep 2012 22:25:49 +0000 (+0000) Subject: Bugzilla #53598: avoid IllegalArgumentException by setting the breakClass field in... X-Git-Tag: fop-2_0~295 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=10e39f016aa7dceacb24fdd8258c7e67e44f1495;p=xmlgraphics-fop.git Bugzilla #53598: avoid IllegalArgumentException by setting the breakClass field in BreakElement to a legal default value Patch by Robert Meyer, applied with some modifications git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@1380923 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/src/java/org/apache/fop/layoutmgr/BreakElement.java b/src/java/org/apache/fop/layoutmgr/BreakElement.java index 77e7f140b..f3f173d8c 100644 --- a/src/java/org/apache/fop/layoutmgr/BreakElement.java +++ b/src/java/org/apache/fop/layoutmgr/BreakElement.java @@ -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 UnresolvedListElement { 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 UnresolvedListElement { * @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 UnresolvedListElement { 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 UnresolvedListElement { * * @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 */ diff --git a/status.xml b/status.xml index adde62df3..3e73488fb 100644 --- a/status.xml +++ b/status.xml @@ -62,6 +62,10 @@ documents. Example: the fix of marks layering will be such a case when it's done. --> + + Always set the breakClass field to a legal value in BreakElement, so as to avoid + IllegalArgumentExceptions in other parts of the code. + Restored support for break-before on fo:table. diff --git a/test/java/org/apache/fop/layoutmgr/BreakElementTestCase.java b/test/java/org/apache/fop/layoutmgr/BreakElementTestCase.java new file mode 100644 index 000000000..c836bce7c --- /dev/null +++ b/test/java/org/apache/fop/layoutmgr/BreakElementTestCase.java @@ -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()); + } +}