You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by "Phil Steitz (JIRA)" <ji...@apache.org> on 2015/10/25 21:15:27 UTC

[jira] [Commented] (POOL-306) BaseGenericObjectPool IdentityWrapper equals violates Java spec

    [ https://issues.apache.org/jira/browse/POOL-306?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14973419#comment-14973419 ] 

Phil Steitz commented on POOL-306:
----------------------------------

The check was left off for speed, knowing that in the only use of this inner class in [pool] the cast will succeed.  Since this class actually can be instantiated by clients, I am +0 for the proposed change, which I would hope would be optimized out anyway.  Any objections to this change?  Thanks for reviewing the code.

> 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
>
> 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)