You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by "Piotr Kaczmarski (JIRA)" <ji...@apache.org> on 2014/09/25 19:16:33 UTC

[jira] [Comment Edited] (LANG-1039) HashCodeBuilder.reflectionHashCode(Object object) returns always the same result for any array

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

Piotr Kaczmarski edited comment on LANG-1039 at 9/25/14 5:16 PM:
-----------------------------------------------------------------

{quote}
The first line in the Javadoc for the HashCodeBuilder is:
bq. Assists in implementing Object.hashCode() methods.
{quote}

and the second line in the Javadoc is:
bq. This class enables a good hashCode method to be built for any class.

This is the interface:
reflectionHashCode(Object object, String... excludeFields)
It promises, that it will work for any given Object.
It doesnt say, that it isn't for arrays.
Neither does Javadoc.

So I see two options:
1. To add statement like: "Warning: This method provides constant result of 17 for any array."
2. To refactor this method for consistency.

Living it the way it is is simply irresponsible.




was (Author: halfdan):
{quote}
The first line in the Javadoc for the HashCodeBuilder is:
bq. Assists in implementing Object.hashCode() methods.
{quote}

and the second line in the Javadoc is:
bq. This class enables a good hashCode method to be built for any class.



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