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!