[JAVA-3682] PolygonCoordinates Constructor throws NPE Created: 04/Apr/20  Updated: 06/Apr/20  Resolved: 06/Apr/20

Status: Closed
Project: Java Driver
Component/s: None
Affects Version/s: 3.12.2
Fix Version/s: None

Type: Bug Priority: Major - P3
Reporter: Florian Stefan Assignee: Unassigned
Resolution: Duplicate Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

Java 11


Issue Links:
Duplicate
duplicates JAVA-3635 GeoJSON Geometry constructors throw NPE Closed

 Description   

 

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);



 Comments   
Comment by Florian Stefan [ 04/Apr/20 ]

Ah, didn't see that. Thanks for the quick response!

Comment by Jeffrey Yemin [ 04/Apr/20 ]

Thanks for the report. This duplicates JAVA-3635 so I'm going to close this one out. That ticket is scheduled and so a fix should be available soon.

Generated at Thu Feb 08 09:00:11 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.