FOP-2999: Rollback after checking next page

git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@1886916 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/fop-core/src/main/java/org/apache/fop/fo/pagination/PageSequence.java b/fop-core/src/main/java/org/apache/fop/fo/pagination/PageSequence.java
index 3f82e68..79955ff 100644
--- a/fop-core/src/main/java/org/apache/fop/fo/pagination/PageSequence.java
+++ b/fop-core/src/main/java/org/apache/fop/fo/pagination/PageSequence.java
@@ -542,4 +542,10 @@
     public List<ChangeBar> getClonedChangeBarList() {
         return new LinkedList<ChangeBar>(changeBarList);
     }
+
+    public void setOnlyTryInfinite(boolean b) {
+        if (pageSequenceMaster != null) {
+            pageSequenceMaster.onlyTryInfinite = b;
+        }
+    }
 }
diff --git a/fop-core/src/main/java/org/apache/fop/fo/pagination/PageSequenceMaster.java b/fop-core/src/main/java/org/apache/fop/fo/pagination/PageSequenceMaster.java
index f218e43..b9840e0 100644
--- a/fop-core/src/main/java/org/apache/fop/fo/pagination/PageSequenceMaster.java
+++ b/fop-core/src/main/java/org/apache/fop/fo/pagination/PageSequenceMaster.java
@@ -49,6 +49,7 @@
     private SubSequenceSpecifier currentSubSequence;
     private int currentSubSequenceNumber = -1;
     private BlockLevelEventProducer blockLevelEventProducer;
+    protected boolean onlyTryInfinite;
 
     // The terminology may be confusing. A 'page-sequence-master' consists
     // of a sequence of what the XSL spec refers to as
@@ -199,6 +200,9 @@
                                                     boolean isBlankPage,
                                                     String mainFlowName)
                                                       throws PageProductionException {
+        if (onlyTryInfinite && currentSubSequence != null && !currentSubSequence.isInfinite()) {
+            throw new PageProductionException("Limited to infinite");
+        }
         if (currentSubSequence == null) {
             currentSubSequence = getNextSubSequence();
             if (currentSubSequence == null) {
diff --git a/fop-core/src/main/java/org/apache/fop/layoutmgr/PageProvider.java b/fop-core/src/main/java/org/apache/fop/layoutmgr/PageProvider.java
index 3c3409c..266a7d9 100644
--- a/fop-core/src/main/java/org/apache/fop/layoutmgr/PageProvider.java
+++ b/fop-core/src/main/java/org/apache/fop/layoutmgr/PageProvider.java
@@ -28,6 +28,7 @@
 import org.apache.fop.area.BodyRegion;
 import org.apache.fop.area.PageViewport;
 import org.apache.fop.fo.Constants;
+import org.apache.fop.fo.pagination.PageProductionException;
 import org.apache.fop.fo.pagination.PageSequence;
 import org.apache.fop.fo.pagination.Region;
 import org.apache.fop.fo.pagination.RegionBody;
@@ -192,7 +193,9 @@
             colIndex -= columnCount;
             pageIndex++;
             page = getPage(false, pageIndex, RELTO_CURRENT_ELEMENT_LIST);
-            columnCount = page.getPageViewport().getCurrentSpan().getColumnCount();
+            if (page.getPageViewport().getPage() != null) {
+                columnCount = page.getPageViewport().getCurrentSpan().getColumnCount();
+            }
         } while (colIndex >= columnCount);
         return new Column(page, pageIndex, colIndex, columnCount);
     }
@@ -316,7 +319,8 @@
             log.debug("blank condition doesn't match. Replacing PageViewport.");
             replace = true;
         }
-        if (page.getPageViewport().getCurrentSpan().getColumnCount() == 1
+        if (page.getPageViewport().getPage() != null
+                && page.getPageViewport().getCurrentSpan().getColumnCount() == 1
                 && !this.spanAllForCurrentElementList) {
             RegionBody rb = (RegionBody)page.getSimplePageMaster().getRegion(Region.FO_REGION_BODY);
             int colCount = rb.getColumnCount();
@@ -394,13 +398,27 @@
     }
 
     public int getCurrentIPD() {
+        if (startPageOfCurrentElementList == 0) {
+            return -1;
+        }
         Page page = getPageFromColumnIndex(startColumnOfCurrentElementList);
         return page.getPageViewport().getBodyRegion().getColumnIPD();
     }
 
     public int getNextIPD() {
-        Page page = getPageFromColumnIndex(startColumnOfCurrentElementList + 1);
-        return page.getPageViewport().getBodyRegion().getColumnIPD();
+        pageSeq.setOnlyTryInfinite(true);
+        try {
+            int oldSize = cachedPages.size();
+            Page page = getPageFromColumnIndex(startColumnOfCurrentElementList + 1);
+            if (oldSize != cachedPages.size()) {
+                cachedPages.remove(cachedPages.size() - 1);
+            }
+            return page.getPageViewport().getBodyRegion().getColumnIPD();
+        } catch (PageProductionException e) {
+            return getCurrentIPD();
+        } finally {
+            pageSeq.setOnlyTryInfinite(false);
+        }
     }
 
     public int getCurrentColumnCount() {
diff --git a/fop-core/src/main/java/org/apache/fop/layoutmgr/list/ListItemLayoutManager.java b/fop-core/src/main/java/org/apache/fop/layoutmgr/list/ListItemLayoutManager.java
index d079824..ffc4e7c 100644
--- a/fop-core/src/main/java/org/apache/fop/layoutmgr/list/ListItemLayoutManager.java
+++ b/fop-core/src/main/java/org/apache/fop/layoutmgr/list/ListItemLayoutManager.java
@@ -492,6 +492,9 @@
     private boolean isChangingIPD(LayoutManager lm) {
         PageProvider pageProvider = lm.getPSLM().getPageProvider();
         int currentIPD = pageProvider.getCurrentIPD();
+        if (currentIPD == -1) {
+            return false;
+        }
         int nextIPD = pageProvider.getNextIPD();
         return nextIPD != currentIPD;
     }
diff --git a/fop/test/layoutengine/standard-testcases/flow_changing-ipd_list3.xml b/fop/test/layoutengine/standard-testcases/flow_changing-ipd_list3.xml
new file mode 100644
index 0000000..4b2b408
--- /dev/null
+++ b/fop/test/layoutengine/standard-testcases/flow_changing-ipd_list3.xml
@@ -0,0 +1,378 @@
+<?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 that blocks of texts are re-laid out after a change of the flow ipd.
+    </p>
+  </info>
+  <fo>
+<fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format" xmlns:fox="http://xmlgraphics.apache.org/fop/extensions">
+  <fo:layout-master-set>
+    <fo:simple-page-master master-name="PrimaryPage" page-width="11in" page-height="8.5in" margin-bottom="0.25in" margin-right="0.25in" margin-top="0.25in" margin-left="0.25in">
+      <fo:region-body margin-bottom="1in" margin-right="0.5in" margin-top="1.6in" margin-left="0.5in" region-name="PrimaryPageBody" background-color="yellow"/>
+
+    </fo:simple-page-master>
+
+    <fo:page-sequence-master master-name="PrimaryPages">
+      <fo:repeatable-page-master-reference master-reference="PrimaryPage" maximum-repeats="2"/>
+    </fo:page-sequence-master>
+
+  </fo:layout-master-set>
+  <fo:page-sequence format="1" id="th_default_sequence1" initial-page-number="auto" force-page-count="auto" master-reference="PrimaryPages">
+
+    <fo:flow flow-name="PrimaryPageBody">
+      <fo:block>
+        <fo:block font-size="18pt">
+          <fo:leader/>
+        </fo:block>
+        <fo:block font-size="18pt">
+          <fo:leader/>
+        </fo:block>
+        <fo:block font-size="18pt">
+          <fo:leader/>
+        </fo:block>
+        <fo:block font-size="40pt" color="#0095DA">Small Group</fo:block>
+        <fo:block font-size="40pt" color="#0095DA">health insurance</fo:block>
+        <fo:block>
+          <fo:leader/>
+        </fo:block>
+        <fo:block font-size="18pt" color="#0095DA">For the business of:</fo:block>
+        <fo:block>
+          <fo:leader/>
+        </fo:block>
+        <fo:block font-size="18pt">EC Logistics LLC</fo:block>
+        <fo:block font-size="18pt" />
+        <fo:block>
+          <fo:leader/>
+        </fo:block>
+        <fo:block font-size="12pt">
+          <fo:inline color="#0095DA">Effective Date:</fo:inline> 02/01/2021</fo:block>
+        <fo:block>
+          <fo:leader/>
+        </fo:block>
+        <fo:block font-size="9pt" padding-after="3pt">
+          <fo:inline font-weight="bold">Prepared by:</fo:inline>
+          <fo:inline text-transform="capitalize">wb underwriting</fo:inline>
+        </fo:block>
+        <fo:block font-size="9pt" padding-after="3pt">02/10/2021</fo:block>
+        <fo:block font-size="9pt" padding-after="3pt">(800) 869-6989</fo:block>
+        <fo:block font-size="26pt" color="#0095DA">
+          <fo:leader/>
+          <fo:block break-before="page"/>Success!</fo:block>
+        <fo:block font-size="16pt">EC Logistics LLC is now enrolled.</fo:block>
+        <fo:block font-size="12pt">
+          <fo:leader/>
+        </fo:block>
+        <fo:block font-size="9pt" padding-after="3pt">We’ve put together tips and information, as well as a roster of enrolled members (with member ID included) and final rates for your records.</fo:block>
+        <fo:block font-size="9pt" padding-after="3pt">
+          <fo:leader/>
+        </fo:block>
+        <fo:table table-layout="fixed" width="100%">
+          <fo:table-column column-width="proportional-column-width(45)" column-number="1"/>
+          <fo:table-column column-width="proportional-column-width(5)" column-number="2"/>
+          <fo:table-column column-width="proportional-column-width(45)" column-number="3"/>
+          <fo:table-column column-width="proportional-column-width(5)" column-number="4"/>
+          <fo:table-body>
+            <fo:table-row>
+              <fo:table-cell>
+                <fo:block>
+                  <fo:block font-size="9pt" padding-after="3pt">
+                    <fo:inline font-weight="bold">About group enrollment timing</fo:inline>
+                  </fo:block>
+                </fo:block>
+              </fo:table-cell>
+              <fo:table-cell>
+                <fo:block>
+                  <fo:block>
+                    <fo:leader/>
+                  </fo:block>
+                </fo:block>
+              </fo:table-cell>
+              <fo:table-cell>
+                <fo:block>
+                  <fo:block font-size="9pt" padding-after="3pt">
+                    <fo:inline font-weight="bold">About member benefits</fo:inline>
+                  </fo:block>
+                </fo:block>
+              </fo:table-cell>
+              <fo:table-cell>
+                <fo:block>
+                  <fo:block font-size="9pt" padding-after="3pt">
+                    <fo:leader/>
+                  </fo:block>
+                </fo:block>
+              </fo:table-cell>
+            </fo:table-row>
+            <fo:table-row>
+              <fo:table-cell>
+                <fo:block>
+                  <fo:list-block font-size="9pt" line-height="10pt">
+                    <fo:list-item>
+                      <fo:list-item-label font-size="10pt">
+                        <fo:block>•</fo:block>
+                      </fo:list-item-label>
+                      <fo:list-item-body start-indent="body-start()">
+                        <fo:block>This group will appear in <fo:inline color="#0095DA">Broker Connection</fo:inline> after the group effective date.</fo:block>
+                      </fo:list-item-body>
+                    </fo:list-item>
+                  </fo:list-block>
+                  <fo:list-block font-size="9pt" line-height="10pt">
+                    <fo:list-item>
+                      <fo:list-item-label font-size="10pt">
+                        <fo:block>•</fo:block>
+                      </fo:list-item-label>
+                      <fo:list-item-body start-indent="body-start()">
+                        <fo:block>This group will appear in <fo:inline color="#0095DA">Employer Connection</fo:inline> Plus after the first month’s billing statement has been generated, which generally occurs by the 14th business day of the month.</fo:block>
+                      </fo:list-item-body>
+                    </fo:list-item>
+                  </fo:list-block>
+                </fo:block>
+              </fo:table-cell>
+              <fo:table-cell>
+                <fo:block>
+                  <fo:block>
+                    <fo:leader/>
+                  </fo:block>
+                </fo:block>
+              </fo:table-cell>
+              <fo:table-cell>
+                <fo:block>
+                  <fo:list-block font-size="9pt" line-height="10pt">
+                    <fo:list-item>
+                      <fo:list-item-label font-size="10pt">
+                        <fo:block>•</fo:block>
+                      </fo:list-item-label>
+                      <fo:list-item-body start-indent="body-start()">
+                        <fo:block>Members can use our Find a Doctor flier to learn how to search for doctors/specialists/facilities</fo:block>
+                      </fo:list-item-body>
+                    </fo:list-item>
+                  </fo:list-block>
+                  <fo:list-block font-size="9pt" line-height="10pt">
+                    <fo:list-item>
+                      <fo:list-item-label font-size="10pt">
+                        <fo:block>•</fo:block>
+                      </fo:list-item-label>
+                      <fo:list-item-body start-indent="body-start()">
+                        <fo:block>Members can access care 24/7 via phone or video consultations with Teladoc</fo:block>
+                      </fo:list-item-body>
+                    </fo:list-item>
+                  </fo:list-block>
+                  <fo:list-block font-size="9pt" line-height="10pt">
+                    <fo:list-item>
+                      <fo:list-item-label font-size="10pt">
+                        <fo:block>•</fo:block>
+                      </fo:list-item-label>
+                      <fo:list-item-body start-indent="body-start()">
+                        <fo:block>For access to Pharmacy Benefits, members must use the plan- specific alpha prefix with their member ID number.</fo:block>
+                      </fo:list-item-body>
+                    </fo:list-item>
+                  </fo:list-block>
+                </fo:block>
+              </fo:table-cell>
+              <fo:table-cell>
+                <fo:block>
+                  <fo:block>
+                    <fo:leader/>
+                  </fo:block>
+                </fo:block>
+              </fo:table-cell>
+            </fo:table-row>
+            <fo:table-row>
+              <fo:table-cell>
+                <fo:block>
+                  <fo:block>
+                    <fo:leader/>
+                  </fo:block>
+                </fo:block>
+              </fo:table-cell>
+              <fo:table-cell>
+                <fo:block>
+                  <fo:block>
+                    <fo:leader/>
+                  </fo:block>
+                </fo:block>
+              </fo:table-cell>
+              <fo:table-cell>
+                <fo:block>
+                  <fo:block>
+                    <fo:leader/>
+                  </fo:block>
+                </fo:block>
+              </fo:table-cell>
+              <fo:table-cell>
+                <fo:block>
+                  <fo:block>
+                    <fo:leader/>
+                  </fo:block>
+                </fo:block>
+              </fo:table-cell>
+            </fo:table-row>
+            <fo:table-row height="0.502708325783412cm">
+              <fo:table-cell>
+                <fo:block>
+                  <fo:block font-size="9pt" padding-after="3pt">
+                    <fo:inline font-weight="bold">About member enrollment information and next steps</fo:inline>
+                  </fo:block>
+                </fo:block>
+              </fo:table-cell>
+              <fo:table-cell>
+                <fo:block>
+                  <fo:block>
+                    <fo:leader/>
+                  </fo:block>
+                </fo:block>
+              </fo:table-cell>
+              <fo:table-cell>
+                <fo:block>
+                  <fo:block font-size="9pt" padding-after="3pt">
+                    <fo:inline font-weight="bold">See examples below:</fo:inline>
+                  </fo:block>
+                </fo:block>
+              </fo:table-cell>
+              <fo:table-cell>
+                <fo:block>
+                  <fo:block font-size="9pt" padding-after="3pt">
+                    <fo:leader/>
+                  </fo:block>
+                </fo:block>
+              </fo:table-cell>
+            </fo:table-row>
+            <fo:table-row>
+              <fo:table-cell>
+                <fo:block>
+                  <fo:list-block font-size="9pt" line-height="10pt">
+                    <fo:list-item>
+                      <fo:list-item-label font-size="10pt">
+                        <fo:block>•</fo:block>
+                      </fo:list-item-label>
+                      <fo:list-item-body start-indent="body-start()">
+                        <fo:block>Identification cards should arrive in approximately 7 to10 business days at each subscriber’s home.</fo:block>
+                      </fo:list-item-body>
+                    </fo:list-item>
+                  </fo:list-block>
+                  <fo:list-block font-size="9pt" line-height="10pt">
+                    <fo:list-item>
+                      <fo:list-item-label font-size="10pt">
+                        <fo:block>•</fo:block>
+                      </fo:list-item-label>
+                      <fo:list-item-body start-indent="body-start()">
+                        <fo:block>Access to ID card via our mobile app is available within 24 to 48 hours.</fo:block>
+                      </fo:list-item-body>
+                    </fo:list-item>
+                  </fo:list-block>
+                  <fo:list-block font-size="9pt" line-height="10pt">
+                    <fo:list-item>
+                      <fo:list-item-label font-size="10pt">
+                        <fo:block>•</fo:block>
+                      </fo:list-item-label>
+                      <fo:list-item-body start-indent="body-start()">
+                        <fo:block>Temporary ID cards can be printed after members register online.</fo:block>
+                      </fo:list-item-body>
+                    </fo:list-item>
+                  </fo:list-block>
+                  <fo:list-block font-size="9pt" line-height="10pt">
+                    <fo:list-item>
+                      <fo:list-item-label font-size="10pt">
+                        <fo:block>•</fo:block>
+                      </fo:list-item-label>
+                      <fo:list-item-body start-indent="body-start()">
+                        <fo:block>Members should appear in our Pharmacy Eligibility system within 24 to 48 hours.</fo:block>
+                      </fo:list-item-body>
+                    </fo:list-item>
+                  </fo:list-block>
+                  <fo:list-block font-size="9pt" line-height="10pt">
+                    <fo:list-item>
+                      <fo:list-item-label font-size="10pt">
+                        <fo:block>•</fo:block>
+                      </fo:list-item-label>
+                      <fo:list-item-body start-indent="body-start()">
+                        <fo:block>Eligibility can be verified prior to receipt of ID cards by calling <fo:inline font-weight="bold">(888) 319-5999</fo:inline>.</fo:block>
+                      </fo:list-item-body>
+                    </fo:list-item>
+                  </fo:list-block>
+                </fo:block>
+              </fo:table-cell>
+              <fo:table-cell>
+                <fo:block>
+                  <fo:block>
+                    <fo:leader/>
+                  </fo:block>
+                </fo:block>
+              </fo:table-cell>
+              <fo:table-cell>
+                <fo:block>
+                  <fo:block font-size="9pt" padding-after="3pt">XEH - HMO members (example: XEH999999999)</fo:block>
+                  <fo:block font-size="9pt" padding-after="3pt">XEA - PPO members (example: XEA999999999)</fo:block>
+                  <fo:block font-size="9pt" padding-after="3pt">XNK - Tandem PPO members (example: XNK999999999)</fo:block>
+                  <fo:block font-size="9pt" padding-after="3pt">Pharmacy services also requires the BIN # 600428 and PCN numbers: PCN # 01910000 - for Commercial HMO and PPO</fo:block>
+                  <fo:block font-size="9pt" padding-after="3pt">PCN # 02960000 – for Commercial HAS</fo:block>
+                </fo:block>
+              </fo:table-cell>
+              <fo:table-cell>
+                <fo:block>
+                  <fo:block font-size="9pt" padding-after="3pt">
+                    <fo:leader/>
+                  </fo:block>
+                </fo:block>
+              </fo:table-cell>
+            </fo:table-row>
+            <fo:table-row>
+              <fo:table-cell>
+                <fo:block>
+                  <fo:block>
+                    <fo:leader/>
+                  </fo:block>
+                </fo:block>
+              </fo:table-cell>
+              <fo:table-cell>
+                <fo:block>
+                  <fo:block>
+                    <fo:leader/>
+                  </fo:block>
+                </fo:block>
+              </fo:table-cell>
+              <fo:table-cell>
+                <fo:block>
+                  <fo:block>
+                    <fo:leader/>
+                  </fo:block>
+                </fo:block>
+              </fo:table-cell>
+              <fo:table-cell>
+                <fo:block>
+                  <fo:block>
+                    <fo:leader/>
+                  </fo:block>
+                </fo:block>
+              </fo:table-cell>
+            </fo:table-row>
+          </fo:table-body>
+        </fo:table>
+      </fo:block>
+      <fo:block id="TH_LastPage"/>
+    </fo:flow>
+  </fo:page-sequence>
+</fo:root>
+  </fo>
+  <checks>
+    <eval expected="Small" xpath="//pageViewport[1]//flow/block//word"/>
+    <eval expected="Success!" xpath="//pageViewport[2]//flow/block//word"/>
+  </checks> 
+</testcase>
diff --git a/fop/test/layoutengine/standard-testcases/flow_changing-ipd_list4.xml b/fop/test/layoutengine/standard-testcases/flow_changing-ipd_list4.xml
new file mode 100644
index 0000000..ee04d1b
--- /dev/null
+++ b/fop/test/layoutengine/standard-testcases/flow_changing-ipd_list4.xml
@@ -0,0 +1,71 @@
+<?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 that blocks of texts are re-laid out after a change of the flow ipd.
+    </p>
+  </info>
+  <fo>
+<fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format" xmlns:fox="http://xmlgraphics.apache.org/fop/extensions" font-family="Helvetica">
+  <fo:layout-master-set>
+    <fo:simple-page-master master-name="PageFront" page-width="210mm" page-height="297mm">
+      <fo:region-body margin-bottom="22mm" margin-right="80mm" margin-top="100mm" margin-left="20mm" region-name="letterPageBody"/>
+    </fo:simple-page-master>
+    <fo:simple-page-master master-name="PageCont" page-width="210mm" page-height="297mm">
+      <fo:region-body margin-right="30mm" margin-bottom="30mm" margin-top="12mm" margin-left="20mm" region-name="letterPageBody"/>
+    </fo:simple-page-master>
+    <fo:page-sequence-master master-name="LetterPages">
+      <fo:repeatable-page-master-alternatives>
+        <fo:conditional-page-master-reference page-position="first" master-reference="PageFront"/>
+        <fo:conditional-page-master-reference page-position="rest" master-reference="PageCont"/>
+        <fo:conditional-page-master-reference page-position="last" master-reference="PageCont"/>
+      </fo:repeatable-page-master-alternatives>
+    </fo:page-sequence-master>
+  </fo:layout-master-set>
+  <fo:page-sequence format="1" id="th_default_sequence1" force-page-count="even" initial-page-number="auto" master-reference="LetterPages">
+    <fo:flow flow-name="letterPageBody">
+      <fo:block-container height="41mm" overflow="hidden" width="55mm" top="45mm" left="20mm" absolute-position="fixed">
+        <fo:block>
+          <fo:block font-family="Arial" font-size="10pt" line-height="13pt">Mr les</fo:block>
+        </fo:block>
+      </fo:block-container>
+      <fo:block>
+        <fo:list-block start-indent="1pt" space-before="1pt" keep-together.within-page="always" keep-with-previous.within-page="always">
+          <fo:list-item font-family="Arial" font-size="10pt" space-before="2px">
+            <fo:list-item-label font-family="ZapfDingbats" font-size="4pt" line-height="10pt">
+              <fo:block>
+                <fo:inline>●</fo:inline>
+              </fo:block>
+            </fo:list-item-label>
+            <fo:list-item-body font-family="Arial" font-size="10pt" start-indent="4mm" space-before="2px">
+              <fo:block>Cover summary (all your key policy information)</fo:block>
+            </fo:list-item-body>
+          </fo:list-item>
+        </fo:list-block>
+      </fo:block>
+    </fo:flow>
+  </fo:page-sequence>
+</fo:root>
+  </fo>
+  <checks>
+    <eval expected="Mr" xpath="//pageViewport[1]//flow/block//word"/>
+    <eval expected="" xpath="//pageViewport[2]//flow/block//word"/>
+  </checks> 
+</testcase>
diff --git a/fop/test/layoutengine/standard-testcases/flow_changing-ipd_list5.xml b/fop/test/layoutengine/standard-testcases/flow_changing-ipd_list5.xml
new file mode 100644
index 0000000..7041ce4
--- /dev/null
+++ b/fop/test/layoutengine/standard-testcases/flow_changing-ipd_list5.xml
@@ -0,0 +1,69 @@
+<?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 that blocks of texts are re-laid out after a change of the flow ipd.
+    </p>
+  </info>
+  <fo>
+<fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format" xmlns:fox="http://xmlgraphics.apache.org/fop/extensions">
+  <fo:layout-master-set>
+    <fo:simple-page-master master-name="PageFront" page-width="8.5in" page-height="11in" margin-bottom="0.2in" margin-right="0.5in" margin-top="0.5in" margin-left="0.5in">
+      <fo:region-body region-name="letterPageBody1" margin-bottom="0.3in" margin-right="0pt" margin-top="1.6in" margin-left="0pt"/>
+      <fo:region-before region-name="Header" extent="10.8in"/>
+    </fo:simple-page-master>
+    <fo:simple-page-master master-name="PageRest" page-width="8.5in" page-height="11in" margin-bottom="0.1in" margin-right="0.5in" margin-top="0.5in" margin-left="0.5in">
+      <fo:region-body margin-bottom="0.1in" margin-right="0pt" margin-top="0.4in" margin-left="0pt" column-gap="0.5in" column-count="2" region-name="letterPageBody"/>
+    </fo:simple-page-master>
+    <fo:page-sequence-master master-name="LetterPages">
+      <fo:repeatable-page-master-alternatives>
+        <fo:conditional-page-master-reference page-position="first" master-reference="PageFront"/>
+        <fo:conditional-page-master-reference page-position="rest" master-reference="PageRest"/>
+        <fo:conditional-page-master-reference page-position="last" master-reference="PageRest"/>
+      </fo:repeatable-page-master-alternatives>
+    </fo:page-sequence-master>
+  </fo:layout-master-set>
+  <fo:page-sequence format="1" id="th_default_sequence1" initial-page-number="auto" force-page-count="auto" master-reference="LetterPages">
+    <fo:static-content flow-name="Header">
+      <fo:block>
+        <fo:list-block font-family="Helvetica" font-size="10pt" line-height="11pt">
+          <fo:list-item space-after="5pt" space-before="5pt" line-height="11pt">
+            <fo:list-item-label font-family="Helvetica" font-size="10pt" text-indent="0.1in" line-height="11pt">
+              <fo:block>1.</fo:block>
+            </fo:list-item-label>
+            <fo:list-item-body start-indent="0.325in" font-family="Helvetica" font-size="10pt" line-height="11pt">
+              <fo:block>
+                <fo:inline font-weight="bold">Your </fo:inline>name is the name on the attached declaration.</fo:block>
+            </fo:list-item-body>
+          </fo:list-item>
+        </fo:list-block>
+      </fo:block>
+    </fo:static-content>
+    <fo:flow flow-name="letterPageBody">
+      <fo:block>AGREEMENT</fo:block>
+    </fo:flow>
+  </fo:page-sequence>
+</fo:root>
+  </fo>
+  <checks>
+    <eval expected="" xpath="//pageViewport[1]//flow/block//word"/>
+    <eval expected="AGREEMENT" xpath="//pageViewport[2]//flow/block//word"/>
+  </checks> 
+</testcase>
diff --git a/fop/test/layoutengine/standard-testcases/flow_changing-ipd_list6.xml b/fop/test/layoutengine/standard-testcases/flow_changing-ipd_list6.xml
new file mode 100644
index 0000000..bd420c3
--- /dev/null
+++ b/fop/test/layoutengine/standard-testcases/flow_changing-ipd_list6.xml
@@ -0,0 +1,121 @@
+<?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 that blocks of texts are re-laid out after a change of the flow ipd.
+    </p>
+  </info>
+  <fo>
+<fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format" xmlns:fox="http://xmlgraphics.apache.org/fop/extensions">
+  <fo:layout-master-set>
+    <fo:simple-page-master master-name="FirstPage" page-width="210mm" page-height="297mm">
+      <fo:region-body margin-bottom="20mm" margin-right="74mm" margin-top="90mm" margin-left="8mm" region-name="Body"/>      
+    </fo:simple-page-master>
+    <fo:simple-page-master master-name="SecondPage" page-width="210mm" page-height="297mm">
+      <fo:region-body margin-right="8mm" margin-top="8mm" margin-left="8mm" region-name="Body"/>
+      <fo:region-start precedence="true" region-name="SecondPage" extent="180mm"/>
+    </fo:simple-page-master>
+    <fo:page-sequence-master master-name="AnnualStatement">
+      <fo:repeatable-page-master-reference maximum-repeats="1" master-reference="FirstPage"/>
+      <fo:repeatable-page-master-reference maximum-repeats="1" master-reference="SecondPage"/>
+    </fo:page-sequence-master>
+  </fo:layout-master-set>
+  <fo:page-sequence format="1" id="th_default_sequence1" initial-page-number="auto" force-page-count="end-on-even" master-reference="AnnualStatement">   
+    <fo:static-content flow-name="SecondPage">
+      <fo:block-container height="281mm" margin-top="8mm">
+        <fo:block-container width="194mm" margin-right="8mm" margin-left="8mm">          
+          <fo:block>           
+            <fo:table table-layout="fixed" width="100%">
+              <fo:table-column column-width="proportional-column-width(49.5)" column-number="1"/>
+              <fo:table-column column-width="proportional-column-width(2.5)" column-number="2"/>
+              <fo:table-column column-width="proportional-column-width(48)" column-number="3"/>
+              <fo:table-body>
+                <fo:table-row>
+                  <fo:table-cell>
+                    <fo:block>
+                      <fo:block>
+                      
+                        <fo:table table-layout="fixed" width="100%">
+                          <fo:table-column column-width="proportional-column-width(4.16666666666667)" column-number="1"/>
+                          <fo:table-column column-width="proportional-column-width(62.5)" column-number="2"/>
+                          <fo:table-column column-width="proportional-column-width(4.16666666666667)" column-number="3"/>
+                          <fo:table-column column-width="proportional-column-width(29.1666666666667)" column-number="4"/>
+                          <fo:table-body>
+                            <fo:table-row>
+                              <fo:table-cell keep-together.within-page="always" padding-bottom="1mm" padding-left="2mm" padding-right="2mm" padding-top="1mm" background-color="#FFE7E1">
+                                <fo:block>
+                                  <fo:block color="#333333"  font-size="10pt" keep-together.within-page="always" keep-with-next.within-page="always" line-height="13pt">
+                                    <fo:leader/>
+                                  </fo:block>
+                                </fo:block>
+                              </fo:table-cell>
+                              <fo:table-cell keep-together.within-page="always" padding-bottom="1mm" padding-left="2mm" padding-right="2mm" padding-top="1mm" background-color="#FFE7E1">
+                                <fo:block>
+                                  <fo:list-block color="#ff5c39"  font-size="9pt" keep-together.within-page="always" keep-with-next.within-page="always" line-height="11pt">
+                                    <fo:list-item>
+                                      <fo:list-item-label>
+                                        <fo:block>·</fo:block>
+                                      </fo:list-item-label>
+                                      <fo:list-item-body color="#333333"  font-size="10pt" keep-together.within-page="always" keep-with-next.within-page="always" line-height="13pt" margin-left="5mm">
+                                        <fo:block>
+                                          <fo:inline color="#8031a7">London charges</fo:inline>
+                                        </fo:block>
+                                      </fo:list-item-body>
+                                    </fo:list-item>
+                                  </fo:list-block>
+                                </fo:block>
+                              </fo:table-cell>
+                            </fo:table-row>
+                          </fo:table-body>
+                        </fo:table>
+                      </fo:block>
+                    </fo:block>
+                  </fo:table-cell>
+                  <fo:table-cell>
+                    <fo:block>
+                      <fo:block>
+                        <fo:leader/>
+                      </fo:block>
+                    </fo:block>
+                  </fo:table-cell>
+                  <fo:table-cell>
+                    <fo:block>
+                      <fo:block>
+                      </fo:block>
+                    </fo:block>
+                  </fo:table-cell>
+                </fo:table-row>
+              </fo:table-body>
+            </fo:table>
+          </fo:block>
+        </fo:block-container>
+      </fo:block-container>
+    </fo:static-content>   
+    <fo:flow flow-name="Body">
+      <fo:block></fo:block>
+    </fo:flow>
+  </fo:page-sequence>  
+</fo:root>
+  </fo>
+  <checks>
+    <eval expected="" xpath="//pageViewport[1]//block//word"/>
+    <eval expected="·" xpath="//pageViewport[2]//block//word"/>
+  </checks> 
+</testcase>