flyingsaucerproject / flyingsaucer

XML/XHTML and CSS 2.1 renderer in pure Java
Other
2.02k stars 564 forks source link

multiple tbody tags with pagination lead to ArrayIndexOutOfBoundsException since 9.9.1 #379

Closed theodor-franke closed 2 months ago

theodor-franke commented 2 months ago

When you try to generate a PDF from this HTML we get a ArrayIndexOutOfBoundsException. This only happens since version 9.9.1 version, the versions before worked fine.

<html>
<head>
    <style>
        table{
            -fs-table-paginate: paginate;
        }
        tbody {
           page-break-inside: avoid;
        }
    </style>
</head>

<body>
    <table>
        <thead>
            <tr>
                <th>name</th>
                <th>age</th>
            </tr>
        </thead>
        <tbody>
            <tr>
                <td rowspan="2">Rowspan</td>
                <td height="300px">Normal</td>
            </tr>
            <tr>
                <td height="300px">normal</td>
            </tr>
        </tbody>
        <tbody>
            <tr>
                <td rowspan="2">Rowspan</td>
                <td height="300px">Normal</td>
            </tr>
            <tr>
                <td height="300px">normal</td>
            </tr>
        </tbody>
    </table>
</body>
</html>

I Think that #358 caused some side-effects. Full stack-trace:

Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: Index 3 out of bounds for length 3
    at org.xhtmlrenderer.newtable.TableSectionBox.setCellWidths(TableSectionBox.java:217)
    at org.xhtmlrenderer.newtable.TableSectionBox.layoutChildren(TableSectionBox.java:136)
    at org.xhtmlrenderer.render.BlockBox.layout(BlockBox.java:856)
    at org.xhtmlrenderer.newtable.TableSectionBox.layout(TableSectionBox.java:281)
    at org.xhtmlrenderer.render.BlockBox.layout(BlockBox.java:785)
    at org.xhtmlrenderer.layout.BlockBoxing.layoutBlockChild0(BlockBoxing.java:318)
    at org.xhtmlrenderer.layout.BlockBoxing.layoutBlockChild(BlockBoxing.java:296)
    at org.xhtmlrenderer.layout.BlockBoxing.layoutContent(BlockBoxing.java:102)
    at org.xhtmlrenderer.render.BlockBox.layoutChildren(BlockBox.java:976)
    at org.xhtmlrenderer.newtable.TableBox.layoutChildren(TableBox.java:320)
    at org.xhtmlrenderer.render.BlockBox.layout(BlockBox.java:856)
    at org.xhtmlrenderer.render.BlockBox.layout(BlockBox.java:785)
    at org.xhtmlrenderer.newtable.TableBox.layoutTable(TableBox.java:285)
    at org.xhtmlrenderer.newtable.TableBox.layout(TableBox.java:244)
    at org.xhtmlrenderer.layout.BlockBoxing.layoutBlockChild0(BlockBoxing.java:318)
    at org.xhtmlrenderer.layout.BlockBoxing.layoutBlockChild(BlockBoxing.java:296)
    at org.xhtmlrenderer.layout.BlockBoxing.layoutContent(BlockBoxing.java:89)
    at org.xhtmlrenderer.render.BlockBox.layoutChildren(BlockBox.java:976)
    at org.xhtmlrenderer.render.BlockBox.layout(BlockBox.java:856)
    at org.xhtmlrenderer.render.BlockBox.layout(BlockBox.java:785)
    at org.xhtmlrenderer.layout.BlockBoxing.layoutBlockChild0(BlockBoxing.java:318)
    at org.xhtmlrenderer.layout.BlockBoxing.layoutBlockChild(BlockBoxing.java:296)
    at org.xhtmlrenderer.layout.BlockBoxing.layoutContent(BlockBoxing.java:89)
    at org.xhtmlrenderer.render.BlockBox.layoutChildren(BlockBox.java:976)
    at org.xhtmlrenderer.render.BlockBox.layout(BlockBox.java:856)
    at org.xhtmlrenderer.render.BlockBox.layout(BlockBox.java:785)
    at org.xhtmlrenderer.pdf.ITextRenderer.layout(ITextRenderer.java:275)
    at main.main(main.java:45)
asolntsev commented 2 months ago

Hi @syluna . Can you please investigate this issue? I confirm it was caused by PR https://github.com/flyingsaucerproject/flyingsaucer/pull/358

Also, I created a test that easily reproduces this problem: https://github.com/flyingsaucerproject/flyingsaucer/pull/380

asolntsev commented 2 months ago

Good morning @syluna ! Could you please advice how to fix this problem? Otherwise I will have to revert PR #358 (because I have no idea how to fix the issue - there is very complex code...).

syluna commented 2 months ago

Hi @asolntsev, I look for this this weekend, and back when I have a solution otherwise revert the PR

asolntsev commented 2 months ago

@syluna Hi. Have you got a chance to review the problem?

syluna commented 2 months ago

@asolntsev Not from now please revert PR and I redo this when I fix it. Thanks

asolntsev commented 2 months ago

@syluna Thank you! Currently, I've reverted PR https://github.com/flyingsaucerproject/flyingsaucer/pull/358 to release a fix.

Hoping you will get back with a solution ;)

syluna commented 2 months ago

Sure thanks !