This issue has been created
 
 
XWiki Platform / cid:jira-generated-image-avatar-f44e646c-ac29-42e9-b516-039d5ac11dce XWIKI-25806 Open

NumberProperty#equals throws a ClassCastException when compared with a property of another type

 
View issue   ยท   Add comment
 

Issue created

 
cid:jira-generated-image-avatar-2b451a16-f49a-4771-a0c8-83cc8c70b121 Thomas Mortagne created this issue on 19/Nov/26 15:19
 
Summary: NumberProperty#equals throws a ClassCastException when compared with a property of another type
Issue Type: cid:jira-generated-image-avatar-f44e646c-ac29-42e9-b516-039d5ac11dce Bug
Affects Versions: 5.2-milestone-1
Assignee: Unassigned
Components: Old Core
Created: 19/Nov/26 15:19
Priority: cid:jira-generated-image-static-major-fd34f929-3e2b-481c-857a-27f118fa6587 Major
Reporter: Thomas Mortagne
Description:

NumberProperty#equals throws a ClassCastException instead of returning false when it is compared with a property of another type (for example a StringProperty, when an object property is stored with a different type than the one of the same object in an extension XAR):

java.lang.ClassCastException: class com.xpn.xwiki.objects.StringProperty cannot be cast to class com.xpn.xwiki.objects.NumberProperty
    at com.xpn.xwiki.objects.NumberProperty.equals(NumberProperty.java:111)
    at com.xpn.xwiki.objects.BaseCollection.equals(BaseCollection.java:839)
    at com.xpn.xwiki.objects.BaseObject.equals(BaseObject.java:340)
    at com.xpn.xwiki.doc.XWikiDocument.equalsData(XWikiDocument.java:5124)
    at org.xwiki.extension.xar.internal.handler.XarExtensionJobFinishedListener.maybeDeletePages(XarExtensionJobFinishedListener.java:251)
    at org.xwiki.extension.xar.internal.handler.XarExtensionJobFinishedListener.onEvent(XarExtensionJobFinishedListener.java:156)

As reported in XWIKI-25633, this happens for example when uninstalling a XAR extension: comparing a page with the version provided by the extension fails, so the page is kept, and the uninstall job ends with an error (logged as "Failed to load attachments", which is misleading).

BaseElement#equals does check that both elements have the same class, but NumberProperty#equals evaluates ((NumberProperty) obj).getValue() as an argument of EqualsBuilder#append, so the cast is executed even when appendSuper(super.equals(obj)) already returned false. The other property types do not have this problem since they return before casting.