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

BaseGenericObjectPool IdentityWrapper equals violates Java spec

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Minor
    • Resolution: Fixed
    • 2.4.2
    • 2.4.3
    • None
    • 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

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

            Dates

              Created:
              Updated:
              Resolved: