LINQ Reporting Engine - empty array throws error even with null check

Hello,

When accessing fields of array items in a foreach I get an error when the array is empty, even when I put the whole foreach in a conditional checking whether the array is empty. Please find attached minimal examples.Empty Array Issue.zip (12.3 KB)

I’ve tried sending an empty array object, sending a null, and omitting the field entirely but all fail.

I’m using:

  • Aspose.Words for Java, v22.9
  • a Word template
  • the ReportingEngine
  • a JsonDataSource

I’m also using the ALLOW_MISSING_MEMBERS reporting engine option but still get the error.

I notice a similar thread from a couple of years ago: LINQ Reporting engine throws java.lang.IllegalStateException - Aspose.Words Product Family - Free Support Forum - aspose.com

Exception thrown is:

java.lang.NullPointerException: Cannot invoke “com.aspose.words.internal.zzqF.zzYIY(Object, String)” because “this.zzZmo” is null
at com.aspose.words.internal.zzZlX.zzYIY(Unknown Source)
at com.aspose.words.internal.zzYeJ.zzYIY(Unknown Source)
at com.aspose.words.internal.zzWNU.zzYIY(Unknown Source)
at com.aspose.words.internal.zzYBa.zzO3(Unknown Source)
at com.aspose.words.internal.zzW9B.zzYIY(Unknown Source)
at com.aspose.words.internal.zzW9B.zzZMk(Unknown Source)
at com.aspose.words.internal.zzW9B.zzX46(Unknown Source)
at com.aspose.words.internal.zzW9B.zz0r(Unknown Source)
at com.aspose.words.internal.zzW9B.zzZkW(Unknown Source)
at com.aspose.words.internal.zzW9B.zzYr0(Unknown Source)
at com.aspose.words.internal.zzW9B.zzGK(Unknown Source)
at com.aspose.words.internal.zzW9B.zzeh(Unknown Source)
at com.aspose.words.internal.zzW9B.zzZGw(Unknown Source)
at com.aspose.words.internal.zzW9B.zzWza(Unknown Source)
at com.aspose.words.internal.zzW9B.zzYSp(Unknown Source)
at com.aspose.words.internal.zzW9B.zzXlR(Unknown Source)
at com.aspose.words.internal.zzW9B.zzWsF(Unknown Source)
at com.aspose.words.internal.zzW9B.zzwU(Unknown Source)
at com.aspose.words.internal.zzW9B.zzZKV(Unknown Source)
at com.aspose.words.internal.zzW9B.zzYLj(Unknown Source)
at com.aspose.words.internal.zzW9B.zzWh5(Unknown Source)
at com.aspose.words.internal.zzW9B.zzXUZ(Unknown Source)
at com.aspose.words.internal.zzWrz.zzZc5(Unknown Source)
at com.aspose.words.internal.zzWrz.zz8q(Unknown Source)
at com.aspose.words.internal.zzWrz.zzYIY(Unknown Source)
at com.aspose.words.internal.zzWrz.zzYIY(Unknown Source)
at com.aspose.words.internal.zzWUg.zz8G(Unknown Source)
at com.aspose.words.internal.zzYHC.zzXdL(Unknown Source)
at com.aspose.words.internal.zzYHC.zzYuk(Unknown Source)
at com.aspose.words.internal.zzYHC.zzXSY(Unknown Source)
at com.aspose.words.internal.zzYHC.zzYIC(Unknown Source)
at com.aspose.words.internal.zzYHC.zzW9j(Unknown Source)
at com.aspose.words.internal.zzWUg.zzYIY(Unknown Source)
at com.aspose.words.internal.zzWUg.zzYIY(Unknown Source)
at com.aspose.words.internal.zzVt.zzYIY(Unknown Source)
at com.aspose.words.internal.zzVt.zzYIY(Unknown Source)
at com.aspose.words.ReportingEngine.buildReport(Unknown Source)
at com.aspose.words.ReportingEngine.buildReport(Unknown Source)
…rest omitted

Are you able to advise the correct way of doing this?

Thank you for your help,

@LewisAllen

We were unable to reproduce getting of NullPointerException while using the following code:

JsonDataSource dataSource = new JsonDataSource("PeopleTest.json");
Document document = new Document("PeopleTestTemplate.docx");

ReportingEngine engine = new ReportingEngine();
engine.setOptions(ReportBuildOptions.ALLOW_MISSING_MEMBERS);
engine.buildReport(document, dataSource);

document.save("Out.docx");

For PeopleTest.json and PeopleTest3.json, no exception is thrown and for PeopleTest2.json, a different exception is thrown. Could you please double check the issue on your end?

@ivan.lyagin Thank you for your timely response on this.

I have modified the code to match your example, but I unfortunately still receive the same null pointer error as before. Example files Empty Array Issue.zip (11.2 KB)

Code being used:

Document document = new Document(“C:\temp\Empty Array Issue\PeopleTestTemplate.docx”);
JsonDataSource dataSource = new JsonDataSource(“C:\temp\Empty Array Issue\Json Examples\PeopleTest.json”);
ReportingEngine engine = new ReportingEngine();
engine.setOptions(ReportBuildOptions.ALLOW_MISSING_MEMBERS);

// Build report.
engine.buildReport(document, dataSource);

Is there any further detail I can provide to help diagnose the issue?

Many thanks,

@LewisAllen

Could you please also share which JDK/JRE versions and OS you use?

Sure,

JDK - openjdk 18.0.1.1
OS - Windows 10 Enterprise Version

Thanks,

@LewisAllen

We are working on your query and will get back as soon as we have any result.

1 Like

@LewisAllen

Unfortunately, we are still not able to reproduce the issue on our end while using JDK and OS versions you provided. Could you please (1) share your locale settings and (2) double check Aspose.Words version you use? Also, it would help a lot, if you could prepare a standalone console app reproducing the issue, so we could check it in more detail. Thanks for your cooperation.

@ivan.lyagin

I have done some more investigating and found switching to OpenJDK 8 (zulu8.64.0.19-ca-jdk8.0.345-win_x64) worked as required.

Switching to OpenJDK 11 (zulu11.58.23-ca-jdk11.0.16.1-win_x64) resulted in a different error which matches this thread ( Aspose.Words illegal reflective access operation - Aspose.Words Product Family - Free Support Forum - aspose.com) although this only seems to error on my first run and works OK thereafter.

I’m using Aspose Words version 22.9 through Gradle

implementation(“com.aspose:aspose-words:22.9:jdk16”)

I’ll update this thread if I can find more information or put together a minimal app.

Thanks for your help,

2 Likes