commons-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Duncan Jones (JIRA)" <j...@apache.org>
Subject [jira] [Commented] (LANG-1039) HashCodeBuilder.reflectionHashCode(Object object) returns always the same result for any array
Date Fri, 26 Sep 2014 21:24:34 GMT

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

Duncan Jones commented on LANG-1039:
------------------------------------

Since there isn't a new use case being discussed, I'm content that the class can remain as
it is (functionally). To avoid any future confusion about how the method works, I've made
some adjustments to the Javadoc to make it clear that a constant result is return if the supplied
object has no fields to include in the hash code.

---

Author: djones
Date: Fri Sep 26 21:19:12 2014
New Revision: 1627889

URL: http://svn.apache.org/r1627889
Log:
Made it clear that the fields of the object form the hash code (LANG-1039).
Pulled magic values into constants.

Modified:
    commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/builder/HashCodeBuilder.java


> HashCodeBuilder.reflectionHashCode(Object object) returns always the same result for
any array
> ----------------------------------------------------------------------------------------------
>
>                 Key: LANG-1039
>                 URL: https://issues.apache.org/jira/browse/LANG-1039
>             Project: Commons Lang
>          Issue Type: Bug
>          Components: lang.builder.*
>    Affects Versions: 3.3.2
>         Environment: Windows 7, Java 6
>            Reporter: Bartosz Paszkowski
>
> HashCodeBuilder.reflectionHashCode(Object object) returns always the same result for
any array. The result is 17.
> There is no information in javadoc, that this method works in that way.
> The same situation in previous versions.
> *Example:*
> {code}
> public class HashCodeBuilderTest {
>     
>     public static void main(String[] args) {
>         
>         System.out.println(HashCodeBuilder.reflectionHashCode(new double[] {1, 1}));
>         System.out.println(HashCodeBuilder.reflectionHashCode(new double[] {2, 2}));
>         System.out.println(HashCodeBuilder.reflectionHashCode(new int[] {3, 3}));
>         System.out.println(HashCodeBuilder.reflectionHashCode(new int[] {4, 4}));
>         System.out.println(HashCodeBuilder.reflectionHashCode(new Long[] {5L, 5L}));
>         System.out.println(HashCodeBuilder.reflectionHashCode(new Double[] {null, null}));
>         System.out.println(HashCodeBuilder.reflectionHashCode(new Object[] {Boolean.FALSE,
1L, null}));
>         
>     }
> }
> {code}
> *Output:*
> {code}
> 17
> 17
> 17
> 17
> 17
> 17
> 17
> {code}
> *Fix example 1*
> First check if argument obj in HashCodeBuilder.reflectionHashCode(Object obj) is an array
and than use java.util.Arrays.hashCode(Object[] array)



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

Mime
View raw message