FileCorruptedException in multi-threaded application

Hello,

I use Aspose.Words v2.4.2 for Java (JDK JSE 1.5.0_06) and in the context of a multi-threaded application (one thread by generated document) with relative high speed processing (document generated in 2 seconds), i encounter sometime this exception :

com.aspose.words.FileCorruptedException: The document appears to be corrupted and cannot be loaded.

If i retry the processing that has failed, the error doesn’t occurs…i precize that each thread work on a document and a document is not shared between different thread.

Full stack trace:

eu.curia.pwe.error.PWEException: com.aspose.words.FileCorruptedException: The document appears to be corrupted and cannot be loaded.
at eu.curia.pwe.service.impl.DocumentProcessorWordImpl.generateLabel(DocumentProcessorWordImpl.java:2901)
at sun.reflect.GeneratedMethodAccessor31.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
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 $Proxy19.generateLabel(Unknown Source)
at eu.curia.pwe.service.BusinessRequestProcessorThread.run(BusinessRequestProcessorThread.java:246)
at sun.reflect.GeneratedMethodAccessor29.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
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 $Proxy24.run(Unknown Source)
at java.lang.Thread.run(Thread.java:619)
Caused by: com.aspose.words.FileCorruptedException: The document appears to be corrupted and cannot be loaded.
at com.aspose.words.Document.a(Unknown Source)
at com.aspose.words.Document.a(Unknown Source)
at com.aspose.words.Document.(Unknown Source)
at com.aspose.words.Document.(Unknown Source)
at eu.curia.pwe.service.impl.DocumentProcessorWordImpl.generateLabel(DocumentProcessorWordImpl.java:2581)
… 26 more
Caused by: java.lang.IllegalStateException: Current state = RESET, new state = FLUSHED
at java.nio.charset.CharsetDecoder.throwIllegalStateException(CharsetDecoder.java:951)
at java.nio.charset.CharsetDecoder.flush(CharsetDecoder.java:640)
at java.nio.charset.CharsetDecoder.decode(CharsetDecoder.java:769)
at asposewobfuscated.bv.e(Unknown Source)
at com.aspose.words.iv.a(Unknown Source)
at com.aspose.words.ae.a(Unknown Source)
at com.aspose.words.bn.read(Unknown Source)
… 31 more

Thanks in advance.

Best regards,
Dominique

Hi
Thanks for your inquiry. Sometimes this occurs because there is some problem with document you are trying to open using Aspose.Words. Could you please attach the document that causes the problem? I will try to reproduce the issue and provide you more information.
Best regards.

Hi,

This error can occur with every Word file (document or template).

I have attached a sample but with this sample the error can occur or not, the fixed thing is that error only occurs when processing is very quick and is in a thread…

I’m apologizing to cannot give you more informations but this error occur randomly…

Thanks in advance.

Dominique

Hi
Thank you for additional information. I will consult with our lead java developer and provide you more information.
For now I can only suggest you to try using the latest version of Aspose.Words for java:
https://releases.aspose.com/words/net
Best regards.

Hi Dominique,
According to your trace, java.nio.charset.CharsetDecoder conflicts with itself. It’s funny, but we are using sun.nio.cs.ThreadLocalCoders to thread-safely get CharsetDecodersJ Please, try another Aspose.Words jar that doesn’t use ThreadLocalCoders – may be this can solve the issue. I have sent you the jar by email – please check your post.
Best Regards,

Hello,

Thanks for you answer.

I have a problem with your new jar because, due to the api break mentioned on your blog, i must perform a migration thus i will keep the jar and if the issue block application deployment i will perform the migration.

Thanks another time.

Best regards,
Dominique