[
https://issues.apache.org/jira/browse/LANG-1820?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
Partha Paul updated LANG-1820:
------------------------------
Description:
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.
was:
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. 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.
Environment:
Commons Lang version: (3.20.0 including the current snapshot version)
Java version: (javac 17.0.12)
> ObjectUtils.anyNull(Object) returns false for empty array, which contradicts
> Javadoc which states true should be returned
> -------------------------------------------------------------------------------------------------------------------------
>
> 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
>
> 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.
--
This message was sent by Atlassian Jira
(v8.20.10#820010)