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

Ivan Ponomarev updated LANG-1813:
---------------------------------
    Description: 
Since commit 8c6294dd70f986088262a6b75a382cbc9e980543 (dated Jul 19, 2003), the 
Javadoc for {{org.apache.commons.lang3.ArrayUtils#hashCode(...)}} states that a 
{{null}} array input “returns zero”.

However, this has never been true in practice: the method delegates to {{{}new 
HashCodeBuilder().append(array).toHashCode(){}}}, and {{HashCodeBuilder}} 
returns *629* for {{null}} input (with its default initial value and 
multiplier). This creates a long-standing discrepancy between documented and 
actual behavior.

Given the age of the issue and the possibility that some legacy code may rely 
on the current behavior, changing the implementation to return 0 for {{null}} 
could be a breaking change. The safest resolution appears to be updating the 
Javadoc to match actual behavior (i.e., remove the “null returns zero” promise).

Reproducer: the following test fails
{code:java}
@Test
void testNullArrayHashCode() {
    // According to javadoc: "null returns zero"
    assertEquals(0, ArrayUtils.hashCode(null));
}{code}
 

Fix: https://github.com/apache/commons-lang/pull/1580

  was:
Since commit 8c6294dd70f986088262a6b75a382cbc9e980543 (dated Jul 19, 2003), the 
Javadoc for {{org.apache.commons.lang3.ArrayUtils#hashCode(...)}} states that a 
{{null}} array input “returns zero”.

However, this has never been true in practice: the method delegates to {{{}new 
HashCodeBuilder().append(array).toHashCode(){}}}, and {{HashCodeBuilder}} 
returns *629* for {{null}} input (with its default initial value and 
multiplier). This creates a long-standing discrepancy between documented and 
actual behavior.

Given the age of the issue and the possibility that some legacy code may rely 
on the current behavior, changing the implementation to return 0 for {{null}} 
could be a breaking change. The safest resolution appears to be updating the 
Javadoc to match actual behavior (i.e., remove the “null returns zero” promise).

Reproducer: the following test fails
{code:java}
@Test
void testNullArrayHashCode() {
    // According to javadoc: "null returns zero"
    assertEquals(0, ArrayUtils.hashCode(null));
}{code}


> `ArrayUtils#hashCode` Javadoc incorrectly states “null returns zero” (actual 
> result is 629)
> -------------------------------------------------------------------------------------------
>
>                 Key: LANG-1813
>                 URL: https://issues.apache.org/jira/browse/LANG-1813
>             Project: Commons Lang
>          Issue Type: Bug
>          Components: lang.*
>            Reporter: Ivan Ponomarev
>            Priority: Trivial
>
> Since commit 8c6294dd70f986088262a6b75a382cbc9e980543 (dated Jul 19, 2003), 
> the Javadoc for {{org.apache.commons.lang3.ArrayUtils#hashCode(...)}} states 
> that a {{null}} array input “returns zero”.
> However, this has never been true in practice: the method delegates to 
> {{{}new HashCodeBuilder().append(array).toHashCode(){}}}, and 
> {{HashCodeBuilder}} returns *629* for {{null}} input (with its default 
> initial value and multiplier). This creates a long-standing discrepancy 
> between documented and actual behavior.
> Given the age of the issue and the possibility that some legacy code may rely 
> on the current behavior, changing the implementation to return 0 for {{null}} 
> could be a breaking change. The safest resolution appears to be updating the 
> Javadoc to match actual behavior (i.e., remove the “null returns zero” 
> promise).
> Reproducer: the following test fails
> {code:java}
> @Test
> void testNullArrayHashCode() {
>     // According to javadoc: "null returns zero"
>     assertEquals(0, ArrayUtils.hashCode(null));
> }{code}
>  
> Fix: https://github.com/apache/commons-lang/pull/1580



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to