I have a Java Servlet to generate document with Aspose Word Library 16.7. Many times when the Word Document is read in the http request and passed to the Aspose Words Document:
com.aspose.words.Document doc = new com.aspose.words.Document(inputstream);
I receive the following error:
java.lang.ClassCastException: Cannot cast class java.lang.Integer to class java.lang.Boolean at com.aspose.words.zzZ4V.zzZti(Unknown Source) at com.aspose.words.zzZ4V.zzZ(Unknown Source) at com.aspose.words.zzAW.visitSectionStart(Unknown Source)
at com.aspose.words.Section.zzZ(Unknown Source)
at com.aspose.words.CompositeNode.acceptCore(Unknown Source)
at com.aspose.words.Section.accept(Unknown Source)
at com.aspose.words.CompositeNode.acceptChildren(Unknown Source)
at com.aspose.words.CompositeNode.acceptCore(Unknown Source)
at com.aspose.words.Document.accept(Unknown Source)
at com.aspose.words.zzAW.zzZ(Unknown Source)
at com.aspose.words.Document.zzY(Unknown Source)
at com.aspose.words.Document.zzZ(Unknown Source)
at com.aspose.words.Document.<init>(Unknown Source)
at com.aspose.words.Document.<init>(Unknown Source)
at com.aspose.words.Document.<init>(Unknown Source)
I can’t reproduce this error. When I try local with this document. I have no problem
It is a memory problem?
Should I use a BufferedInputStream?
Why the document cannot be parsed?.
Any ideas?
Could you tell me please where and why this ClassCastException occured . I can’t see anything because your source code is obfuscated.
Thanks for your inquiry. To ensure a timely and accurate response, please attach the following resources here for testing:
Your input Word document.
Please share your working environment e.g. operating system, Java version etc.
Please share the source code without compilation errors that helps us to reproduce your problem on our end and attach it here for testing.
As soon as you get these pieces of information ready, we’ll start investigation into your issue and provide you more information. Thanks for your cooperation.
PS: To attach these resources, please zip them and Click ‘Reply’ button that will bring you to the ‘reply page’ and there at the bottom you can include any attachments with that post by clicking the ‘Add/Update’ button.
I’ve seen the same behavior in my case, but it’s not really reproducible currently.
As it seems, after some time of opening and working with various Word documents, documents cannot be loaded anymore by using
Document doc = new Document(inputStream);
(where inputStream is usually a ByteArrayInputStream, but that shouldn’t matter). It’s not a specific document that throws this exception, most (or even all) documents cannot be opened afterwards. Stacktrace (with version 16.2.0):
Thanks for your inquiry. We suggest you please upgrade to the latest version of Aspose.Words for Java 17.4. Hope this helps you.
If you still face problem, please share the requested detail in my previous post here for testing. We will investigate the issue and provide you more information on this. Unfortunately, it is difficult to say what the problem is without document. We need your document to reproduce the problem. Thanks for your cooperation.
Thanks for your response. As mentioned before, I cannot reproduce it locally and it’s not a specific document that doesn’t work anymore afterwards. After loading and processing various documents (in different threads concurrently), a point seems to be reached where no further documents (or maybe some documents will work, but most will fail) can be loaded, even those that worked before. Trying the newest version of Aspose Words and check if this issue was already fixed will only work when I were able to successfully reproduce it locally.
I will try this and provide you with all the information needed. For this it would be really great to get a hint what could have gone wrong (based on the provided stack trace). I assume that reading a specific attribute did not return the expected boolean value but an integer value instead (which results in the ClassCastException). I might guess that it’s like a visibility check for a section within the word document, but I’m not really sure. With more information I might be able to produce a document and some code that will result in the same behavior. It will most likely not occur if the document is only loaded once. It might be more likely that the issue appears if documents are processed concurrently (threading issue, static state).
Thanks for sharing the detail. The ClassCastException is used to indicate that the application’s code has attempted to cast a specific object to a class of which it is not an instance. For example, an Integer object cannot be casted to a String object.
We need your document and code example to reproduce this issue at our end. As soon as you get these pieces of information ready, we’ll start investigation into your issue and provide you more information. Thanks for your cooperation.
If I’m able to reproduce it locally, i will let you know and provide you with the required information.
I encountered two other exceptions beside the already mentioned ClassCastException (see stacktraces below). Same circumstances apply as for the initial one.
Documents are loaded and processed in various threads, but a single document is always processed in only one thread.
Stacktrace 1 (loading a document)
Caused by: com.aspose.words.FileCorruptedException: The document appears to be corrupted and cannot be loaded.
at com.aspose.words.FileFormatUtil.zzZ
at com.aspose.words.Document.zzY
at com.aspose.words.Document.zzZ
at com.aspose.words.Document.
at com.aspose.words.Document.
at com.aspose.words.Document.
…
Caused by: java.lang.IllegalArgumentException: duplicate
at asposewobfuscated.zzGJ.add
at com.aspose.words.zzZ65.zzZvQ
at com.aspose.words.zzZ65.zzBa
at com.aspose.words.zz5.zzUS
at com.aspose.words.zz5.zzUT
at com.aspose.words.zzZ65.zzZvT
at com.aspose.words.zzZ65.zzZ
at com.aspose.words.zzBH.visitSectionStart
at com.aspose.words.Section.zzZ
at com.aspose.words.CompositeNode.acceptCore
at com.aspose.words.Section.accept
at com.aspose.words.CompositeNode.acceptChildren
at com.aspose.words.CompositeNode.acceptCore
at com.aspose.words.Document.accept
at com.aspose.words.zzBH.zzZ
at com.aspose.words.Document.zzY
Stacktrace 2(converting document to html)
Caused by: java.lang.IllegalStateException: Requested default value for an unknown attribute.
at com.aspose.words.zz5.zzUS
at com.aspose.words.zz5.zzUT
at com.aspose.words.zzZ65.zzUr
at com.aspose.words.Document.fetchInheritedSectionAttr
at com.aspose.words.FootnoteOptions.zzUT
at com.aspose.words.FootnoteOptions.getNumberStyle
at com.aspose.words.zz0E.zzZYK
at com.aspose.words.zz0E.zzZYQ
at com.aspose.words.zzZW7.zzZ
at com.aspose.words.Document.zzZ
at com.aspose.words.Document.zzZ
at com.aspose.words.Document.zzZ
at com.aspose.words.Document.save
A found a forum thread with the same exception and a similar circumstances (my stacktraces are from a Windows machine too): IllegalArgumentException: duplicate
Hopefully the additional stacktraces might give you some information what could have go wrong. If you have any hints, just let me know, it might make it easier for me to reproduce it locally.
Thanks for your inquiry. As requested earlier, We need your document and code example to reproduce these issues at our end. Please share the requested detail for testing. Thanks for your cooperation.
I’ve finally been able to reproduce this issue. This post is merely for others having the same exceptions and to close this thread.
The various errors occur in a environment with different threads when a locale is set using CurrentThreadSettings.getLocaleSettings(). Depending on what locale is set the errors might occur (see Java class for examples).
Is still reproducable with 16.8, but seems to be fixed with 16.10, probably by one of:
WORDSNET - 13826 System.InvalidCastException is thrown while loading document under different Culture
WORDSNET - 13979 System.InvalidCastException is thrown while loading document under different Culture
public static void main(String[] args) throws Exception
{
final int numberOfThreads = 2; // works when only one thread is involved
final int queueSize = 500;
final ConcurrentLinkedQueue <Integer> queue = new ConcurrentLinkedQueue <> ();
for (int i = 0; i <queueSize; i++)
{
queue.add(i);
}
final AtomicInteger failureCount = new AtomicInteger();
List <Thread> threads = new ArrayList <> ();
for (int i = 0; i <numberOfThreads; i++)
{
final int threadNo = i;
Runnable runnable = new Runnable()
{
@Override
public void run()
{
Integer processingNo;
while ((processingNo = queue.poll()) != null)
{
try
{
System.out.println("Thread " + String.format("%03d", threadNo) + " processing " + String.format("%03d", processingNo));
execute();
}
catch (Exception e)
{
System.err.println("Thread " + String.format("%03d", threadNo) + " processing " + String.format("%03d", processingNo) + " failed (#" + failureCount.incrementAndGet() + "): " + e.getMessage());
}
}
}
};
Thread thread = new Thread(runnable);
thread.start();
threads.add(thread);
}
for (Thread thread: threads)
{
thread.join();
}
System.out.println("All threads joined");
}
private static void execute() throws Exception
{
// Examples:
// - fails with de_CH and de
// - fails with de and null
// - works with de and en
execute(new Locale("de", "CH"));
execute(new Locale("de"));
// execute(new Locale("en"));
// execute(null);
}
private static void execute(Locale locale) throws Exception
{
if (locale != null)
{
// <17.3
CurrentThreadSettings.getLocaleSettings().set(locale);
//>= 17.3
// CurrentThreadSettings.setLocale(locale);
}
try
{
new Document();
}
finally
{
if (locale != null)
{
// <17.3
CurrentThreadSettings.getLocaleSettings().remove();
}
}
}
We have tested the scenario using latest version of Aspose.Words for Java 17.11 and have not found the shared issue. Please upgrade to the latest version of Aspose.Words for Java 17.11.
Cookie Notice
To provide you with the best experience, we use cookies for personalization, analytics, and ads. By using our site, you agree to our cookie policy.
Enables storage, such as cookies, related to analytics.
Sets consent for sending user data to Google for online advertising purposes.
Sets consent for personalized advertising.
Cookie Notice
To provide you with the best experience, we use cookies for personalization, analytics, and ads. By using our site, you agree to our cookie policy.
More info
Enables storage, such as cookies, related to analytics.
Enables storage, such as cookies, related to advertising.
Sets consent for sending user data to Google for online advertising purposes.
Sets consent for personalized advertising.
Cookie Notice
To provide you with the best experience, we use cookies for personalization, analytics, and ads. By using our site, you agree to our cookie policy.
More info
Enables storage, such as cookies, related to analytics.
Enables storage, such as cookies, related to advertising.
Sets consent for sending user data to Google for online advertising purposes.