I have excel having chart with primary and secondary axis. I am to retrieve the chart Axis details to update the maximum value. I am having XSSFSheet instance after loading the given excel on which i am retrieving drawing and chart as below: final XSSFDrawing drawing = xsh.createDrawingPatriarch(); final XSSFChart chart = drawing.getCharts().get(0); final List<XSSFChartAxis> axisList = (List<XSSFChartAxis>) chart.getAxis(); While debugging, it seems that XSSFChart.getAxis() is not having null check on axis variable and its not initialized. Its just checking the empty check. Which is why its failing. axis is initialized in the constructor. However in this case, its not initialized. I think in this case it should not come as null or it should be initialized on getAxis also.
Can you produce a small junit unit test showing this problem? And ideally also a patch if you can see the right fix!
Created attachment 32306 [details] SampleExcel
I just downloaded the src from svn and trying to get used to build process and creating patch . Meanwhile I just provide the test case and possible fix (which, I had tried out to be working). Test Examples: //Load existing excel with some chart on it having primary and secondary axis. final File res = new File("SampleExcel.xlsx"); final Workbook workbook = new XSSFWorkbook(OPCPackage.open(new FileInputStream(res))); final Sheet sh = workbook.getSheetAt(0); final XSSFSheet xsh = (XSSFSheet) sh; final XSSFDrawing drawing = xsh.createDrawingPatriarch(); final XSSFChart chart = drawing.getCharts().get(0); final List<XSSFChartAxis> axisList = (List<XSSFChartAxis>) chart.getAxis(); //Note: getAxis fails as axis variable inside chart is null. for(XSSFChartAxis axis: axisList){ //Do Some operation. } Fix:XSSFChart.java ===================== public List<? extends XSSFChartAxis> getAxis() { //ADDED NULL Check and Initialize the axis. if(axis == null){ axis = new ArrayList<XSSFChartAxis>(); } if (axis.isEmpty() && hasAxis()) { parseAxis(); } return axis; }
Thanks for the Patch, this is now applied via r1647317, although I reworked it slightly to not need to query in getAxis() constantly, we rather now create the List of Axises always.
(In reply to Dominik Stadler from comment #4) > Thanks for the Patch, this is now applied via r1647317, although I reworked > it slightly to not need to query in getAxis() constantly, we rather now > create the List of Axises always. Thanks for applying the patch.