Hi there,
I’m getting the following error, at calling document.getFirstSection().clearHeaderFooters(), deep inside the Aspose Library:
java.lang.NullPointerException: Cannot invoke “com.aspose.words.Node.getNextSibling()” because “parameter2” is null
This happens when creating the same document multiple times concurrently via a REST Service. The same document is at first created correctly multiple times, when all of a sudden for the same Document this NPE is thrown.
There seems to be no issue, when creating the document just a single time.
Issue happens with Version 25.2 but not with older Versions, like 23.3.
Any ideas what the issue might be?
Many thanks in advance and best regards
@support.enowa.ag Could you please attach your problematic document here for testing? We will check the issue and provide you more information.
Thanks for ultra quick reply!
Unfortunaltely this not that easy to provide, but mainly seems to happen when processing this uploaded document. But as said, mostly this causes no issues for excacty the same document.
Our Application (jee app running on quarkus) procudes a single document by composing multiple word/docx documents based on quite complex rules.
So basically we read the Word Document and create an aspose document for this Word doc. For this document then clearHeaderFooters is called before appending it to the final document.
So code is (simplified):
Document doc = new Document(inputStreamOfWordDoc);
doc.getFirstSection().clearHeadersFooters();
appendDocToFinalDocument(doc);
TestDoc.docx (63.9 KB)
Excpetion is thrown at the clearHeaderFototer Call.
Stacktrace:
2025-03-26 14:55:42,759 WARNING [de.nob.d70.ser.api.D7030Resource] (executor-thread-18) java.lang.NullPointerException: Cannot invoke "com.aspose.words.Node.getNextSibling()" because "<parameter2>" is null: java.lang.RuntimeException: java.lang.NullPointerException: Cannot invoke "com.aspose.words.Node.getNextSibling()" because "<parameter2>" is null
at com.aspose.words.zzXUa.hasNext(Unknown Source)
at com.aspose.words.NodeCollection.zzVXb(Unknown Source)
at com.aspose.words.Section.clearHeadersFooters(Unknown Source)
at com.aspose.words.Section.clearHeadersFooters(Unknown Source)
at de.nobiscum.d7030.core.model.TextModule.combineDocuments(TextModule.java:515)
at de.nobiscum.d7030.core.model.TextModule.execute(TextModule.java:106)
at de.nobiscum.d7030.core.model.Group.execute(Group.java:148)
at de.nobiscum.d7030.core.model.Group.executeCondition(Group.java:261)
at de.nobiscum.d7030.core.model.Group.execute(Group.java:123)
at de.nobiscum.d7030.core.model.Group.execute(Group.java:148)
at de.nobiscum.d7030.core.model.Group.executeCondition(Group.java:261)
at de.nobiscum.d7030.core.model.Group.execute(Group.java:123)
at de.nobiscum.d7030.core.model.Group.execute(Group.java:148)
at de.nobiscum.d7030.core.model.Group.execute(Group.java:130)
at de.nobiscum.d7030.core.model.Group.execute(Group.java:148)
at de.nobiscum.d7030.core.model.Group.execute(Group.java:130)
at de.nobiscum.d7030.core.model.Group.execute(Group.java:148)
at de.nobiscum.d7030.core.DocumentGenerator.prepareDocument(DocumentGenerator.java:236)
at de.nobiscum.d7030.core.DocumentGenerator.generateDocument(DocumentGenerator.java:148)
at de.nobiscum.d7030.server.boundary.DocumentProducerService.produceDocument(DocumentProducerService.java:148)
at de.nobiscum.d7030.server.boundary.DocumentProducerService.generateDocument(DocumentProducerService.java:85)
at de.nobiscum.d7030.server.boundary.DocumentProducerService_Subclass.generateDocument$$superforward(Unknown Source)
at de.nobiscum.d7030.server.boundary.DocumentProducerService_Subclass$$function$$1.apply(Unknown Source)
at io.quarkus.arc.impl.AroundInvokeInvocationContext.proceed(AroundInvokeInvocationContext.java:73)
at io.quarkus.arc.impl.AroundInvokeInvocationContext$NextAroundInvokeInvocationContext.proceed(AroundInvokeInvocationContext.java:97)
at io.quarkus.narayana.jta.runtime.interceptor.TransactionalInterceptorBase.invokeInOurTx(TransactionalInterceptorBase.java:136)
at io.quarkus.narayana.jta.runtime.interceptor.TransactionalInterceptorBase.invokeInOurTx(TransactionalInterceptorBase.java:107)
at io.quarkus.narayana.jta.runtime.interceptor.TransactionalInterceptorRequired.doIntercept(TransactionalInterceptorRequired.java:38)
at io.quarkus.narayana.jta.runtime.interceptor.TransactionalInterceptorBase.intercept(TransactionalInterceptorBase.java:61)
at io.quarkus.narayana.jta.runtime.interceptor.TransactionalInterceptorRequired.intercept(TransactionalInterceptorRequired.java:32)
at io.quarkus.narayana.jta.runtime.interceptor.TransactionalInterceptorRequired_Bean.intercept(Unknown Source)
at io.quarkus.arc.impl.InterceptorInvocation.invoke(InterceptorInvocation.java:42)
at io.quarkus.arc.impl.AroundInvokeInvocationContext.proceed(AroundInvokeInvocationContext.java:70)
at io.quarkus.arc.impl.AroundInvokeInvocationContext.proceed(AroundInvokeInvocationContext.java:62)
at de.nobiscum.d7030.server.monitoring.PerformanceAuditor.measurePerformance(PerformanceAuditor.java:38)
at de.nobiscum.d7030.server.monitoring.PerformanceAuditor_Bean.intercept(Unknown Source)
at io.quarkus.arc.impl.InterceptorInvocation.invoke(InterceptorInvocation.java:42)
at io.quarkus.arc.impl.AroundInvokeInvocationContext.perform(AroundInvokeInvocationContext.java:30)
at io.quarkus.arc.impl.InvocationContexts.performAroundInvoke(InvocationContexts.java:27)
at de.nobiscum.d7030.server.boundary.DocumentProducerService_Subclass.generateDocument(Unknown Source)
at de.nobiscum.d7030.server.boundary.DocumentProducerService_ClientProxy.generateDocument(Unknown Source)
at de.nobiscum.d7030.server.api.v2.boundary.DocumentCreationRequestResource.createDocument(DocumentCreationRequestResource.java:134)
at de.nobiscum.d7030.server.api.v2.boundary.DocumentCreationRequestResource.produceWithTimestamp(DocumentCreationRequestResource.java:93)
at de.nobiscum.d7030.server.api.v2.boundary.DocumentCreationRequestResource_Subclass.produceWithTimestamp$$superforward(Unknown Source)
at de.nobiscum.d7030.server.api.v2.boundary.DocumentCreationRequestResource_Subclass$$function$$5.apply(Unknown Source)
at io.quarkus.arc.impl.AroundInvokeInvocationContext.proceed(AroundInvokeInvocationContext.java:73)
at io.quarkus.arc.impl.AroundInvokeInvocationContext$NextAroundInvokeInvocationContext.proceed(AroundInvokeInvocationContext.java:97)
at de.nobiscum.d7030.server.api.v2.logging.LoggingInterceptor.logInterfaceCall(LoggingInterceptor.java:47)
at de.nobiscum.d7030.server.api.v2.logging.LoggingInterceptor_Bean.intercept(Unknown Source)
at io.quarkus.arc.impl.InterceptorInvocation.invoke(InterceptorInvocation.java:42)
at io.quarkus.arc.impl.AroundInvokeInvocationContext.proceed(AroundInvokeInvocationContext.java:70)
at io.quarkus.arc.impl.AroundInvokeInvocationContext$NextAroundInvokeInvocationContext.proceed(AroundInvokeInvocationContext.java:97)
at de.nobiscum.d7030.server.monitoring.PerformanceAuditor.measurePerformance(PerformanceAuditor.java:38)
at de.nobiscum.d7030.server.monitoring.PerformanceAuditor_Bean.intercept(Unknown Source)
at io.quarkus.arc.impl.InterceptorInvocation.invoke(InterceptorInvocation.java:42)
at io.quarkus.arc.impl.AroundInvokeInvocationContext.proceed(AroundInvokeInvocationContext.java:70)
at io.quarkus.arc.impl.AroundInvokeInvocationContext.proceed(AroundInvokeInvocationContext.java:62)
at de.nobiscum.d7030.server.api.v2.exception.RestfulExceptionInterceptor.invoke(RestfulExceptionInterceptor.java:26)
at de.nobiscum.d7030.server.api.v2.exception.RestfulExceptionInterceptor_Bean.intercept(Unknown Source)
at io.quarkus.arc.impl.InterceptorInvocation.invoke(InterceptorInvocation.java:42)
at io.quarkus.arc.impl.AroundInvokeInvocationContext.perform(AroundInvokeInvocationContext.java:30)
at io.quarkus.arc.impl.InvocationContexts.performAroundInvoke(InvocationContexts.java:27)
at de.nobiscum.d7030.server.api.v2.boundary.DocumentCreationRequestResource_Subclass.produceWithTimestamp(Unknown Source)
at de.nobiscum.d7030.server.api.v2.boundary.DocumentCreationRequestResource_ClientProxy.produceWithTimestamp(Unknown Source)
at de.nobiscum.d7030.server.api.v2.boundary.DocumentCreationRequestResource$quarkusrestinvoker$produceWithTimestamp_e782108759b6cce6744fab91b65d189b22b4566a.invoke(Unknown Source)
at org.jboss.resteasy.reactive.server.handlers.InvocationHandler.handle(InvocationHandler.java:29)
at io.quarkus.resteasy.reactive.server.runtime.QuarkusResteasyReactiveRequestContext.invokeHandler(QuarkusResteasyReactiveRequestContext.java:141)
at org.jboss.resteasy.reactive.common.core.AbstractResteasyReactiveContext.run(AbstractResteasyReactiveContext.java:147)
at io.quarkus.vertx.core.runtime.VertxCoreRecorder$15.runWith(VertxCoreRecorder.java:638)
at org.jboss.threads.EnhancedQueueExecutor$Task.doRunWith(EnhancedQueueExecutor.java:2675)
at org.jboss.threads.EnhancedQueueExecutor$Task.run(EnhancedQueueExecutor.java:2654)
at org.jboss.threads.EnhancedQueueExecutor.runThreadBody(EnhancedQueueExecutor.java:1627)
at org.jboss.threads.EnhancedQueueExecutor$ThreadBody.run(EnhancedQueueExecutor.java:1594)
at org.jboss.threads.DelegatingRunnable.run(DelegatingRunnable.java:11)
at org.jboss.threads.ThreadLocalResettingRunnable.run(ThreadLocalResettingRunnable.java:11)
at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30)
at java.base/java.lang.Thread.run(Thread.java:1583)
Caused by: java.lang.NullPointerException: Cannot invoke "com.aspose.words.Node.getNextSibling()" because "<parameter2>" is null
at com.aspose.words.NodeCollection.zzj2(Unknown Source)
at com.aspose.words.NodeCollection.zzWRs(Unknown Source)
at com.aspose.words.NodeCollection.getNextMatchingNode(Unknown Source)
at com.aspose.words.zzXUa.hasNext(Unknown Source)
... 76 more
I’ve now replaced the supposedly problematic document(s) with a very simple document:
testReplacement.docx (15.0 KB)
With that I’m not seeing the NPE anymore.
Also with the original document issue only occurs during load testing (and also only since using Version 25.2.)
@support.enowa.ag Thank you for additional information. I have managed to reproduce the problem by running the task in multiple threads:
List<ThreadImpl> threads = new ArrayList<>();
for(int i=0; i<1000; i++)
{
ThreadImpl thread = new ThreadImpl();
threads.add(thread);
Thread t = new Thread(thread);
t.start();
}
// Wait some time.
Thread.sleep(10000);
for(ThreadImpl t : threads)
if(!t.Result.equals("Successful"))
System.out.println(t.Result);
private static class ThreadImpl implements Runnable
{
@Override
public void run() {
try {
Document doc = new Document("C:\\Temp\\in.docx");
doc.getFirstSection().clearHeadersFooters();
Result = "Successful";
}
catch (Exception ex) {
Result = ex.getMessage();
for(StackTraceElement e : ex.getStackTrace())
Result+=e.toString()+"\r\n";
}
}
public String Result = "";
}
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): WORDSNET-28048
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.
Internally, clearHeadersFooters
method generally does the following:
for(HeaderFooter hf : doc.getFirstSection().getHeadersFooters())
hf.removeAllChildren();
If replace clearHeadersFooters
exception does not occur on my side. So you can try using this code as a temporary workaround.
I’do some additional testing regarding the actual content of the produced documents but besides that, the provided workaround seems to work. Also not getting the NPE anymore with that.
Thanks for the quick help!
1 Like