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

BaseGenericObjectPool IdentityWrapper equals violates Java spec

    XMLWordPrintableJSON

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Minor
    • Resolution: Fixed
    • Affects Version/s: 2.4.2
    • Fix Version/s: 2.4.3
    • Labels:
      None
    • Flags:
      Patch

      Description

      Noticed that the equals implementation assumes the other parameter can be successfully cast to IdentityWrapper:

              @Override
              @SuppressWarnings("rawtypes")
              public boolean equals(Object other) {
                  return ((IdentityWrapper) other).instance == instance;
              }
      

      (There is a chance that this could throw a ClassCastException.)

      See BC_EQUALS_METHOD_SHOULD_WORK_FOR_ALL_OBJECTS.

      I recommend:

              @Override
              @SuppressWarnings("rawtypes")
              public boolean equals(Object other) {
                  return other instanceof IdentityWrapper && ((IdentityWrapper) other).instance == instance;
              }
      

        Attachments

          Activity

            People

            • Assignee:
              Unassigned
              Reporter:
              awhitford Anthony Whitford
            • Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: