Free Support Forum - aspose.com

Document.updatePageLayout throws Null pointer exception using Java

Hello,

I’m getting an NullPointerException when calling Document.updatePageLayout().

When I then try to call Document.save() I get an IllegalArgumentException.

If I leave out the updatePageLayout() everything works fine.

Please find both stack traces below.

Thanks for your support!
Dirk Steinkamp


java.lang.NullPointerException

at com.aspose.words.zzYV6.zzYCr(Unknown Source)

at com.aspose.words.zzZJO.zzL(Unknown Source)

at com.aspose.words.zzZJO.zzZX(Unknown Source)

at com.aspose.words.zzZJN.zzZ(Unknown Source)

at com.aspose.words.zzZJN.zzM(Unknown Source)

at com.aspose.words.zzZJX.zzI(Unknown Source)

at com.aspose.words.zzZJW.zzD(Unknown Source)

at com.aspose.words.zzZJW.zzU(Unknown Source)

at com.aspose.words.zzZJW.zzV(Unknown Source)

at com.aspose.words.zzW7.zzZ(Unknown Source)

at com.aspose.words.zzW7.zzZ(Unknown Source)

at com.aspose.words.zzYW5.zzYDc(Unknown Source)

at com.aspose.words.zzYW5.zzY(Unknown Source)

at com.aspose.words.zzYW5.zzZ(Unknown Source)

at com.aspose.words.zzGX.zzY(Unknown Source)

at com.aspose.words.zzGX.zzN(Unknown Source)

at com.aspose.words.zzW7.zzZ(Unknown Source)

at com.aspose.words.zzW7.zzZ(Unknown Source)

at com.aspose.words.zzYW5.zzYDc(Unknown Source)

at com.aspose.words.zzYW5.zzY(Unknown Source)

at com.aspose.words.zzYW5.zzZ(Unknown Source)

at com.aspose.words.zzXP.zzc2(Unknown Source)

at com.aspose.words.zzXP.zzW(Unknown Source)

at com.aspose.words.zzXP.zzX(Unknown Source)

at com.aspose.words.zzZ5F.zzF(Unknown Source)

at com.aspose.words.zzZ5F.zzG(Unknown Source)

at com.aspose.words.zzZ5F.zzYS3(Unknown Source)

at com.aspose.words.zzZ5F.zzN(Unknown Source)

at com.aspose.words.zzZ4Q.zzG(Unknown Source)

at com.aspose.words.zzYU9.zz9(Unknown Source)

at com.aspose.words.zz8N.zzG(Unknown Source)

at com.aspose.words.zz8O.zzZG5(Unknown Source)

at com.aspose.words.zzZ5M.zzYSm(Unknown Source)

at com.aspose.words.Document.updatePageLayout(Unknown Source)

at de.isd_service.koko.tools.office.word.KokoWordDocAsposeImpl.updateAllFieldReferences(KokoWordDocAsposeImpl.java:1646)

at de.isd_service.koko.merger.word.WordMerger.afterAllRecords(WordMerger.java:270)

at de.isd_service.koko.merger.Merger.processRows(Merger.java:336)

at de.isd_service.koko.merger.word.WordSingleRecordMerger.processRows(WordSingleRecordMerger.java:39)

at de.isd_service.koko.merger.multi.MultiBriefMerger.processRowsAndGenerateOutput(MultiBriefMerger.java:215)

at de.isd_service.koko.main.KokoWorker.doWork(KokoWorker.java:97)

at de.isd_service.koko.main.KokoWorker$1.run(KokoWorker.java:197)

at de.isd_service.koko.main.KokoWorker.startWorkAndReturnToPool(KokoWorker.java:215)

at de.isd_service.koko.main.MainClassic.processArgs(MainClassic.java:275)

at de.isd_service.koko.main.MainClassic.main(MainClassic.java:138)

Specified argument was out of the range of valid values.

Parameter name: pageIndex

java.lang.IllegalArgumentException: Specified argument was out of the range of valid values.

Parameter name: pageIndex

at com.aspose.words.Document.zzYf(Unknown Source)

at com.aspose.words.zzZZQ.zzY(Unknown Source)

at com.aspose.words.zzZZQ.zzZ(Unknown Source)

at com.aspose.words.zzZF2.zzZ(Unknown Source)

at com.aspose.words.Document.zzZ(Unknown Source)

at com.aspose.words.Document.zzZ(Unknown Source)

at com.aspose.words.Document.save(Unknown Source)

at de.isd_service.koko.tools.office.word.KokoWordDocAsposeImpl.exportPDF(KokoWordDocAsposeImpl.java:159)

at de.isd_service.koko.merger.word.WordMerger.pdf(WordMerger.java:358)

at de.isd_service.koko.merger.Merger.pdf4Dms(Merger.java:936)

at de.isd_service.koko.merger.multi.MultiBriefMerger.pdf4Dms(MultiBriefMerger.java:116)

at de.isd_service.koko.merger.Merger.saveToDms(Merger.java:678)

at de.isd_service.koko.merger.multi.MultiBriefMerger.saveToDms(MultiBriefMerger.java:322)

at de.isd_service.koko.merger.Merger.saveToDmsIfAllowedAndCheckSuccess(Merger.java:598)

at de.isd_service.koko.merger.Merger.doOutput(Merger.java:542)

at de.isd_service.koko.merger.multi.MultiBriefMerger.processRowsAndGenerateOutput(MultiBriefMerger.java:243)

at de.isd_service.koko.main.KokoWorker.doWork(KokoWorker.java:97)

at de.isd_service.koko.main.KokoWorker$1.run(KokoWorker.java:197)

at de.isd_service.koko.main.KokoWorker.startWorkAndReturnToPool(KokoWorker.java:215)

at de.isd_service.koko.main.MainClassic.processArgs(MainClassic.java:275)

at de.isd_service.koko.main.MainClassic.main(MainClassic.java:138)

@Dirk_Steinkamp

Could you please attach your input Word document here for testing? We will investigate the issue on our side and provide you more information.

Thanks for your reply!

I’ve been trying to create a reproducible error from the document. Unfortunately with no success so far. The error only occurs sometimes after my program has done a bunch of modifications on the template document – and if I try to save the document right before calling the update as a docx and then reopen it in a unit test the error doesn’t occur again.
Do you have any hint how to save the internal document representation in a way that will preserve “everything”, so I get a pinned down situation for a reproducible test case?

@Dirk_Steinkamp

It is difficult to say what the problem is without document. Could you please share complete detail of your use case? Moreover, we need your document for testing. Thank for your cooperation.

Hi Tahir,
thanks for your reply. Sorry, it took me a while to look compile this mail – you’ll see it’s a little more complicated.
I get it’s difficult without a document. So I attached you two versions of the file that results in problems:

Attachment
TNSUB.zip (330.5 KB)

You find the original template-file and the file with some filled in data (saved directly before the code that usually results in the exception).

I only fear: you will not be able to reproduce my problem using this file, which seems to be because of a side-effect of the save operation (see below).

At least I can’t reproduce it with this code:

@Test
public void testUpdatePageLayout() throws Exception {
    Document asposeDoc = new Document("TNSUB.docx");
    // ... lots of code happens here in the real application ...
    asposeDoc.updatePageLayout();
}

I have two more findings:

  1. If I save the document before I call updatePageLayout() the problem disappears. Thus this is my current workaround:

    asposeDoc.save("nul", SaveFormat.DOCM);
    asposeDoc.updatePageLayout();

  2. I digged somewhat into the decompiled library and found the following code:

From com.aspose.words.zzYUQ (Aspose-Words 20.3):

final boolean zzYBn() {
	return super.zzYBn() || this.zzYzK().zzYBn();
}

final zzYUV zzYzK() {
	FieldStart var1 = this.zzXW2.getField().getStart();
	zzZJ5 var2;
	(var2 = this.zzjI().zzYyM().zzZbR()).zzW(this);

	zzYUV var3;
	do {
		if (!var2.movePrevious()) {
			return null;
		}
	} while ((var3 = (zzYUV) zzYI.zzZ(var2.zzZbW(), zzYUV.class)) == null || var3.zzYBB() != 2
			|| var3.zzYzY().zzYzV() != var1);
	return var3;
}

It looks like the call to zzYzK() returns null (because movePrevious() returned false) and thus the second argument in zzYBn() can’t be properly evaluated and results in a NullPointerException. Here’s my stack-trace from the real app with Aspose 20.3:

Exception bei updateAllFieldReferences. java.lang.NullPointerException - null
java.lang.NullPointerException
	at com.aspose.words.zzYUQ.zzYBn(Unknown Source)
	at com.aspose.words.zzZJC.zzL(Unknown Source)
	at com.aspose.words.zzZJC.zzZX(Unknown Source)
	at com.aspose.words.zzZJB.zzZ(Unknown Source)
	at com.aspose.words.zzZJB.zzM(Unknown Source)
	at com.aspose.words.zzZJL.zzI(Unknown Source)
	at com.aspose.words.zzZJK.zzC(Unknown Source)
	at com.aspose.words.zzZJK.zzU(Unknown Source)
	at com.aspose.words.zzZJK.zzV(Unknown Source)
	at com.aspose.words.zzW5.zzZ(Unknown Source)
	at com.aspose.words.zzW5.zzZ(Unknown Source)
	at com.aspose.words.zzYVS.zzYCc(Unknown Source)
	at com.aspose.words.zzYVS.zzY(Unknown Source)
	at com.aspose.words.zzYVS.zzZ(Unknown Source)
	at com.aspose.words.zzGU.zzY(Unknown Source)
	at com.aspose.words.zzGU.zzN(Unknown Source)
	at com.aspose.words.zzW5.zzZ(Unknown Source)
	at com.aspose.words.zzW5.zzZ(Unknown Source)
	at com.aspose.words.zzYVS.zzYCc(Unknown Source)
	at com.aspose.words.zzYVS.zzY(Unknown Source)
	at com.aspose.words.zzYVS.zzZ(Unknown Source)
	at com.aspose.words.zzXN.zzbJ(Unknown Source)
	at com.aspose.words.zzXN.zzW(Unknown Source)
	at com.aspose.words.zzXN.zzX(Unknown Source)
	at com.aspose.words.zzZ53.zzF(Unknown Source)
	at com.aspose.words.zzZ53.zzG(Unknown Source)
	at com.aspose.words.zzZ53.zzYRh(Unknown Source)
	at com.aspose.words.zzZ53.zzN(Unknown Source)
	at com.aspose.words.zzZ4F.zzG(Unknown Source)
	at com.aspose.words.zzYTT.zz9(Unknown Source)
	at com.aspose.words.zz8L.zzG(Unknown Source)
	at com.aspose.words.zz8M.zzZFF(Unknown Source)
	at com.aspose.words.zzZ5A.zzYRA(Unknown Source)
	at com.aspose.words.Document.updatePageLayout(Unknown Source)
	at de.isd_service.koko.tools.office.word.KokoWordDocAsposeImpl.updateAllFieldReferences(KokoWordDocAsposeImpl.java:1797)
	at de.isd_service.koko.merger.word.WordMerger.afterAllRecords(WordMerger.java:273)
	at de.isd_service.koko.merger.word.WordGroupedTablesMerger.afterAllRecords(WordGroupedTablesMerger.java:343)
	at de.isd_service.koko.merger.Merger.processRows(Merger.java:364)
	at de.isd_service.koko.merger.Merger.processRowsAndGenerateOutput(Merger.java:241)
	at de.isd_service.koko.main.KokoWorker.doWork(KokoWorker.java:102)
	at de.isd_service.koko.main.KokoWorker$1.run(KokoWorker.java:234)
	at de.isd_service.koko.main.KokoWorker.startWorkAndReturnToPool(KokoWorker.java:252)
	at de.isd_service.koko.main.MainClassic.processArgs(MainClassic.java:317)
	at de.isd_service.koko.main.MainClassic.main(MainClassic.java:152)

I hope this information helps to pinpoint down what’s going wrong. As the library is obfuscated I have no idea what might cause it – but somehow saving the file has the sideeffect that the NPE doesn’t occur any more.

Dirk

@Dirk_Steinkamp

Thanks for sharing the documents and detail. Please note that calling Document.updatePageLayout method for simple document does not reproduce this issue. You are creating documents from your template document. We need the code example that you use to create the documents.

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 and provide you more information on it.

That’s as I expected and have written. I can’t reproduce it myself with the simple test case. I would love to provide a simple example to reproduce the error – yet I don’t know how to do that as I have no idea, where the trouble lies. Could you give me a clue?

The document generation is part of a complex application, that processes an awful lot of different document types in a generic way.

Is there any way to store the document state in a kind of “snapshot” way that I could provide you with?

Could the additional information I provided help you to provide me with any hint what I might look for?

@Dirk_Steinkamp

Thanks for your inquiry. Unfortunately, we cannot comment on this issue without reproducing it. We need code example to reprodue this issue. Please share the requested details for testing. Thanks for your cooperation.