We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

[Words 17.3] ArrayIndexOutOfBoundsException on document.updateFields()

Good day

We are planning on using Aspose.Words to automatically generate monthly reports for our customers. We plan on doing so by creating sub-reports in separate modules. At the moment we have a ‘ticketing’ module collecting data from ServiceNow and a ‘monitoring’ module gathering information from a Check_MK monitoring system. Currently we are in active development and are running into some minor issues.

For generating the reports we make use of the LINQ reporting engine provided by Aspose.Words. The failing report is made up of one master template file and the ticketing module’s dedicated template. The master file contains a title page, a ToC and some version information. The ticketing template consists of 6 headings as well as 6 charts. (Both files are attached to this post in a ZIP archive)
The generation itself is working flawlessly. The problem only occurs when invoking the document.updateFields() method, resulting in an ArrayIndexOutOfBoundsException.

The troubleshooting steps we already took are the following:

  • Using a master template only containing a ToC
  • Completely rewrote the module’s template file
  • Removed any umlauts from the document
  • Experimented with different numbers of headings and length of the module’s template
  • Deleting chart after chart (which ended in Words no longer throwing the error when using less or equal to 4 charts)
  • Reordering the charts in the conflicting module’s template
None of these steps fully resolved the issue we are facing.

Our conclusion is as follows:
Whenever there are more than 4 chart objects (no matter in what order or which charts they are) the updateFields method will fail with an “ArrayIndexOutOfBoundsException: 4”. Removing any two charts from the document will let the method pass and update the ToC correctly.

Now to the technical part:
We are using Aspose.Words for Java version 17.3 using not Java as main programming language but Python (with jpype). Now, we know this is not officially supported and we may try implementing a similar process in Java itself, however, if it wasn’t necessary, we would rather not.

The following list describes the steps our application takes while creating a single report (rewritten to Java)
  1. Load and set the license: License lic = new License(); lic.setLicense(“path”);
  2. Gather meta data (creation date, customer name etc.)
  3. Load master template into instance variable: Document doc = new Document(“path”);
  4. Prepare the reporting engine: ReportingEngine re = new ReportingEngine();
  5. Generate a sub-report for each module [ collect data, fill Java ArrayList object with information, build the report, return an Aspose.Words Document instance ]
  6. Append each sub-report to the template file: doc.appendDocument(subdoc, ImportFormatMode.USE_DESTINATION_STYLES); // in a for loop
  7. Fill in meta data using: re.buildReport(doc, reportMetaData, “reportData”);
  8. Update document fields: doc.updateFields(); // exception here [catched]
  9. Save document: doc.save(“path”);

Catching the exception and continuing execution results in a vaild word document. Only the ToC is erroneous showing only ‘?’ instead of page numbers.

I attached the master and the module’s template file (in a ZIP), a full stacktrace and a screenshot of the erroneous ToC as well as our Java classes used to fill in the report data (if of avail; also in a ZIP). If you need anything else, I’m willing to provide further information.

Do you know of any problems regarding the document.updateFields() method? Did we do any (obvious) mistakes?

Thank you in advance.

Kind regards

Hi Marco,

Thanks for your inquiry. Please create a simple Java application (source code without compilation errors) that helps us to reproduce your problem on our end and attach it here for testing. We will investigate the issue on our side and provide you more information.

Thanks for your cooperation.

Hi Tahir

Thank you for your answer.
I was able to reproduce the same behaviour in a plain Java application. However, the code is not as simple as I intended it to be.

Attached you’ll find a ZIP file containing the Java source files as well as the two template documents and sample data which are all needed to execute the generation. You’d have to adjust the variables basePath and licensePath in the main method of Reporting.java in order for it to run.

The relevant method handling the generation is “generateReport” in Reporting.java. The data from the CSV file is read in “readCsv” also in Reporting.java, however, this method does not seem to be connected to the problem as we collect the information using a REST-API in the real application.

I added some comments and JavaDoc trying to clarify the intention of several tasks a bit further.

If you have any further questions or requests I’m willing to help :slight_smile:

Kind regards

Hi Marco,

Thanks for sharing the detail. We are working over your query and will get back to you soon.

Hi Marco,

Thanks for your patience. We have tested the scenario and have managed to reproduce the same issue at our side. For the sake of correction, we have logged this problem in our issue tracking system as WORDSNET-15068. You will be notified via this forum thread once this issue is resolved.

We apologize for your inconvenience.

Hi Tahir

Thank you for your effort. Looking forward to a solution :slight_smile:

Kind regards

The issues you have found earlier (filed as WORDSNET-15068) have been fixed in this Aspose.Words for .NET 17.5 update and this Aspose.Words for Java 17.5 update.

This message was posted using Notification2Forum from Downloads module by aspose.notifier.