Bug 43237 - IndexOutOfBoundsException
Summary: IndexOutOfBoundsException
Status: NEW
Alias: None
Product: Fop - Now in Jira
Classification: Unclassified
Component: general (show other bugs)
Version: 0.94
Hardware: All other
: P3 normal
Target Milestone: ---
Assignee: fop-dev
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2007-08-29 05:05 UTC by Hussein Shafie
Modified: 2012-04-07 01:51 UTC (History)
2 users (show)



Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Hussein Shafie 2007-08-29 05:05:06 UTC
This IndexOutOfBoundsException:

===============================================================
java.lang.IndexOutOfBoundsException: Index: 1, Size: 1
        at java.util.ArrayList.RangeCheck(ArrayList.java:508)
        at java.util.ArrayList.get(ArrayList.java:320)
        at
org.apache.fop.layoutmgr.PageBreakingAlgorithm.computeDemerits(PageBreakingAlgorithm.java:644)
        at
org.apache.fop.layoutmgr.BreakingAlgorithm.considerLegalBreak(BreakingAlgorithm.java:737)
        at
org.apache.fop.layoutmgr.PageBreakingAlgorithm.considerLegalBreak(PageBreakingAlgorithm.java:309)
        at
org.apache.fop.layoutmgr.BreakingAlgorithm.findBreakingPoints(BreakingAlgorithm.java:485)
        at
org.apache.fop.layoutmgr.BreakingAlgorithm.findBreakingPoints(BreakingAlgorithm.java:403)
        at
org.apache.fop.layoutmgr.AbstractBreaker.doLayout(AbstractBreaker.java:338)
        at
org.apache.fop.layoutmgr.AbstractBreaker.doLayout(AbstractBreaker.java:263)
        at
org.apache.fop.layoutmgr.PageSequenceLayoutManager.activateLayout(PageSequenceLayoutManager.java:144)
        at
org.apache.fop.area.AreaTreeHandler.endPageSequence(AreaTreeHandler.java:233)
        at
org.apache.fop.fo.pagination.PageSequence.endOfNode(PageSequence.java:145)
        at
org.apache.fop.fo.FOTreeBuilder$MainFOHandler.endElement(FOTreeBuilder.java:378)
        at org.apache.fop.fo.FOTreeBuilder.endElement(FOTreeBuilder.java:194)
===============================================================

Workaround:

  In src/java/org/apache/fop/layoutmgr/PageBreakingAlgorithm.java, replace:

===============================================================
if (footnotesPending) {
    if (footnoteListIndex < footnotesList.size() - 1) {
        // add demerits for the deferred footnotes
        demerits += (footnotesList.size() - 1 - footnoteListIndex) 
                        * deferredFootnoteDemerits;
    }
    if (footnoteElementIndex 
            < ((LinkedList) footnotesList.get(footnoteListIndex)).size() - 1) {
        // add demerits for the footnote split between pages
        demerits += splitFootnoteDemerits;
    }
}
===============================================================
 
  by:

===============================================================
if (footnotesPending) {
    int footnotesListSize = footnotesList.size();
    if (footnoteListIndex < footnotesListSize - 1) {
        // add demerits for the deferred footnotes
        demerits += (footnotesListSize - 1 - footnoteListIndex) 
                        * deferredFootnoteDemerits;
    }
    if (footnoteListIndex < footnotesListSize &&
        footnoteElementIndex 
            < ((LinkedList) footnotesList.get(footnoteListIndex)).size() - 1) {
        // add demerits for the footnote split between pages
        demerits += splitFootnoteDemerits;
    }
}
===============================================================
Comment 1 Vincent Hennebert 2007-08-30 08:16:13 UTC
Hi,

Can you please attach to this bug a short FO file showing the exception? It
might serve as a testcase.

Thanks,
Vincent
Comment 2 Hussein Shafie 2007-08-30 09:04:54 UTC
I'm really sorry but I don't have a short XSL-FO file which may be used to
easily reproduce this problem. I just have a large one, moreover full of
fo:external-graphic.

I presumed that by reading the code pinpointed by the stack trace, you could
guess   in which conditions such IndexOutOfBoundsException occurs.

Comment 3 Rainer Maximini 2007-09-04 05:50:53 UTC
I have exact the same problem here, but also only in a very large XSL-FO file.
The described workaround does not works correct because the first footnote is
always missing.
Comment 4 Dieter Laslov 2007-09-18 09:24:08 UTC
I did an other workaround, that seems to work: I changed 

==========================================
    private void resetFootnotes(LinkedList elementLists) {
        for (int i = 0; i < elementLists.size(); i++) {
            LinkedList removedList = (LinkedList)
footnotesList.remove(footnotesList.size() - 1);
            lengthList.remove(lengthList.size() - 1);

            // update totalFootnotesLength
            if (lengthList.size() > 0) {
                totalFootnotesLength = ((Integer)
lengthList.get(lengthList.size() - 1)).intValue();
            } else {
                totalFootnotesLength = 0;
            }
        }
        // update footnotesPending;
        if (footnotesList.size() == 0) {
            footnotesPending = false;
        }
    }
=================================================

to 

=================================================
    private void resetFootnotes(LinkedList elementLists) {
        for (int i = 0; i < elementLists.size(); i++) {
            LinkedList removedList = (LinkedList)
footnotesList.remove(footnotesList.size() - 1);
            lengthList.remove(lengthList.size() - 1);

            // update totalFootnotesLength
            if (lengthList.size() > 0) {
                totalFootnotesLength = ((Integer)
lengthList.get(lengthList.size() - 1)).intValue();
            } else {
                totalFootnotesLength = 0;
            }
        }
        footnoteListIndex = footnotesList.size() - 1;
        // update footnotesPending;
        if (footnotesList.size() == 0) {
            footnotesPending = false;
        }
    }
=================================================

(difference is only adding one line)

BTW: my FO is very huge too (about 1.7 MB)
Comment 5 Johans Marvin Taboada Villca 2007-09-25 12:53:39 UTC
Got into same issue, my scenario:
  * svn-book.fo (Subversion Book), FO file obtained with Xalan-J-2.7.0 (from
fop-0.94 distro), not xsltproc. Testcase candidate? (I tried to attach .fo file
without results)
Comment 6 Glenn Adams 2012-04-07 01:41:25 UTC
resetting P2 open bugs to P3 pending further review