Bug 65366 - NullPointerException in XDDFDataSourcesFactory
Summary: NullPointerException in XDDFDataSourcesFactory
Status: NEW
Alias: None
Product: POI
Classification: Unclassified
Component: XDDF (show other bugs)
Version: 5.0.0-FINAL
Hardware: PC All
: P2 normal (vote)
Target Milestone: ---
Assignee: POI Developers List
Depends on:
Reported: 2021-06-08 08:32 UTC by monnomiznogoud
Modified: 2021-06-10 08:21 UTC (History)
0 users

File containing the model chart (23.17 KB, application/vnd.openxmlformats-officedocument.spreadsheetml.sheet)
2021-06-08 08:32 UTC, monnomiznogoud

Note You need to log in before you can comment on or make changes to this bug.
Description monnomiznogoud 2021-06-08 08:32:13 UTC
Created attachment 37894 [details]
File containing the model chart

categoryDS.getNumRef() and valuesDS.getNumRef() are null in the case of an existing .xlsx file containing a copied chart for which the links were removed by the user.
Result: when reading this file, copying the model chart in order to use it in another file, we have a NullPointerException in XDDFDataSourcesFactory when calling xssfChart.getChartSeries()

            CTChartSpace chartSpace = ChartSpaceDocument.Factory.parse(modelChart.getPackagePart().getInputStream(), POIXMLTypeLoader.DEFAULT_XML_OPTIONS).getChartSpace(); 
            CTChart ctc = chartSpace.getChart();
            final CreationHelper helper = wb.getCreationHelper();
            final XSSFClientAnchor anchor = (XSSFClientAnchor) helper.createClientAnchor();
            anchor.setCol2(x + w - 1);
            anchor.setRow2(y + h - 1);
            xssfChart = drawing.createChart(anchor);
              existingSeries = xssfChart.getChartSeries();

	at org.apache.poi.xddf.usermodel.chart.XDDFDataSourcesFactory$1.<init>(XDDFDataSourcesFactory.java:28)
	at org.apache.poi.xddf.usermodel.chart.XDDFDataSourcesFactory.fromDataSource(XDDFDataSourcesFactory.java:27)
	at org.apache.poi.xddf.usermodel.chart.XDDFScatterChartData$Series.<init>(XDDFScatterChartData.java:125)
	at org.apache.poi.xddf.usermodel.chart.XDDFScatterChartData.<init>(XDDFScatterChartData.java:46)
	at org.apache.poi.xddf.usermodel.chart.XDDFChart.getChartSeries(XDDFChart.java:488)

The solution was easy on my part: I copied XDDFDataSourcesFactory.java and modified it, checking if getNumRef() returns null everywhere and handling the resulting null category and values CTNumData
Comment 1 PJ Fanning 2021-06-08 19:19:38 UTC
I suspect this is also fixed - see https://github.com/apache/poi/blob/trunk/poi-ooxml/src/main/java/org/apache/poi/xddf/usermodel/chart/XDDFDataSourcesFactory.java#L48

The next release should happen in the next month or 2.
Comment 2 monnomiznogoud 2021-06-10 08:21:36 UTC
It seems to be the case. Thanks.