Chart.validateChartLayout Throws ArgumentOutOfRangeException in Java

Something bad is happening with attached presentation, it throws

class com.aspose.slides.exceptions.ArgumentOutOfRangeException: Specified argument was out of the range of valid values.
Parameter name: Parameter name: index

on validateChartData() for third embedded excel. Please check!

Code:

@Test
    public void embedded() throws Exception {

        String path = "INPUT_validate_chart_error_on_excel_embeddings.pptx"; //$NON-NLS-1$

        com.aspose.slides.Presentation presentation;

        try (InputStream testStream = new FileInputStream(path)) {
            presentation = new com.aspose.slides.Presentation(testStream);
        }

        com.aspose.slides.ISlideCollection slides = presentation.getSlides();

        for (com.aspose.slides.ISlide slide : slides) {
            com.aspose.slides.IShapeCollection shapes = slide.getShapes();

            for (com.aspose.slides.IShape shape : shapes) {
                if ((shape instanceof com.aspose.slides.IChart)) {
                    IChart chart = (com.aspose.slides.IChart) shape;

                    byte[] bytes = null;
                    try {
                        bytes = chart.getChartData().readWorkbookStream();
                    } catch (InvalidOperationException ioe) {
                        System.err.println("Not accessible chart data");

//                        continue;
                    }

                    if (bytes != null) {
                        try (InputStream excelStream = new ByteArrayInputStream(bytes)) {
                            com.aspose.cells.Workbook workbook = new com.aspose.cells.Workbook(excelStream);

                            com.aspose.cells.WorksheetCollection worksheets = workbook.getWorksheets();

                            for (com.aspose.cells.Worksheet worksheet : worksheets) {
                                com.aspose.cells.Cells cells = worksheet.getCells();

                                int maxRowIndex = cells.getMaxRow();
                                int maxColumnIndex = cells.getMaxColumn();

                                for (int i = 0; i <= maxRowIndex; i++) {
                                    for (int j = 0; j <= maxColumnIndex; j++) {
                                        com.aspose.cells.Cell cell = cells.get(i, j);

                                        if (!cell.isFormula() && !cell.isArrayFormula()) {
                                            Object value = cell.getValue();

                                            if (value instanceof String && cell.getStyle() != null && !cell.getStyle().isPercent()) {
                                                cell.setValue("Z_" + value);
                                            }
                                        }
                                    }
                                }

                                for (com.aspose.cells.Chart chart1 : worksheet.getCharts()) {

                                    com.aspose.cells.Title chartTitle = chart1.getTitle();
                                    chartTitle.setText("Z_" + chartTitle.getText());

                                    com.aspose.cells.Title chartXAxisTitle = chart1.getCategoryAxis().getTitle();
                                    chartXAxisTitle.setText("Z_" + chartXAxisTitle.getText());

                                    // handle secondary x-axis title if exists
                                    com.aspose.cells.Title chartSecondXAxisTitle = chart1.getSecondCategoryAxis().getTitle();
                                    if (chartSecondXAxisTitle.getText() != null) {
                                        chartSecondXAxisTitle.setText("Z_" + chartSecondXAxisTitle.getText());
                                    }

                                    com.aspose.cells.Title chartYAxisTitle = chart1.getValueAxis().getTitle();
                                    chartYAxisTitle.setText("Z_" + chartYAxisTitle.getText());

                                    // handle secondary y-axis title if exists
                                    com.aspose.cells.Title chartSecondYAxisTitle = chart1.getSecondValueAxis().getTitle();
                                    if (chartSecondYAxisTitle.getText() != null) {
                                        chartSecondYAxisTitle.setText("Z_" + chartSecondYAxisTitle.getText());
                                    }

                                    // handle z-axis (depth axis) if chart is 3D
                                    com.aspose.cells.Title chartZAxisTitle = chart1.getSeriesAxis().getTitle();
                                    if (chart1.getIs3D()) {
                                        chartZAxisTitle.setText("Z_" + chartZAxisTitle.getText());
                                    }

                                    chart1.calculate();
                                }
                            }

                            workbook.calculateFormula();

                            ByteArrayOutputStream baos = new ByteArrayOutputStream();

                            workbook.save(baos, com.aspose.cells.SaveFormat.XLSX);

                            baos.flush();

                            chart.getChartData().writeWorkbookStream(baos.toByteArray());

                        } catch (Exception e) {
                            throw new RuntimeException(e);
                        }


                    }

                    com.aspose.slides.ITextFrame textFrame = chart.getAxes().getVerticalAxis().getTitle().getTextFrameForOverriding();
                    if (textFrame != null) {
                        textFrame.setText("Z_" + textFrame.getText());
                    }
                    com.aspose.slides.IAxis secondary = chart.getAxes().getSecondaryVerticalAxis();
                    if (secondary != null) {
                        textFrame = secondary.getTitle().getTextFrameForOverriding();
                        if (textFrame != null) {
                            textFrame.setText("Z_" + textFrame.getText());
                        }
                    }
                    textFrame = chart.getChartTitle().getTextFrameForOverriding();
                    if (textFrame != null) {
                        textFrame.setText("Z_" + textFrame.getText());
                    }

                    textFrame = chart.getAxes().getHorizontalAxis().getTitle().getTextFrameForOverriding();
                    if (textFrame != null) {
                        textFrame.setText("Z_" + textFrame.getText());
                    }

                    secondary = chart.getAxes().getSecondaryHorizontalAxis();
                    if (secondary != null) {
                        textFrame = chart.getAxes().getSecondaryHorizontalAxis().getTitle().getTextFrameForOverriding();
                        if (textFrame != null) {
                            textFrame.setText("Z_" + textFrame.getText());
                        }
                    }

                    for (com.aspose.slides.IShape uShape : chart.getUserShapes().getShapes()) {
                        if (uShape instanceof com.aspose.slides.IAutoShape) {
                            ((com.aspose.slides.IAutoShape) uShape).getTextFrame()
                                    .setText("Z_" + ((com.aspose.slides.IAutoShape) uShape).getTextFrame().getText());
                        } else if (uShape instanceof com.aspose.slides.GroupShape) {
                            for (com.aspose.slides.IShape uGroupSHape : ((com.aspose.slides.GroupShape) uShape).getShapes()) {
                                // needs refactoring :)
                                if (uGroupSHape instanceof com.aspose.slides.IAutoShape) {
                                    ((com.aspose.slides.IAutoShape) uGroupSHape).getTextFrame()
                                            .setText("Z_" + ((com.aspose.slides.IAutoShape) uGroupSHape).getTextFrame().getText());
                                }
                            }
                        } else if (uShape instanceof com.aspose.slides.ITable) {
                            // needs refactoring 2 :(
                            ((com.aspose.slides.ITable) uShape).getColumns()
                                    .forEach(x -> x
                                            .forEach(y -> y
                                                    .getTextFrame()
                                                    .setText("Z_" + y
                                                            .getTextFrame()
                                                            .getText())));
                        } else if (uShape instanceof com.aspose.slides.ISmartArt) {
                            for(com.aspose.slides.ISmartArtNode smartArtNode: ((com.aspose.slides.ISmartArt) uShape).getAllNodes()) {
                                smartArtNode.getTextFrame().setText("Z_" + smartArtNode.getTextFrame().getText());
                            }
                        }
                    }

                    chart.validateChartLayout();

                    try {
                        com.aspose.slides.IChartDataWorkbook workbook = chart.getChartData().getChartDataWorkbook();
                        chart.validateChartLayout();
                        System.err.println("validate NonE-xtracted");
//            }
                    } catch (com.aspose.slides.exceptions.InvalidOperationException e) {
                        String extPath = chart.getChartData().getExternalWorkbookPath();
                        System.out.println("Slide chart skipped (external): " + extPath);
                    }
                } else if (shape instanceof com.aspose.slides.IAutoShape) {
                    ((com.aspose.slides.IAutoShape) shape).getTextFrame()
                            .setText("Z_" + ((com.aspose.slides.IAutoShape) shape).getTextFrame().getText());
                } else if (shape instanceof com.aspose.slides.GroupShape) {
                    for (com.aspose.slides.IShape uGroupSHape : ((com.aspose.slides.GroupShape) shape).getShapes()) {
                        // needs refactoring :)
                        if (uGroupSHape instanceof com.aspose.slides.IAutoShape) {
                            ((com.aspose.slides.IAutoShape) uGroupSHape).getTextFrame()
                                    .setText("Z_" + ((com.aspose.slides.IAutoShape) uGroupSHape).getTextFrame().getText());
                        }
                    }
                } else if (shape instanceof com.aspose.slides.ITable) {
                    // needs refactoring 2 :(
                    ((com.aspose.slides.ITable) shape).getColumns()
                            .forEach(x -> x
                                    .forEach(y -> y
                                            .getTextFrame()
                                            .setText("Z_" + y
                                                    .getTextFrame()
                                                    .getText())));
                } else if (shape instanceof com.aspose.slides.ISmartArt) {
                    for(com.aspose.slides.ISmartArtNode smartArtNode: ((com.aspose.slides.ISmartArt) shape).getAllNodes()) {
                        smartArtNode.getTextFrame().setText("Z_" + smartArtNode.getTextFrame().getText());
                    }
                }
            }
        }

        File tmpSaveFile = Files.createTempFile("validate_chart_error_on_excel_embeddings", ".pptx").toFile();

        try (FileOutputStream fos = new FileOutputStream(tmpSaveFile)) {
            presentation.save(fos, SaveFormat.Pptx);
        }
    }

INPUT_validate_chart_error_on_excel_embeddings.pptx.zip (6.4 MB)

@zpredojevic,
Thank you for reporting the issue. I have reproduced the problem where the validateChartLayout method throws the ArgumentOutOfRangeException. We apologize for any inconvenience caused.

We have opened the following new ticket(s) in our internal issue tracking system and will deliver their fixes according to the terms mentioned in Free Support Policies.

Issue ID(s): SLIDESJAVA-39843

You can obtain Paid Support Services if you need support on a priority basis, along with the direct access to our Paid Support management team.

:frowning_face: Thank You!

@zpredojevic,
Thank you for helping make Aspose.Slides better.