Bug 65016

Summary: Creating a chart throws IndexOutOfBoundsException
Product: POI Reporter: Dominik Stadler <dominik.stadler>
Component: XDDFAssignee: POI Developers List <dev>
Severity: major    
Priority: P2    
Version: unspecified   
Target Milestone: ---   
Hardware: PC   
OS: Linux   
Attachments: List of dates and values for a chart

Description Dominik Stadler 2020-12-20 22:03:58 UTC
Created attachment 37636 [details]
List of dates and values for a chart

The following unit-test combined with the attached sample document throws an exception.

I tried to "fix" it, but couldn't, if this is some incorrect usage of the new XDDFChart functionality, we should at least try to validate the inputs and provide a better error message.

	at org.apache.xmlbeans.impl.store.Xobj.removeElement(Xobj.java:2099)
	at org.apache.xmlbeans.impl.store.Xobj.remove_element(Xobj.java:2130)
	at org.openxmlformats.schemas.drawingml.x2006.chart.impl.CTNumDataImpl.unsetPtCount(CTNumDataImpl.java:168)
	at org.apache.poi.xddf.usermodel.chart.XDDFDataSource.fillNumericalCache(XDDFDataSource.java:84)
	at org.apache.poi.xddf.usermodel.chart.XDDFChartData$Series.plot(XDDFChartData.java:214)
	at org.apache.poi.xddf.usermodel.chart.XDDFChart.plot(XDDFChart.java:418)
	at org.apache.poi.xddf.usermodel.chart.TestXDDFChart.testException(TestXDDFChart.java:102)

    public void testException() throws IOException {
        try (XSSFWorkbook wb = XSSFTestDataSamples.openSampleWorkbook("chart20201220.xlsx")) {
            XSSFSheet splitSheet = wb.getSheet("Splits");

            XDDFChart chart = newXDDFChart();
            XDDFChartLegend legend = chart.getOrAddLegend();

            // Use a category axis for the bottom axis.
            XDDFCategoryAxis bottomAxis = chart.createCategoryAxis(AxisPosition.BOTTOM);
            XDDFValueAxis leftAxis = chart.createValueAxis(AxisPosition.LEFT);

            XDDFChartData data = chart.createData(ChartTypes.LINE, bottomAxis, leftAxis);

            // starting row 1 to include description
            XDDFNumericalDataSource<Double> xs = XDDFDataSourcesFactory.fromNumericCellRange(splitSheet,
                    new CellRangeAddress(2, 100, 0, 0));
            XDDFNumericalDataSource<Double> ys1 = XDDFDataSourcesFactory.fromNumericCellRange(splitSheet,
                    new CellRangeAddress(2, 100, 1, 1));

            data.addSeries(xs, ys1);


            try (OutputStream out = new FileOutputStream("/tmp/chart20201220.xlsx")) {
Comment 1 Dominik Stadler 2020-12-20 22:11:29 UTC
This is on the latest trunk, btw.
Comment 2 Alain Fagot Bearez 2021-01-19 03:57:42 UTC
Following pull request should fix the exception which was thrown when trying to unset an underlying XML element which was not set.


Could you check if this also fixes your use case?
Comment 3 Dominik Stadler 2021-01-19 05:45:44 UTC
This seems to fix the issue for me, Thanks!
Comment 4 Alain Fagot Bearez 2021-01-19 21:35:36 UTC
fixed by r1885700