Uploaded image for project: 'Java Driver'
  1. Java Driver
  2. JAVA-3682

PolygonCoordinates Constructor throws NPE

    • Type: Icon: Bug Bug
    • Resolution: Duplicate
    • Priority: Icon: Major - P3 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);

            Assignee:
            Unassigned Unassigned
            Reporter:
            fstefan@ebay.com Florian Stefan
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: