Uploaded image for project: 'XWiki Platform'
  1. XWiki Platform
  2. XWIKI-25806

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

    XMLWordPrintable

Details

    • Unknown
    • N/A
    • N/A

    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.

      Attachments

        Issue Links

          Activity

            People

              tmortagne Thomas Mortagne
              tmortagne Thomas Mortagne
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: