ClassCastException happened when invoke Document.compare method

Hi friends:

I use Aspose.Word to compare words, it’s good. But recently I noticed it may fail in some cases and I don’t know why yet. The error message is like:

 exception:java.lang.ClassCastException: com.aspose.words.Run cannot be cast to com.aspose.words.Paragraph
 	at com.aspose.words.zzYMZ.zzZo(Unknown Source)
 	at com.aspose.words.zzM9.zzNk(Unknown Source)
 	at com.aspose.words.zzM9.zzZ(Unknown Source)
 	at com.aspose.words.zzM9.zz0r(Unknown Source)
 	at com.aspose.words.zzYMZ.zzYns(Unknown Source)
 	at com.aspose.words.zzYMZ.zzT(Unknown Source)
 	at com.aspose.words.zzYUE.zzZ(Unknown Source)
 	at com.aspose.words.zzYKZ.zzY(Unknown Source)
 	at com.aspose.words.zzYKZ.zzZ(Unknown Source)
 	at com.aspose.words.zzYKK.zzZ(Unknown Source)
 	at com.aspose.words.zzYWJ.zzYDL(Unknown Source)
 	at com.aspose.words.zzYMZ.zzYns(Unknown Source)
 	at com.aspose.words.zzYMZ.zzT(Unknown Source)
 	at com.aspose.words.zz3W.zzZys(Unknown Source)
 	at com.aspose.words.zz3W.zzZ(Unknown Source)
 	at com.aspose.words.Document.zzZ(Unknown Source)
 	at com.aspose.words.Document.compare(Unknown Source)
 	at com.myapp.service.impl.WordCompareServiceImpl.compareByAspose(WordCompareServiceImpl.java:150)

And my code is quite simple:

CompareOptions compareOptions = new CompareOptions();
compareOptions.setTarget(ComparisonTargetType.NEW);
compareOptions.setGranularity(Granularity.CHAR_LEVEL);
compareOptions.setIgnoreFormatting(true);

String author;
if (Boolean.TRUE.equals(needAuthor) && StringUtil.isNotBlank(compareResource.getUploaderName()))
{
    author = compareResource.getUploaderName();
}
else
{
    author = wordCompareConfig.getAuthor();
}

// If either document has a revision, an exception will be thrown
if (origin.getRevisions().getCount() == 0 && compare.getRevisions().getCount() == 0)
{
    try
    {
        origin.compare(compare, author, new Date(), compareOptions); // the exception occurs here
    }
    catch (Exception e)
    {
        log.error("compare failed", e);
        throw BizException.wrap(ServerResponseCode.OPERATION_ERROR, "compare failed");
    }
}

Is there something wrong in my code? Please help!

@longmenzhitong You code is correct. Could you please attach the source documents that cause this problem? We will check the issue on our side and provide you more information.

Thanks for your reply and of course, there are the documents: 1.docx (56 KB) 2.docx (56.5 KB)

@longmenzhitong
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-25860

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.

Ok. One last question: once there is a result, how can I know?

@longmenzhitong We will notify your here in this forum thread once the issue is resolved or we have more information for you.

Ok. Thanks very much!

1 Like

The issues you have found earlier (filed as WORDSNET-25860) have been fixed in this Aspose.Words for Java 23.10 update.