NullPointerException during Document.save() action

Hello,

I use Aspose.Words api for Java with Java SE 1.5.0_06 under Unix Solaris 10 Update 6 environment (in a web application).

In relation with my initial issue :
<a href="FileCorruptedException in multi-threaded application

I have updated to Aspose.Words version 2.6.0 (i have also tried version 2.5.0 with the same issue) but now i obtains a NullPointerException when is use the method save(String,int) from the Document object. My document object is not null ;o)

Thanks in advance for your help…

Best regards,
Dominique

Hi
Thanks for your request. Could you please attach your document and code for testing? We will try to reproduce the problem on our side.
Also, please provide full stack trace of the error.
Best regards.

Hi,

Find in attach a sample document (on Windows i haven’t the issue)

Below there the stack and the method body that running well witth Aspose.Word 2.4.2…

STACK:

eu.curia.pwe.error.PWEException: java.lang.NullPointerException
at eu.curia.pwe.service.impl.DocumentProcessorWordImpl.saveDocumentToTemporaryFile(Unknown Source)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:310)
at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:182)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:149)
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:106)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171)
at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:89)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:204)
at $Proxy15.saveDocumentToTemporaryFile(Unknown Source)
at eu.curia.pwe.service.BusinessRequestProcessorThread.run(Unknown Source)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:310)
at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:182)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:149)
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:106)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171)
at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:89)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:204)
at $Proxy17.run(Unknown Source)
at java.lang.Thread.run(Thread.java:595)
Caused by: java.lang.NullPointerException
at com.aspose.words.kq.a(Unknown Source)
at com.aspose.words.fv.e(Unknown Source)
at com.aspose.words.ih.d(Unknown Source)
at com.aspose.words.ou.a(Unknown Source)
at com.aspose.words.dj.eP(Unknown Source)
at com.aspose.words.dj.eK(Unknown Source)
at com.aspose.words.dj.a(Unknown Source)
at com.aspose.words.Document.a(Unknown Source)
at com.aspose.words.Document.save(Unknown Source)
… 29 more

METHOD CODE:

public File saveDocumentToTemporaryFile(Object document) throws PWEException {
    File file = null;
    try {
        // In this implementation the Object passed MUST be a ASPOSE.WORDS
        // document
        if (!(document instanceof Document)) {
            throw new PWEException("Object passed must be a instance of ‘com.aspose.words.Document’ class !");
        }
        // Generate a file name
        file = new File(this.projectConfiguration.getProperty("pwe.tmp.directory") + "/"
                \+ ServiceUtils.generateResponseID() + RandomStringUtils.randomAlphabetic(6) + ".doc");
        // Save file
        ((Document) document).save(file.getAbsolutePath(), SaveFormat.DOC);
    } catch (Exception e) {
        throw new PWEException(e);
    }

    return file;
}

Thanks in advance.

Dominique

Hi Dominique,
Is it the same multithread environment as in your initial issue? The thing is that Aspose.Words doesn’t even touch the method that throws in your stack trace if I using the doc and the code you provide.
Apparently, it is some kind of multi thread conflict. Please, check your configuration, may be your servlet container launches several simultaneous Aspose.Words applications or simultaneously uses different versions of one lib, etc.
About your initial issue – did you check the jar I emailed to you?
Best regards,

Hi,

It’s true that my application launch severals threads where each thread generare a document, there a problem with it ?

Can you resent me the jar file because my mailbox has crashed…

Thanks in advance.

Best regards,

Hi,
There are no problems with multithread if every Aspose.Words application is launched in the hard sandbox. But we will get unexpected behavior if several applications simultaneously trying to access one file, one variable, etc.
I can’t send you the jar because I deleted it too:) But I think it didn’t help us because the new error is completely different.
We have to divide is your issue multithread or JIT optimization.

  1. Did you get the error consistently? Or it varies from launch to launch?
  2. Can you get the same error in the same environment but in the single thread?
  3. Did your Solaris environment use JIT optimization for jvm? Can you temporarily disable this optimization?
    Best regards,

Hi,

OK for the JAR.

Please find below answers to your questions :

  1. Yes each time is use Document.save() on Solaris environment
  2. No
  3. JIT is by default activated on JSE 1.5.0x

We deploy the application on a Oracle OC4J application server version 10.1.3.1 and we add this options to the JVM (recommanded by Oracle to avoid stability issues with the container) :

-Djava.nio.channels.spi.SelectorProvider=sun.nio.ch.PollSelectorProvider

Thanks in advance

Hi,
Thanks for the answers.
Before I send you test jar. Please, if you can, disable (temporarily) JIT on your jvm – is the error still here?
Regards,

Hello,
I disabled JIT on the JVM with the option -Xint, but the problem is still existing. Can you send me the test jar you were talking about?
Thank you.

Hi,
I’ve got news… We finally found out that the problem is not around the Document.save() method, but about creating Word comments in the document.
I’ve run the following code (given as an example here: https://reference.aspose.com/words/net/aspose.words/comment/), alternating the Aspose.Words lib version (2.4.2 and 2.6.0):

import com.aspose.words.Comment;
import com.aspose.words.Document;
import com.aspose.words.DocumentBuilder;
import com.aspose.words.Paragraph;
import com.aspose.words.Run;
import com.aspose.words.SaveFormat;
public class InsertCommentTest {
    /**
     * Main method
     * @param args
     */
    public static void main(String[] args) {
        try{
            System.out.println("Starting process...");

            Document doc = new Document();
            DocumentBuilder builder = new DocumentBuilder(doc);
            builder.write("Some text is added.");

            Comment comment = new Comment(doc);
            builder.getCurrentParagraph().appendChild(comment);
            comment.getParagraphs().add(new Paragraph(doc));
            comment.getFirstParagraph().getRuns().add(new Run(doc, "Comment text."));

            doc.save("c:\\toto.txt", SaveFormat.DOC);

            System.out.println("...end of process");
        }
        catch(Exception e){
            e.printStackTrace();
        }
    }
}

Here are the results:

With v2.4.2 :
Starting process...
 ...end of process*

 With v2.6.0:
 *Starting process...
 java.lang.NullPointerException
at com.aspose.words.kq.a(Unknown Source)
 at com.aspose.words.fv.e(Unknown Source)
 at com.aspose.words.ih.d(Unknown Source)
 at com.aspose.words.ou.a(Unknown Source)
 at com.aspose.words.dj.eP(Unknown Source)
 at com.aspose.words.dj.eK(Unknown Source)
 at com.aspose.words.dj.a(Unknown Source)
 at com.aspose.words.Document.a(Unknown Source)
 at com.aspose.words.Document.save(Unknown Source)
 at InsertCommentTest.main(InsertCommentTest.java:35)*

So it works fine with v2.4.2, but not with v2.6.0. Can you give us more information?
Best regards,

Hi
Thank you for additional information and sorry for delayed response. This is known issue #4346 in our defect database. This issue is already fixed in .NET version of Aspose.Words and next java release will also contain this fix.
You can also easy fix this on your side. Just set Comment.Author and Comment.Initial properties to non null values. The problem was caused by null author and initials. Please see the following code:

Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
builder.write("Some text is added.");
Comment comment = new Comment(doc);
builder.getCurrentParagraph().appendChild(comment);
comment.getParagraphs().add(new Paragraph(doc));
comment.getFirstParagraph().getRuns().add(new Run(doc, "Comment text."));
comment.setAuthor("");
comment.setInitial("");
doc.save("C:\\Temp\\out.doc");

Hope this helps.
Best regards.

Hi Dominique,
With your last code we easily catch the thing. The fix will be published within a next java release (during a week).
Regards,

Fine! The solution is working.
I’d like to know if there is a list of known issues, for next releases, that we can consult? So before posting a message about a problem, we would search the list if the issue is already existing.
Thank you Alexey and Konstantin for your help.
Best regards,

Hi
Thanks for your request. The list of known issues is for internal use only. So if you have any issues, please post in the forum and we will provide you more information.
Best regards,

We have published new version of Aspose.Words for java. This version contains fix of issue #7359 you have reported earlier.
You can download new version from here:
https://releases.aspose.com/words/net