You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by "Duncan Jones (JIRA)" <ji...@apache.org> on 2016/12/04 16:20:58 UTC

[jira] [Commented] (LANG-1203) Separated annotations HashCodeExclude and EqualsExclude break the general contract for the hashCode method in java.lang.Object

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

Duncan Jones commented on LANG-1203:
------------------------------------

There may be some reasons why excluding a value from a hash code makes sense. See [this StackOverflow question|http://stackoverflow.com/questions/4748211/java-equal-and-hashcode-based-on-different-fields] for some discussion on that topic.

I think there's an argument for having two annotations:

* HashCodeExclude
* EqualsAndHashCodeExclude

I can't see how you can exclude something from equals and not from hash code.


> Separated annotations HashCodeExclude and EqualsExclude break the general contract for the hashCode method in java.lang.Object
> ------------------------------------------------------------------------------------------------------------------------------
>
>                 Key: LANG-1203
>                 URL: https://issues.apache.org/jira/browse/LANG-1203
>             Project: Commons Lang
>          Issue Type: Bug
>          Components: lang.builder.*
>    Affects Versions: 3.5
>            Reporter: Frank Forster
>
> Since version 3.5-SNAPSHOT the annotations HashCodeExclude and EqualsExclude exist in component [lang.builder.*|https://git-wip-us.apache.org/repos/asf?p=commons-lang.git;a=tree;f=src/main/java/org/apache/commons/lang3/builder;hb=HEAD].
> A separated handling of both annotations breaks the general contract for the hashCode method in java.lang.Object ("If two objects are equal according to the equals(Object) method, then calling the hashCode method on each of the two objects must produce the same integer result.").
> Rather there should exist only one exclude annotation dedicated to both methods, like 'EqualsAndHashCodeExclude'.



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