You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by "Partha Paul (Jira)" <ji...@apache.org> on 2026/03/26 23:36:00 UTC
[jira] [Created] (COLLECTIONS-886) CompositeSet.addComposited(Set) does not throw NullPointerException when null is passed, which contradicts current Javadoc comment
Partha Paul created COLLECTIONS-886:
---------------------------------------
Summary: CompositeSet.addComposited(Set) does not throw NullPointerException when null is passed, which contradicts current Javadoc comment
Key: COLLECTIONS-886
URL: https://issues.apache.org/jira/browse/COLLECTIONS-886
Project: Commons Collections
Issue Type: Bug
Affects Versions: 4.5.0
Environment: commons-collections: 4.5.0 (and previous versions)
java: 17.0.12
Reporter: Partha Paul
The Javadoc for {{CompositeSet.addComposited(Set)}} explicitly states that a {{NullPointerException}} should be thrown when the {{set}} parameter is {{{}null{}}}. However, the current implementation contains a null guard ( {{if set != null}} ) that silently ignores null input and doesn't throw an exception.
h5. Javadoc (Current) contains
{code:java}
@throws NullPointerException if {@code set} is null
{code}
h5. Implementation (Current)
{code:java}
public synchronized void addComposited(final Set<E> set) {
if (set != null) {
...
all.add(set);
}
}
{code}
h5. Steps to Reproduce
{code:java}
@Test
void testNullPointerExceptionOnAddCompositedWithNullSet() {
CompositeSet<String> set = new CompositeSet<>(new HashSet<>());
assertThrows(NullPointerException.class, () -> set.addComposited(null));
}
{code}
The test above will fail because no {{NullPointerException}} is thrown.
Happy to submit pr by fixing the javadoc by removing the {{NullPointerException}} clause!
--
This message was sent by Atlassian Jira
(v8.20.10#820010)