Uploaded image for project: 'JBoss Cache'
  1. JBoss Cache
  2. JBCACHE-1412

Marshaller uses equals() to test object equality instead of identity when performing reference counting

    Details

    • Workaround:
      Workaround Exists
    • Workaround Description:
      Hide

      Make sure your objects properly implement equals() and hashCode()! This only comes up if you have a poor equals() or hashCode() implementation.

      Show
      Make sure your objects properly implement equals() and hashCode()! This only comes up if you have a poor equals() or hashCode() implementation.
    • Estimated Difficulty:
      Medium

      Description

      The marshalling logic in TreeCacheMarshaller140 uses a HashMap as store of objects already written so it can replace subsequent writes of the same object with a magic number. Use of a HashMap is incorrect, as magic number replacement should only occur if an object with the same identity is detected, not one that just satisfies equals() but not ==.

      Either a custom map that uses System.identityHashCode() for hashing and == instead of equals() for equality is needed, or the map key should be System.identityHashCode(). Note the Object.hashCode() javadocs do not absolutely guarantee uniqueness in System.identityHashCode(), so a custom map is probably better:

      "As much as is reasonably practical, the hashCode method defined by class Object does return distinct integers for distinct objects. (This is typically implemented by converting the internal address of the object into an integer, but this implementation technique is not required by the JavaTM programming language.)"

      Non-uniquenesss in System.identityHashCode() might be more of an issue in systems with large heaps that can't be addressed with 32 bits.

        Gliffy Diagrams

          Attachments

            Issue Links

              Activity

                People

                • Assignee:
                  manik Manik Surtani
                  Reporter:
                  brian.stansberry Brian Stansberry
                • Votes:
                  0 Vote for this issue
                  Watchers:
                  0 Start watching this issue

                  Dates

                  • Created:
                    Updated:
                    Resolved: