From 5ce5fe50a74b9e3f84cabcffee46f860c86dbd47 Mon Sep 17 00:00:00 2001 From: Simon Steiner Date: Thu, 22 Apr 2021 10:45:11 +0000 Subject: [PATCH] FOP-3008: Table with linefeed-treatment may give ClassCastException git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@1889102 13f79535-47bb-0310-9956-ffa450edef68 --- .../java/org/apache/fop/fo/flow/Wrapper.java | 2 +- .../fop/layoutmgr/AreaAdditionUtil.java | 2 +- .../layoutmgr/BlockStackingLayoutManager.java | 4 +- .../fop/layoutmgr/ElementListUtils.java | 3 +- .../apache/fop/layoutmgr/KnuthPenalty.java | 4 +- .../java/org/apache/fop/util/ListUtil.java | 10 ++++ .../standard-testcases/table_linefeed.xml | 57 +++++++++++++++++++ 7 files changed, 76 insertions(+), 6 deletions(-) create mode 100644 fop/test/layoutengine/standard-testcases/table_linefeed.xml diff --git a/fop-core/src/main/java/org/apache/fop/fo/flow/Wrapper.java b/fop-core/src/main/java/org/apache/fop/fo/flow/Wrapper.java index 39f472cbb..809125088 100644 --- a/fop-core/src/main/java/org/apache/fop/fo/flow/Wrapper.java +++ b/fop-core/src/main/java/org/apache/fop/fo/flow/Wrapper.java @@ -121,7 +121,7 @@ public class Wrapper extends FObjMixed implements CommonAccessibilityHolder { while (ancestor.getNameId() == Constants.FO_WRAPPER) { ancestor = ancestor.getParent(); } - if (!(ancestor instanceof FObjMixed)) { + if (!(ancestor instanceof FObjMixed) && !child.toString().trim().isEmpty()) { invalidChildError( getLocator(), getLocalName(), diff --git a/fop-core/src/main/java/org/apache/fop/layoutmgr/AreaAdditionUtil.java b/fop-core/src/main/java/org/apache/fop/layoutmgr/AreaAdditionUtil.java index d731ab62a..e341078de 100644 --- a/fop-core/src/main/java/org/apache/fop/layoutmgr/AreaAdditionUtil.java +++ b/fop-core/src/main/java/org/apache/fop/layoutmgr/AreaAdditionUtil.java @@ -65,7 +65,7 @@ public final class AreaAdditionUtil { } lastPos = pos; } - if (pos instanceof NonLeafPosition) { + if (pos instanceof NonLeafPosition && pos.getPosition() != null) { // pos was created by a child of this FlowLM positionList.add(pos.getPosition()); lastLM = (pos.getPosition().getLM()); diff --git a/fop-core/src/main/java/org/apache/fop/layoutmgr/BlockStackingLayoutManager.java b/fop-core/src/main/java/org/apache/fop/layoutmgr/BlockStackingLayoutManager.java index 4dddbcf11..1e55edd07 100644 --- a/fop-core/src/main/java/org/apache/fop/layoutmgr/BlockStackingLayoutManager.java +++ b/fop-core/src/main/java/org/apache/fop/layoutmgr/BlockStackingLayoutManager.java @@ -535,8 +535,8 @@ public abstract class BlockStackingLayoutManager extends AbstractLayoutManager return; } - ListElement last = ListUtil.getLast(contentList); - if (last.isGlue()) { + ListElement last = ListUtil.getLastListElement(contentList); + if (last == null || last.isGlue()) { // the last element in contentList is a glue; // it is a feasible breakpoint, there is no need to add // a penalty diff --git a/fop-core/src/main/java/org/apache/fop/layoutmgr/ElementListUtils.java b/fop-core/src/main/java/org/apache/fop/layoutmgr/ElementListUtils.java index 9b964843e..3920481e7 100644 --- a/fop-core/src/main/java/org/apache/fop/layoutmgr/ElementListUtils.java +++ b/fop-core/src/main/java/org/apache/fop/layoutmgr/ElementListUtils.java @@ -178,7 +178,8 @@ public final class ElementListUtils { * @return true if the list ends with a forced break */ public static boolean endsWithForcedBreak(List elems) { - return ((ListElement) ListUtil.getLast(elems)).isForcedBreak(); + ListElement last = ListUtil.getLastListElement(elems); + return last == null || last.isForcedBreak(); } /** diff --git a/fop-core/src/main/java/org/apache/fop/layoutmgr/KnuthPenalty.java b/fop-core/src/main/java/org/apache/fop/layoutmgr/KnuthPenalty.java index 220f9c35d..c80cb389b 100644 --- a/fop-core/src/main/java/org/apache/fop/layoutmgr/KnuthPenalty.java +++ b/fop-core/src/main/java/org/apache/fop/layoutmgr/KnuthPenalty.java @@ -19,6 +19,8 @@ package org.apache.fop.layoutmgr; +import org.apache.fop.fo.Constants; + /** * An instance of this class represents information about a feasible * breaking point; it does not represent any piece of content. @@ -47,7 +49,7 @@ public class KnuthPenalty extends KnuthElement { private int penalty; private boolean penaltyFlagged; - private int breakClass = -1; + private int breakClass = Constants.EN_AUTO; /** * Create a new KnuthPenalty. diff --git a/fop-core/src/main/java/org/apache/fop/util/ListUtil.java b/fop-core/src/main/java/org/apache/fop/util/ListUtil.java index 8e88e4cbf..45af2b5c3 100644 --- a/fop-core/src/main/java/org/apache/fop/util/ListUtil.java +++ b/fop-core/src/main/java/org/apache/fop/util/ListUtil.java @@ -21,6 +21,8 @@ package org.apache.fop.util; import java.util.List; +import org.apache.fop.layoutmgr.ListElement; + /** * Provides helper functions for {@link java.util.List}. * @@ -42,6 +44,14 @@ public final class ListUtil { return list.get(list.size() - 1); } + public static ListElement getLastListElement(List list) { + Object last = getLast(list); + if (last instanceof ListElement) { + return (ListElement) last; + } + return null; + } + /** * Retrieve and remove the last element from a list. * diff --git a/fop/test/layoutengine/standard-testcases/table_linefeed.xml b/fop/test/layoutengine/standard-testcases/table_linefeed.xml new file mode 100644 index 000000000..0486e51b2 --- /dev/null +++ b/fop/test/layoutengine/standard-testcases/table_linefeed.xml @@ -0,0 +1,57 @@ + + + + + +

+ This test checks table linefeed in certain situations. +

+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
-- 2.39.5