java.lang.NullPointerException calling MailMerge.executeWithRegions

Hello,
I’m using aspose.words to fill a document with mailmerge.
It works perfectly except in a single machine running linux on PowerPc using openjdk. I get this error randomly but very often:

java.lang.NullPointerException
	at com.aspose.words.zzZFG.flush(Unknown Source)
	at com.aspose.words.zzYUG.zza(Unknown Source)
	at com.aspose.words.zz8R.zzG(Unknown Source)
	at com.aspose.words.zz8S.zzZGE(Unknown Source)
	at com.aspose.words.zzZ5T.zzYTl(Unknown Source)
	at com.aspose.words.Document.updatePageLayout(Unknown Source)
	at com.aspose.words.zz3U.zzZAp(Unknown Source)
	at com.aspose.words.zz3V.zzFi(Unknown Source)
	at com.aspose.words.zz0S.zzY5(Unknown Source)
	at com.aspose.words.zz0S.zzZuv(Unknown Source)
	at com.aspose.words.zzZHW.zzZ7V(Unknown Source)
	at com.aspose.words.zzZHW.zzZ(Unknown Source)
	at com.aspose.words.MailMerge.zzZ(Unknown Source)
	at com.aspose.words.MailMerge.executeWithRegions(Unknown Source)

Which can be the root cause?
The docx to fill is small: about 30Kb. My steps are very basic:

Documet pDOCUMENT = new Document(w_FULL_PATH_TEMPLATE);
DataSet pDataSet = fillDataSet();
pDOCUMENT.getMailMerge().setFieldMergingCallback( new HandleMergeImageFieldFromBlob() );
pDOCUMENT.getMailMerge().executeWithRegions(pDataSet);

I add that:

  • The problem occurs if I comment out the .setFieldMergingCallback line as well
  • Once the problem occurs I have to restart the web application in order to make the executeWithRegions call. Just as the errors put the library in a “dirty” state

@onof80 Could you please attach your template and sample data that will allow us to reproduce the issue? We will investigate the problem and provide you more information.

Hi alexy,
I’m attaching one of the templates. On that machine I get the error also with an empty dataset:

DataSet pDataSet = new DataSet();

hira_8108_procedure.docx (32.8 KB)

I add that the same problem occurs also calling updateFields (insteand of calling executeWithMerge):

||at com.aspose.words.zzZFG.flush(Unknown Source)|
||at com.aspose.words.zzYUG.zza(Unknown Source)|
||at com.aspose.words.zz8R.zzG(Unknown Source)|
||at com.aspose.words.zz8S.zzZGE(Unknown Source)|
||at com.aspose.words.zzZ5T.zzYTl(Unknown Source)|
||at com.aspose.words.Document.updatePageLayout(Unknown Source)|
||at com.aspose.words.zz3U.zzZAp(Unknown Source)|
||at com.aspose.words.zz3V.zzFi(Unknown Source)|
||at com.aspose.words.zz0S.zzY5(Unknown Source)|
||at com.aspose.words.zz0S.zzZ(Unknown Source)|
||at com.aspose.words.zz0S.zzZ3(Unknown Source)|
||at com.aspose.words.Range.updateFields(Unknown Source)|
||at com.aspose.words.Document.updateFields(Unknown Source)|

@onof80 Which version of Aspose.Words do you use? I have checked your scenario on my side using the latest 21.12 version of Aspose.Words for Java and the problem is not reproducible.

We are using the version 19.11. Has it been fixed in later versions ?

Anyway I get the same error with the 21.12 version, with slight different stack trace:

java.lang.NullPointerException
	at com.aspose.words.zzYvM.flush(Unknown Source)
	at com.aspose.words.zzWY6.zzZcq(Unknown Source)
	at com.aspose.words.zzZ9A.zzZqK(Unknown Source)
	at com.aspose.words.zzZ9A.zzZo9(Unknown Source)
	at com.aspose.words.zzXc9.zzZaS(Unknown Source)
	at com.aspose.words.zzXF7.zzYzS(Unknown Source)
	at com.aspose.words.zzWY6.zzZcq(Unknown Source)
	at com.aspose.words.zzWvZ.zzYzS(Unknown Source)
	at com.aspose.words.zzYfF.zzZp8(Unknown Source)
	at com.aspose.words.zzYfF.zzUH(Unknown Source)
	at com.aspose.words.zzZ9c.zzYVX(Unknown Source)
	at com.aspose.words.Document.updatePageLayout(Unknown Source)

@onof80 I tried with your template and the following code:

Document doc = new Document("C:\\Temp\\in.docx");
DataSet pDataSet = new DataSet();
doc.getMailMerge().executeWithRegions(pDataSet);
doc.save("C:\\Temp\\out.pdf");

and the problem is not reproducible on my side.

It doesn’t occur systematically, but after a number of execution.
I’m now running just the following code, similar to yours, in a web application servlet in tomcat 9, and I get the error after a random number of calls.
I wonder why the error occurs in the flush function. Is it involved in cleaning the java.io.tmpdir files ?

Document doc = new Document(TPLPATH);
DataSet pDataSet = new DataSet();
doLog("Executing.. ");
doc.getMailMerge().executeWithRegions(pDataSet);
doc.save(SAFEFOLDER);
doLog("Saved in " + SAFEFOLDER);

The error is:

java.lang.NullPointerException
	at com.aspose.words.zzYvM.flush(Unknown Source)
	at com.aspose.words.zzWY6.zzZcq(Unknown Source)
	at com.aspose.words.zzZ9A.zzZqK(Unknown Source)
	at com.aspose.words.zzZ9A.zzZo9(Unknown Source)
	at com.aspose.words.zzXc9.zzZaS(Unknown Source)
	at com.aspose.words.zzXF7.zzYzS(Unknown Source)
	at com.aspose.words.zzWY6.zzZcq(Unknown Source)
	at com.aspose.words.zzWvZ.zzYzS(Unknown Source)
	at com.aspose.words.zzYfF.zzZp8(Unknown Source)
	at com.aspose.words.zzYfF.zzUH(Unknown Source)
	at com.aspose.words.zzZ9c.zzYVX(Unknown Source)
	at com.aspose.words.Document.updatePageLayout(Unknown Source)
	at com.aspose.words.zzWlQ.zzVUt(Unknown Source)
	at com.aspose.words.zzhL.zzYuK(Unknown Source)
	at com.aspose.words.zzWU9.zza9(Unknown Source)
	at com.aspose.words.zzWU9.zzZqK(Unknown Source)
	at com.aspose.words.zzWU9.zzZp8(Unknown Source)
	at com.aspose.words.zzWU9.zz8Y(Unknown Source)
	at com.aspose.words.Document.zzWBq(Unknown Source)
	at com.aspose.words.Document.zzZqK(Unknown Source)
	at com.aspose.words.Document.zzZp8(Unknown Source)
	at com.aspose.words.Document.save(Unknown Source)
	at com.aspose.words.Document.save(Unknown Source)
	at hira_ftestasposeR.Page_1(hira_ftestasposeR.java:136)

@onof80 Thank you for additional information. I will consult with our Java developers and provide you more information.

1 Like

I have to rectify: on that machine we are using Linux for ppc64 running RedHat openjdk 1.8.0_302

@onof80 Thank you for additional information. I have logged the issue as WORDSJAVA-2676. Our Java developers will deeply investigate the problem. Once analysis of the issue is done, we will provide you more information.

2 Likes

@onof80 We have completed analyzing the issue. It looks like a random issue in multithread environment + saving document to the single file: doc.save("C:\\Temp\\out.pdf"); + Exception in a flush() method. Could you please try incrementing the output file name for every saving.

Hi alexey,
thank you for your answer but I tried and it does not work.
The only solution we found so far is to move the webapp in a x86 environment.

1 Like

@onof80 The issue has been closed as not a bug. This is a random issue in multithread environment + saving document to the single file: doc.save("C:\\Temp\\out.pdf"); + Exception in a flush() method.
Please try incrementing the output file name for every saving to avoid the problem.

Hi alexey,
I tried but it didn’t work. I tried with a random generated file name as well.
The problem occurs to us only on powerpc architecure.
We arrived to state that we can’t use aspose words on powerpc.

And I add that the same problem, on powerpc, occurs also calling executeWithRegions, not only saving:

at com.aspose.words.zzXIL.flush(Unknown Source)
at com.aspose.words.zzV3.zzYFC(Unknown Source)
at com.aspose.words.zzVWV.zzYhn(Unknown Source)
at com.aspose.words.zzVWV.zzKW(Unknown Source)
at com.aspose.words.zzYH7.zzXUp(Unknown Source)
at com.aspose.words.zzW7K.zzZv8(Unknown Source)
at com.aspose.words.zzV3.zzYFC(Unknown Source)
at com.aspose.words.zzVSK.zzZv8(Unknown Source)
at com.aspose.words.zzYz3.zzXWH(Unknown Source)
at com.aspose.words.zzYz3.zzWxz(Unknown Source)
at com.aspose.words.zzW0z.zzW5v(Unknown Source)
at com.aspose.words.Document.updatePageLayout(Unknown Source)
at com.aspose.words.zzZ9b.zzYxD(Unknown Source)
at com.aspose.words.zzYws.zzVVw(Unknown Source)
at com.aspose.words.zzYHL.zzWeP(Unknown Source)
at com.aspose.words.zzYHL.zzZiW(Unknown Source)
at com.aspose.words.zzYMo.zzZYi(Unknown Source)
at com.aspose.words.zzYMo.zzXWH(Unknown Source)
at com.aspose.words.MailMerge.zzXWH(Unknown Source)
at com.aspose.words.MailMerge.executeWithRegions(Unknown Source)

@onof80 Thank you for additional information. We will take a look at the issue once again and let you know if we find something.

@onof80,

This issue has been logged as WORDSJAVA-2833. We will keep you posted and will let you know as soon as the issue is resolved. Please accept our apologies for the inconvenience.

The issues you have found earlier (filed as WORDSJAVA-2833) have been fixed in this Aspose.Words for Java 24.5 update.