Undefined behavior in Javadoc for Immutable Collections copyOf method when passing null argumentlist1 ll #7617
Closed
2 tasks done
Labels
type=defect
Bug, not working as expected
Guava Version
33.4.0-jre
Description
When using copyOf(Collection<? extends E> elements) method of Immutable collection Javadoc is unclear about the behavior when passing null argument. It specifies that method throws NullPointerException when passed Collection has at least at element that is null (For instance an ArrayList with one of the items with null value), BUT it is NOT specified (or at least it is NOT 100% clear) the behavior if the collection object itself is null.
*/
public static ImmutableSortedSet copyOf(Collection<? extends E> elements) {
There are2 possible behaviors: one to throw NullPointerException (current behavior), BUT also another behavior could be to return and empty Immutable collection. Javadoc should be specific about the implemented behavior
I would re-write Javadoc as
*** @throws NullPointerException if {@code elements} is null or any of the elements of the collection is null**
Example
Expected Behavior
Javadoc is fixed
*/
public static ImmutableSortedSet copyOf(Collection<? extends E> elements) {
Actual Behavior
Javadoc is unclear
Packages
No response
Platforms
No response
Checklist
I agree to follow the code of conduct.
I can reproduce the bug with the latest version of Guava available.
The text was updated successfully, but these errors were encountered: