-
Type: Bug
-
Resolution: Duplicate
-
Priority: Major - P3
-
None
-
Affects Version/s: 3.12.2
-
Component/s: None
-
None
-
Environment:Java 11
Description
The constructor of com.mongodb.client.model.geojson.PolygonCoordinates throws a NullPointerException when it is invoked with a List created by the factory method java.util.List.of().
Example
var polygonCoordinates = new PolygonCoordinates(List.of( new Position(-122.4547, 37.77475), new Position(-122.45302, 37.76638), new Position(-122.51033, 37.76398), new Position(-122.511, 37.77133), new Position(-122.4547, 37.77475) ));
Explanation
The factory method java.util.List.of() creates an instance of AbstractImmutableList. And the constructor of PolygonCoordinates checks if, e.g., its argument exterior contains a null value by invoking exterior.contains(null). But the method call AbstractImmutableList.contains(null) throws a NullPointerException.
Suggestion
Replace list.contains(null) with:
list.stream().anyMatch(Objects::isNull);
- duplicates
-
JAVA-3635 GeoJSON Geometry constructors throw NPE
- Closed