Uploaded image for project: 'Commons Pool'
  1. Commons Pool
  2. POOL-220

PooledObject#compareTo() is not guaranteed consistent with equals

    XMLWordPrintableJSON

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 2.0
    • Labels:
      None

      Description

      PooledObject#compareTo only returns 0 if the getLastRuntime values are equal AND the identityHashCodes are equal.

      This will work OK for the identity comparison, but is not guaranteed to work in all other cases.

      It's possible for two distinct objects to have the same identityHashCode.
      If such objects happen to have the same lastRuntime, then compareTo will return 0, but equals (which defaults to Object#equals) will return false.

      It's not very likely, but it is possible.

      A simple fix would be to define equals() to return true only in the case that the lastRuntime values and identityHashCodes are equal.

      Also, the Javadoc for the compareTo method ought to make clear what the ordering is intended to achieve.

        Attachments

          Activity

            People

            • Assignee:
              Unassigned
              Reporter:
              sebb Sebb
            • Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: