commons-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Mark Thomas (JIRA)" <j...@apache.org>
Subject [jira] [Resolved] (POOL-306) BaseGenericObjectPool IdentityWrapper equals violates Java spec
Date Tue, 15 Mar 2016 14:34:34 GMT

     [ https://issues.apache.org/jira/browse/POOL-306?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]

Mark Thomas resolved POOL-306.
------------------------------
       Resolution: Fixed
    Fix Version/s: 2.4.3

The only problem the proposed change solves is the false positive reports from people and/or
tools that review the code without checking how this class is used.

While the change is functionally pointless I've no objection to it, if only on the grounds
it stops the false positive reports.

> BaseGenericObjectPool IdentityWrapper equals violates Java spec
> ---------------------------------------------------------------
>
>                 Key: POOL-306
>                 URL: https://issues.apache.org/jira/browse/POOL-306
>             Project: Commons Pool
>          Issue Type: Bug
>    Affects Versions: 2.4.2
>            Reporter: Anthony Whitford
>            Priority: Minor
>             Fix For: 2.4.3
>
>
> Noticed that the {{equals}} implementation assumes the {{other}} parameter can be successfully
cast to {{IdentityWrapper}}:
> {code}
>         @Override
>         @SuppressWarnings("rawtypes")
>         public boolean equals(Object other) {
>             return ((IdentityWrapper) other).instance == instance;
>         }
> {code}
> (There is a chance that this could throw a {{ClassCastException}}.)
> See [BC_EQUALS_METHOD_SHOULD_WORK_FOR_ALL_OBJECTS|http://findbugs.sourceforge.net/bugDescriptions.html#BC_EQUALS_METHOD_SHOULD_WORK_FOR_ALL_OBJECTS].
> I recommend:
> {code}
>         @Override
>         @SuppressWarnings("rawtypes")
>         public boolean equals(Object other) {
>             return other instanceof IdentityWrapper && ((IdentityWrapper) other).instance
== instance;
>         }
> {code}



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Mime
View raw message