]> source.dussan.org Git - xmlgraphics-fop.git/commitdiff
Add fix for NPE related to FOP-3098 by Jeremias Maerki
authorChris Bowditch <cbowditch@apache.org>
Mon, 13 Mar 2023 10:56:44 +0000 (10:56 +0000)
committerChris Bowditch <cbowditch@apache.org>
Mon, 13 Mar 2023 10:56:44 +0000 (10:56 +0000)
fop-core/src/main/java/org/apache/fop/layoutmgr/list/ListItemLayoutManager.java
fop/test/layoutengine/standard-testcases/list-block_npe_bug_empty_2nd_block.xml [new file with mode: 0644]

index a15e58ad469ea87b5248f476470b0bb7dcfd48c0..9473db66c2655249ad64b1c9b839d46fe53cf5ff 100644 (file)
@@ -498,6 +498,7 @@ public class ListItemLayoutManager extends SpacedBorderedPaddedBlockLayoutManage
                         && position.getLM() instanceof ListItemContentLayoutManager) {
                     position = position.getPosition();
                     if (position != null
+                            && position.getPosition() != null
                             && position.getLM() instanceof BlockLayoutManager) {
                         retval = new LeafPosition(position.getPosition().getLM(), 0);
                     }
diff --git a/fop/test/layoutengine/standard-testcases/list-block_npe_bug_empty_2nd_block.xml b/fop/test/layoutengine/standard-testcases/list-block_npe_bug_empty_2nd_block.xml
new file mode 100644 (file)
index 0000000..65547c8
--- /dev/null
@@ -0,0 +1,57 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  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.
+-->
+<!-- $Id$ -->
+<testcase>
+  <info>
+    <p>
+      This test checks triggered a NPE in
+      in ListItemLayoutManager.extractBlock() on a null Position due to an empty second block.
+    </p>
+  </info>
+  <fo>
+    <root xmlns="http://www.w3.org/1999/XSL/Format">
+    
+      <layout-master-set>
+        <simple-page-master master-name="a4" page-height="29.7cm" page-width="21cm">
+          <region-body/>
+        </simple-page-master>
+      </layout-master-set>
+      
+      <page-sequence master-reference="a4">
+        <flow flow-name="xsl-region-body">
+          <list-block provisional-distance-between-starts="20mm" provisional-label-separation="4mm">
+            <list-item>
+              <list-item-label end-indent="label-end()">
+                <block>1.1.</block>
+              </list-item-label>
+              <list-item-body start-indent="body-start()">
+                <block>blah blah</block>
+                <block/> <!-- Empty block here caused NPE in ListItemLayoutManager.extractBlock() on a null Position -->
+              </list-item-body>
+            </list-item>
+          </list-block>
+        </flow>
+      </page-sequence>
+    </root>
+  </fo>
+  <checks>
+    <eval expected="1" xpath="count(//pageViewport)"/>
+    <eval expected="1.1." xpath="//pageViewport[@nr=1]/descendant::text[1]"/>
+  </checks>
+</testcase>
+