Bug 65366

Summary: NullPointerException in XDDFDataSourcesFactory
Product: POI Reporter: monnomiznogoud
Component: XDDFAssignee: POI Developers List <dev>
Status: RESOLVED INFORMATIONPROVIDED    
Severity: normal    
Priority: P2    
Version: 5.0.0-FINAL   
Target Milestone: ---   
Hardware: PC   
OS: All   
Attachments: File containing the model chart

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.setAnchorType(AnchorType.MOVE_AND_RESIZE);
            anchor.setCol1(x);
            anchor.setCol2(x + w - 1);
            anchor.setRow1(y);
            anchor.setRow2(y + h - 1);
            xssfChart = drawing.createChart(anchor);
            xssfChart.getCTChart().set(ctc);
              existingSeries = xssfChart.getChartSeries();

java.lang.NullPointerException
	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.