Sign UpSign Up   Sign InSign In Welcome Guest,
Live Chat Live Chat

FileCorruptedException

Last post 09-06-2010, 4:23 AM by aske012. 10 replies.
Sort Posts: Previous Next
  •  05-07-2010, 3:46 AM 236733

    FileCorruptedException Java

    Hi,

     

    We are running Aspose 3.2.1.0 inside JBoss 3.2.6, on Sun JVM 1.5.0, on Solaris 9.

     

    Since upgrading to this version of Aspose we sporadically have seen the following error:

     

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

                at com.aspose.words.Document.a(Document.java:1354)

                at com.aspose.words.Document.b(Document.java:1341)

                at com.aspose.words.Document.a(Document.java:1229)

                at com.aspose.words.Document.<init>(Document.java:149)

                at com.aspose.words.Document.<init>(Document.java:123)

                at mis.pip.edrms.docs.DmDocument.get(DmDocument.java:253)

                ... 66 more

    Caused by: java.lang.IllegalStateException: Current state = CODING_END, new state = CODING

                at java.nio.charset.CharsetDecoder.throwIllegalStateException(CharsetDecoder.java:941)

                at java.nio.charset.CharsetDecoder.decode(CharsetDecoder.java:537)

                at asposewobfuscated.mf.a(Encoding.java:423)

                at asposewobfuscated.tp.jw(BinaryReader.java:165)

                at com.aspose.words.eq.n(Parser.java:163)

                at com.aspose.words.eq.bo(Parser.java:109)

                at com.aspose.words.eq.parse(Parser.java:45)

                at com.aspose.words.cl.read(DocReader.java:93)

                at com.aspose.words.Document.b(Document.java:1258)

                ... 70 more

     

    I note from thread https://aspose.com/community/forums/thread/176433/aspose.words-new-document-failure.aspx that something similar has been reported.

     

    In essence our problem is the same - two Document instances for the same Word document are created at roughly the same time. I won’t bog you down with detail just yet but let me know if you want some example code.

     

    If there is a patch for this, please send it on.

     

    Thanks.

     

     
  •  05-07-2010, 7:05 AM 236796 in reply to 236733

    Re: FileCorruptedException

    Hi

     

    Thanks for your inquiry. Have you tried using the latest version of Aspose.Words for Java. You can download the latest version from here:

    http://www.aspose.com/community/files/72/java-components/aspose.words-for-java/category1378.aspx

     

    Also, it would be great if you provide sample code and documents, which will allow to reproduce the problem.

     

    Best regards.


    Alexey Noskov
    Developer/Technical Support
    Aspose Auckland Team
     
  •  05-11-2010, 3:30 AM 237236 in reply to 236796

    Re: FileCorruptedException

    Attachment: Present (inaccessible)
    I have attached some abstracted sample code and a document.

    I should stress that the problem is sporadic so may be difficult to replicate.

    With regards to the new version Aspose Words you recommended, please confirm that this resolves the issue referenced in the link in my original post.

    Thanks.
     
  •  05-11-2010, 4:50 AM 237262 in reply to 237236

    Re: FileCorruptedException

    Hi

     

    Thank you for additional information. Yes, I can confirm that problem mentioned in the forum thread you referenced to, is already resolved in the latest version.

    Also, I tested your document with the latest version of Aspose.Words and no exceptions occur on my side. So please try using the latest version.

     

    Best regards.


    Alexey Noskov
    Developer/Technical Support
    Aspose Auckland Team
     
  •  05-12-2010, 10:03 AM 237583 in reply to 237262

    Re: FileCorruptedException

    I've downloaded and tested the new version. So far, so good.

    Thanks for the help.
     
  •  06-18-2010, 8:12 AM 244241 in reply to 237583

    Re: FileCorruptedException

    Hi,

    After upgrading to the latest version of Aspose, we are still seeing an error in the same place in our code. See previous post for an abstracted code sample. Like before, the error is sporadic, indicating a threading issue. Here is the new stack trace:

    ... 16 more
    Caused by: com.aspose.words.FileCorruptedException: The document appears to be corrupted and cannot be loaded.
    at com.aspose.words.Document.a(Document.java:1376)
    at com.aspose.words.Document.b(Document.java:1363)
    at com.aspose.words.Document.a(Document.java:1251)
    at com.aspose.words.Document.(Document.java:149)
    at com.aspose.words.Document.(Document.java:123)
    at mis.pip.word.WordUtils.getDocumentContents(WordUtils.java:856)
    ... 19 more
    Caused by: java.lang.IllegalStateException: java.nio.charset.UnsupportedCharsetException: UTF-7
    at asposewobfuscated.mg.vr(Encoding.java:482)
    at asposewobfuscated.mg.vn(Encoding.java:241)
    at asposewobfuscated.mg.U(Encoding.java:460)
    at com.aspose.words.hb.iM(FileFormatDetector.java:246)
    at com.aspose.words.hb.g(FileFormatDetector.java:38)
    at com.aspose.words.Document.b(Document.java:1267)
    ... 23 more
    Caused by: java.nio.charset.UnsupportedCharsetException: UTF-7
    at java.nio.charset.Charset.forName(Charset.java:500)
    at asposewobfuscated.mg.vr(Encoding.java:478)
    ... 28 more

     
  •  06-18-2010, 8:43 AM 244248 in reply to 244241

    Re: FileCorruptedException

    Hi Barry,

    Can you try using the code below to load your document instead and seeing if that fixes it.

    Document doc = new Document(file.getAbsolutePath(), LoadFormat.DOC,"");
    doc.save("Document out.doc", SaveFormat.DOC);

    Thanks,


    Adam Skelton
    Programming Writer
    Aspose Auckland Team
     
  •  08-19-2010, 8:20 AM 254756 in reply to 244248

    Re: FileCorruptedException

    Hi,

    The code change you suggested was implemented and has been running in production for 3 weeks but the same error is still appearing sporadically (the stack trace is the same as the last I posted).

    I still cannot replicate the problem in dev or test.

    Do you have any more suggestions?

    Thanks.

     
  •  08-19-2010, 7:20 PM 254853 in reply to 254756

    Re: FileCorruptedException

    Hi Barry,

    Thanks for this additonal information. I am still unable to reproduce the problem on my side. However regarding what you said in your first post about creating two instances of the same document almost at the same time, this seems to be similar to what the customer on the other thread was doing with multiple threads.

    My suggestion regarding this is to try instead loading the document only once into memory and then create a copy of it for later use by cloning using doc.deepClone() instead of loading the document from disk twice. Please give feedback if this appears to solve the issue.

    Thanks,


    Adam Skelton
    Programming Writer
    Aspose Auckland Team
     
  •  09-06-2010, 3:41 AM 257166 in reply to 254853

    Re: FileCorruptedException

    Hi,

    Sorry for the delay, vacation and other project commitments have got in the way.

    From your previous post are you suggesting that Aspose Words does not support 2 pieces of code in the same thread loading the same the document?

    When we started our project we discussed the possibility of a document cache; a HashMap wrapper that will load a document from disc to memory on first request from a given thread; then use the in memory version whenever the same thread requests the same document. However, on testing the performance impact on reloading from disc was minimal and did not cause any errors at the time so we decided against the added layer of a document cache.

    Can you confirm that the official Aspose Words approach is not to load twice from disc? If so then I will return to plan A and implement a document cache.

    I must also say that I have been nothing but impressed with Aspose Words for the last 3 or so years I have been using it. I think this is the first time I have come up against an issue that I have had to code around.

    Thanks.

     
  •  09-06-2010, 4:23 AM 257170 in reply to 257166

    Re: FileCorruptedException

    Hi Barry,

    Thanks for this additional information.

    I was assuming this exception was occuring when two or more threads were trying to open the same document around the same time. Opening the same document twice in the same method should not cause any issue at all. Is there anything else being done in the same block of code as well? Also, the original issue on the other thread arouse from the Java charset decoder not working properly in a multi threaded enviroment. This was fixed in a previous version so should not be an issue anymore

    Yes, the recommended approach is when working with copies of the same document is to not load the same document twice but instead to worked with a cloned copy. I would highly recommend this in your case as the exception is occuring in the charset decoder. Cloning a document in memory would avoid this altogether and hopefully avoid this issue at the same time.

    Cheers for those kind words regarding Aspose.Words. If you have any further queries, please feel free to ask.

    Thanks,


    Adam Skelton
    Programming Writer
    Aspose Auckland Team
     
View as RSS news feed in XML