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

Gary D. Gregory resolved LANG-1820.
-----------------------------------
    Fix Version/s: 3.21.0
       Resolution: Fixed

> [javadoc] Fix ObjectUtils.anyNull(Object) for empty arrays
> ----------------------------------------------------------
>
>                 Key: LANG-1820
>                 URL: https://issues.apache.org/jira/browse/LANG-1820
>             Project: Commons Lang
>          Issue Type: Bug
>    Affects Versions: 3.20.0
>         Environment: Commons Lang version: (3.20.0 including the current 
> snapshot version)
> Java version: (javac 17.0.12)
>            Reporter: Partha Paul
>            Priority: Major
>              Labels: docuentation, documentation-update, implementation
>             Fix For: 3.21.0
>
>
> The Javadoc for {{ObjectUtils.anyNull(Object...)}} {{@param}} states that 
> {{true}} should be returned when the array is null or empty. However, the 
> current implementation delegates to {{{}!allNotNull(values){}}}, and 
> {{allNotNull()}} returns {{true}} for empty arrays, causing {{anyNull()}} to 
> return {{false}} for empty arrays. This directly contradicts its own 
> documented contract.
> The two methods have conflicting contracts for the empty array case currently:
> {{allNotNull()}} Javadoc states: {{@returns true}} if all values in the array 
> are not null or array contains no elements
> {{anyNull()}} Javadoc states: {{@returns true}} if the array is null or empty
> Since {{anyNull()}} is implemented as {{{}!allNotNull(){}}}, it cannot 
> satisfy both contracts simultaneously for the empty array case.
> h5. Implementation (Current)
> {code:java}
> public static boolean anyNull(final Object... values) {
>     return !allNotNull(values);
> }
> public static boolean allNotNull(final Object... values) {
>     return values != null && Stream.of(values).noneMatch(Objects::isNull);
> }
> {code}
> h5. Steps to Reproduce
> {code:java}
> @Test
> void testAnyNull_EmptyArray_ReturnsTrue() {
>     assertTrue(ObjectUtils.anyNull(), "anyNull should return true for an 
> empty array per Javadoc");
>     assertTrue(ObjectUtils.anyNull(new Object[] {}), "anyNull should return 
> true for an empty array per Javadoc");
> }
> {code}
> Both assertions will fail because {{anyNull()}} returns {{false}} for empty 
> arrays.
> h5. Proposed Fixed
> Update the documentation to reflect this case to something like
> {code:java}
>  @returns false if the array contains no elements {code}
> Updated the documentation in this pr: 
> [https://github.com/apache/commons-lang/pull/1621|https://github.com/apache/commons-lang/pull/1621]



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

Reply via email to