From bac594e719fb09b34f2f4962482262223cbc4bf8 Mon Sep 17 00:00:00 2001 From: Taylor Smock Date: Fri, 22 Sep 2023 05:39:55 -0600 Subject: [PATCH] Fix #23186: NPE when validating relation with no complete members Signed-off-by: Taylor Smock --- .../validation/tests/StreetAddressTest.java | 10 ++++++---- .../validation/tests/StreetAddressTestTest.java | 17 +++++++++++++++++ 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/src/main/java/org/openstreetmap/josm/plugins/mapwithai/data/validation/tests/StreetAddressTest.java b/src/main/java/org/openstreetmap/josm/plugins/mapwithai/data/validation/tests/StreetAddressTest.java index 3cc88ba0..b547839d 100644 --- a/src/main/java/org/openstreetmap/josm/plugins/mapwithai/data/validation/tests/StreetAddressTest.java +++ b/src/main/java/org/openstreetmap/josm/plugins/mapwithai/data/validation/tests/StreetAddressTest.java @@ -156,10 +156,12 @@ private void realVisit(OsmPrimitive primitive) { } else { en = primitive.getBBox().getCenter().getEastNorth(ProjectionRegistry.getProjection()); } - long x = (long) Math.floor(en.getX() * gridDetail); - long y = (long) Math.floor(en.getY() * gridDetail); - final var point = new Point2D.Double(x, y); - primitiveCellMap.computeIfAbsent(point, p -> new ArrayList<>()).add(primitive); + if (en != null) { + long x = (long) Math.floor(en.getX() * gridDetail); + long y = (long) Math.floor(en.getY() * gridDetail); + final var point = new Point2D.Double(x, y); + primitiveCellMap.computeIfAbsent(point, p -> new ArrayList<>()).add(primitive); + } } } } diff --git a/src/test/unit/org/openstreetmap/josm/plugins/mapwithai/data/validation/tests/StreetAddressTestTest.java b/src/test/unit/org/openstreetmap/josm/plugins/mapwithai/data/validation/tests/StreetAddressTestTest.java index bdd7d969..a2933a18 100644 --- a/src/test/unit/org/openstreetmap/josm/plugins/mapwithai/data/validation/tests/StreetAddressTestTest.java +++ b/src/test/unit/org/openstreetmap/josm/plugins/mapwithai/data/validation/tests/StreetAddressTestTest.java @@ -17,8 +17,11 @@ import org.openstreetmap.josm.data.osm.BBox; import org.openstreetmap.josm.data.osm.DataSet; import org.openstreetmap.josm.data.osm.Node; +import org.openstreetmap.josm.data.osm.Relation; +import org.openstreetmap.josm.data.osm.RelationMember; import org.openstreetmap.josm.data.osm.Way; import org.openstreetmap.josm.data.validation.OsmValidator; +import org.openstreetmap.josm.gui.progress.NullProgressMonitor; import org.openstreetmap.josm.testutils.annotations.BasicPreferences; import org.openstreetmap.josm.testutils.annotations.Projection; import org.openstreetmap.josm.tools.Pair; @@ -138,4 +141,18 @@ void testNonRegression23062() { assertDoesNotThrow(() -> test.visit(node)); assertTrue(test.getErrors().isEmpty()); } + + @Test + void testNonRegression23186() { + final StreetAddressTest test = new StreetAddressTest(); + final Relation relation = TestUtils.newRelation( + "addr:city=Alpine " + "addr:housenumber=501 " + "addr:postcode=83128 " + "addr:state=WY " + + "addr:street=Palisades Reservoir County Road 101 " + "landuse=quarry " + + "name=Alota Sand & Gravel Inc " + "phone=+1-307-654-7558 " + "resource=gravel " + + "type=multipolygon", + new RelationMember("outer", new Way(968962006L)), new RelationMember("outer", new Way(968961999L))); + test.startTest(NullProgressMonitor.INSTANCE); + assertDoesNotThrow(() -> test.visit(relation)); + test.endTest(); + } }