Package: josm / 0.0.svn5267+dfsg1-2

07-handle_deleted_nodes_without_coordinates.patch Patch series | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
From: Frederik Ramm <frederik@remote.org>
 Don-vip
Subject: Handle deleted nodes without coordinates after recent OSM API change
Origin: upstream, http://josm.openstreetmap.de/changeset/5326/josm
 upstream, http://josm.openstreetmap.de/changeset/5328/josm
 upstream, http://josm.openstreetmap.de/changeset/5332/josm
 upstream, http://josm.openstreetmap.de/changeset/5333/josm
 upstream, http://josm.openstreetmap.de/changeset/5334/josm
 upstream, http://josm.openstreetmap.de/changeset/5346/josm
 upstream, http://josm.openstreetmap.de/changeset/5349/josm
 upstream, http://josm.openstreetmap.de/changeset/5350/josm
 upstream, http://josm.openstreetmap.de/changeset/5351/josm
 upstream, http://josm.openstreetmap.de/changeset/5356/josm
Bug-Debian: http://bugs.debian.org/682315

---
 src/org/openstreetmap/josm/data/osm/DataSetMerger.java                      |   17 +++--
 src/org/openstreetmap/josm/data/osm/DatasetConsistencyTest.java             |   10 +--
 src/org/openstreetmap/josm/data/osm/Node.java                               |   17 ++---
 src/org/openstreetmap/josm/data/osm/visitor/paint/WireframeMapRenderer.java |   14 ++--
 src/org/openstreetmap/josm/data/validation/tests/DuplicateNode.java         |   27 +++++---
 src/org/openstreetmap/josm/gui/DefaultNameFormatter.java                    |   18 +++--
 src/org/openstreetmap/josm/gui/dialogs/InspectPrimitiveDialog.java          |   14 ++--
 src/org/openstreetmap/josm/gui/history/CoordinateInfoViewer.java            |   32 +++++++---
 src/org/openstreetmap/josm/io/GeoJSONWriter.java                            |    4 -
 src/org/openstreetmap/josm/io/OsmChangesetContentParser.java                |   13 ++--
 src/org/openstreetmap/josm/io/OsmHistoryReader.java                         |   13 ++--
 src/org/openstreetmap/josm/io/OsmReader.java                                |    6 +
 src/org/openstreetmap/josm/io/OsmWriter.java                                |    4 -
 13 files changed, 118 insertions(+), 71 deletions(-)

--- josm.orig/src/org/openstreetmap/josm/data/osm/Node.java
+++ josm/src/org/openstreetmap/josm/data/osm/Node.java
@@ -33,16 +33,12 @@ public final class Node extends OsmPrimi
 
     @Override
     public final void setCoor(LatLon coor) {
-        if(coor != null){
-            updateCoor(coor, null);
-        }
+        updateCoor(coor, null);
     }
 
     @Override
     public final void setEastNorth(EastNorth eastNorth) {
-        if(eastNorth != null) {
-            updateCoor(null, eastNorth);
-        }
+        updateCoor(null, eastNorth);
     }
 
     private void updateCoor(LatLon coor, EastNorth eastNorth) {
@@ -112,8 +108,11 @@ public final class Node extends OsmPrimi
             this.lon = ll.lon();
             this.east = eastNorth.east();
             this.north = eastNorth.north();
-        } else
-            throw new IllegalArgumentException();
+        } else {
+            this.lat = Double.NaN;
+            this.lon = Double.NaN;
+            invalidateEastNorthCache();
+        }
     }
 
     protected Node(long id, boolean allowNegative) {
@@ -177,7 +176,7 @@ public final class Node extends OsmPrimi
     @Override
     void setDataset(DataSet dataSet) {
         super.setDataset(dataSet);
-        if (!isIncomplete() && (getCoor() == null || getEastNorth() == null))
+        if (!isIncomplete() && isVisible() && (getCoor() == null || getEastNorth() == null))
             throw new DataIntegrityProblemException("Complete node with null coordinates: " + toString() + get3892DebugInfo());
     }
 
--- josm.orig/src/org/openstreetmap/josm/io/OsmReader.java
+++ josm/src/org/openstreetmap/josm/io/OsmReader.java
@@ -177,7 +177,11 @@ public class OsmReader extends AbstractR
 
     protected Node parseNode() throws XMLStreamException {
         NodeData nd = new NodeData();
-        nd.setCoor(new LatLon(Double.parseDouble(parser.getAttributeValue(null, "lat")), Double.parseDouble(parser.getAttributeValue(null, "lon"))));
+        String lat = parser.getAttributeValue(null, "lat");
+        String lon = parser.getAttributeValue(null, "lon");
+        if (lat != null && lon != null) {
+            nd.setCoor(new LatLon(Double.parseDouble(lat), Double.parseDouble(lon)));
+        }
         readCommon(nd);
         Node n = new Node(nd.getId(), nd.getVersion());
         n.setVisible(nd.isVisible());
--- josm.orig/src/org/openstreetmap/josm/io/OsmWriter.java
+++ josm/src/org/openstreetmap/josm/io/OsmWriter.java
@@ -135,7 +135,9 @@ public class OsmWriter extends XmlWriter
     public void visit(INode n) {
         if (n.isIncomplete()) return;
         addCommon(n, "node");
-        out.print(" lat='"+n.getCoor().lat()+"' lon='"+n.getCoor().lon()+"'");
+        if (n.getCoor() != null) {
+            out.print(" lat='"+n.getCoor().lat()+"' lon='"+n.getCoor().lon()+"'");
+        }
         if (!withBody) {
             out.println("/>");
         } else {
--- josm.orig/src/org/openstreetmap/josm/gui/DefaultNameFormatter.java
+++ josm/src/org/openstreetmap/josm/gui/DefaultNameFormatter.java
@@ -18,6 +18,7 @@ import java.util.Set;
 
 import org.openstreetmap.josm.Main;
 import org.openstreetmap.josm.data.coor.CoordinateFormat;
+import org.openstreetmap.josm.data.coor.LatLon;
 import org.openstreetmap.josm.data.osm.Changeset;
 import org.openstreetmap.josm.data.osm.IPrimitive;
 import org.openstreetmap.josm.data.osm.IRelation;
@@ -178,7 +179,9 @@ public class DefaultNameFormatter implem
             } else {
                 preset.nameTemplate.appendText(name, node);
             }
-            name.append(" \u200E(").append(node.getCoor().latToString(CoordinateFormat.getDefaultFormat())).append(", ").append(node.getCoor().lonToString(CoordinateFormat.getDefaultFormat())).append(")");
+            if (node.getCoor() != null) {
+                name.append(" \u200E(").append(node.getCoor().latToString(CoordinateFormat.getDefaultFormat())).append(", ").append(node.getCoor().lonToString(CoordinateFormat.getDefaultFormat())).append(")");
+            }
         }
         decorateNameWithId(name, node);
 
@@ -553,11 +556,14 @@ public class DefaultNameFormatter implem
         } else {
             sb.append(name);
         }
-        sb.append(" (")
-        .append(node.getCoords().latToString(CoordinateFormat.getDefaultFormat()))
-        .append(", ")
-        .append(node.getCoords().lonToString(CoordinateFormat.getDefaultFormat()))
-        .append(")");
+        LatLon coord = node.getCoords();
+        if (coord != null) {
+            sb.append(" (")
+            .append(coord.latToString(CoordinateFormat.getDefaultFormat()))
+            .append(", ")
+            .append(coord.lonToString(CoordinateFormat.getDefaultFormat()))
+            .append(")");
+        }
         decorateNameWithId(sb, node);
         return sb.toString();
     }
--- josm.orig/src/org/openstreetmap/josm/gui/dialogs/InspectPrimitiveDialog.java
+++ josm/src/org/openstreetmap/josm/gui/dialogs/InspectPrimitiveDialog.java
@@ -272,12 +272,14 @@ public class InspectPrimitiveDialog exte
         }
 
         void addCoordinates(Node n) {
-            add(tr("Coordinates: "),
-                    Double.toString(n.getCoor().lat()), ", ",
-                    Double.toString(n.getCoor().lon()));
-            add(tr("Coordinates (projected): "),
-                    Double.toString(n.getEastNorth().east()), ", ",
-                    Double.toString(n.getEastNorth().north()));
+            if (n.getCoor() != null) {
+                add(tr("Coordinates: "),
+                        Double.toString(n.getCoor().lat()), ", ",
+                        Double.toString(n.getCoor().lon()));
+                add(tr("Coordinates (projected): "),
+                        Double.toString(n.getEastNorth().east()), ", ",
+                        Double.toString(n.getEastNorth().north()));
+            }
         }
 
         void addReferrers(StringBuilder s, OsmPrimitive o) {
--- josm.orig/src/org/openstreetmap/josm/data/osm/DatasetConsistencyTest.java
+++ josm/src/org/openstreetmap/josm/data/osm/DatasetConsistencyTest.java
@@ -69,7 +69,7 @@ public class DatasetConsistencyTest {
 
     public void checkCompleteNodesWithoutCoordinates() {
         for (Node node:dataSet.getNodes()) {
-            if (!node.isIncomplete() && (node.getCoor() == null || node.getEastNorth() == null)) {
+            if (!node.isIncomplete() && node.isVisible() && (node.getCoor() == null || node.getEastNorth() == null)) {
                 printError("COMPLETE WITHOUT COORDINATES", "%s is not incomplete but has null coordinates", node);
             }
         }
@@ -79,9 +79,11 @@ public class DatasetConsistencyTest {
         for (Node n:dataSet.getNodes()) {
             if (!n.isIncomplete() && !n.isDeleted()) {
                 LatLon c = n.getCoor();
-                BBox box = new BBox(new LatLon(c.lat() - 0.0001, c.lon() - 0.0001), new LatLon(c.lat() + 0.0001, c.lon() + 0.0001));
-                if (!dataSet.searchNodes(box).contains(n)) {
-                    printError("SEARCH NODES", "%s not found using Dataset.searchNodes()", n);
+                if (c != null) {
+                    BBox box = new BBox(new LatLon(c.lat() - 0.0001, c.lon() - 0.0001), new LatLon(c.lat() + 0.0001, c.lon() + 0.0001));
+                    if (!dataSet.searchNodes(box).contains(n)) {
+                        printError("SEARCH NODES", "%s not found using Dataset.searchNodes()", n);
+                    }
                 }
             }
         }
--- josm.orig/src/org/openstreetmap/josm/gui/history/CoordinateInfoViewer.java
+++ josm/src/org/openstreetmap/josm/gui/history/CoordinateInfoViewer.java
@@ -14,6 +14,7 @@ import javax.swing.JLabel;
 import javax.swing.JPanel;
 
 import org.openstreetmap.josm.data.coor.CoordinateFormat;
+import org.openstreetmap.josm.data.coor.LatLon;
 import org.openstreetmap.josm.data.osm.history.HistoryNode;
 import org.openstreetmap.josm.data.osm.history.HistoryOsmPrimitive;
 import org.openstreetmap.josm.gui.NavigatableComponent;
@@ -255,19 +256,24 @@ public class CoordinateInfoViewer extend
             HistoryNode node = (HistoryNode)p;
             HistoryNode oppositeNode = (HistoryNode) opposite;
 
+            LatLon coord = node.getCoords();
+            LatLon oppositeCoord = oppositeNode.getCoords();
+
             // display the coordinates
             //
-            lblLat.setText(node.getCoords().latToString(CoordinateFormat.DECIMAL_DEGREES));
-            lblLon.setText(node.getCoords().lonToString(CoordinateFormat.DECIMAL_DEGREES));
+            lblLat.setText(coord != null ? coord.latToString(CoordinateFormat.DECIMAL_DEGREES) : tr("(none)"));
+            lblLon.setText(coord != null ? coord.lonToString(CoordinateFormat.DECIMAL_DEGREES) : tr("(none)"));
 
             // update background color to reflect differences in the coordinates
             //
-            if (node.getCoords().lat() == oppositeNode.getCoords().lat()) {
+            if (coord == oppositeCoord ||
+                    (coord != null && oppositeCoord != null && coord.lat() == oppositeCoord.lat())) {
                 lblLat.setBackground(Color.WHITE);
             } else {
                 lblLat.setBackground(BGCOLOR_DIFFERENCE);
             }
-            if (node.getCoords().lon() == oppositeNode.getCoords().lon()) {
+            if (coord == oppositeCoord ||
+                    (coord != null && oppositeCoord != null && coord.lon() == oppositeCoord.lon())) {
                 lblLon.setBackground(Color.WHITE);
             } else {
                 lblLon.setBackground(BGCOLOR_DIFFERENCE);
@@ -321,15 +327,23 @@ public class CoordinateInfoViewer extend
             HistoryNode node = (HistoryNode) p;
             HistoryNode oppositeNode = (HistoryNode) opposite;
 
+            LatLon coord = node.getCoords();
+            LatLon oppositeCoord = oppositeNode.getCoords();
+
             // update distance
             //
-            double distance = node.getCoords().greatCircleDistance(oppositeNode.getCoords());
-            if (distance > 0) {
-                lblDistance.setBackground(BGCOLOR_DIFFERENCE);
+            if (coord != null && oppositeCoord != null) {
+                double distance = coord.greatCircleDistance(oppositeNode.getCoords());
+                if (distance > 0) {
+                    lblDistance.setBackground(BGCOLOR_DIFFERENCE);
+                } else {
+                    lblDistance.setBackground(Color.WHITE);
+                }
+                lblDistance.setText(NavigatableComponent.getDistText(distance));
             } else {
-                lblDistance.setBackground(Color.WHITE);
+                lblDistance.setBackground(coord != oppositeCoord ? BGCOLOR_DIFFERENCE : Color.WHITE);
+                lblDistance.setText(tr("(none)"));
             }
-            lblDistance.setText(NavigatableComponent.getDistText(distance));
         }
     }
 }
--- josm.orig/src/org/openstreetmap/josm/io/GeoJSONWriter.java
+++ josm/src/org/openstreetmap/josm/io/GeoJSONWriter.java
@@ -103,6 +103,8 @@ public class GeoJSONWriter implements Vi
     }
 
     protected void appendCoord(LatLon c) {
-        out.append("[").append(c.lon()).append(", ").append(c.lat()).append("]");
+        if (c != null) {
+            out.append("[").append(c.lon()).append(", ").append(c.lat()).append("]");
+        }
     }
 }
--- josm.orig/src/org/openstreetmap/josm/io/OsmChangesetContentParser.java
+++ josm/src/org/openstreetmap/josm/io/OsmChangesetContentParser.java
@@ -102,16 +102,16 @@ public class OsmChangesetContentParser {
             return l;
         }
 
-        protected Double getMandatoryAttributeDouble(Attributes attr, String name) throws SAXException{
+        protected Double getAttributeDouble(Attributes attr, String name) throws SAXException{
             String v = attr.getValue(name);
             if (v == null) {
-                throwException(tr("Missing mandatory attribute ''{0}''.", name));
+                return null;
             }
             double d = 0.0;
             try {
                 d = Double.parseDouble(v);
             } catch(NumberFormatException e) {
-                throwException(tr("Illegal value for mandatory attribute ''{0}'' of type double. Got ''{1}''.", name, v));
+                throwException(tr("Illegal value for attribute ''{0}'' of type double. Got ''{1}''.", name, v));
             }
             return d;
         }
@@ -159,10 +159,11 @@ public class OsmChangesetContentParser {
             Date timestamp = DateUtils.fromString(v);
             HistoryOsmPrimitive primitive = null;
             if (type.equals(OsmPrimitiveType.NODE)) {
-                double lat = getMandatoryAttributeDouble(atts, "lat");
-                double lon = getMandatoryAttributeDouble(atts, "lon");
+                Double lat = getAttributeDouble(atts, "lat");
+                Double lon = getAttributeDouble(atts, "lon");
+                LatLon coor = (lat != null && lon != null) ? new LatLon(lat,lon) : null;
                 primitive = new HistoryNode(
-                        id,version,visible,user,changesetId,timestamp, new LatLon(lat,lon)
+                        id,version,visible,user,changesetId,timestamp,coor
                 );
 
             } else if (type.equals(OsmPrimitiveType.WAY)) {
--- josm.orig/src/org/openstreetmap/josm/io/OsmHistoryReader.java
+++ josm/src/org/openstreetmap/josm/io/OsmHistoryReader.java
@@ -98,16 +98,16 @@ public class OsmHistoryReader {
             return l;
         }
 
-        protected Double getMandatoryAttributeDouble(Attributes attr, String name) throws SAXException{
+        protected Double getAttributeDouble(Attributes attr, String name) throws SAXException{
             String v = attr.getValue(name);
             if (v == null) {
-                throwException(tr("Missing mandatory attribute ''{0}''.", name));
+                return null;
             }
             double d = 0.0;
             try {
                 d = Double.parseDouble(v);
             } catch(NumberFormatException e) {
-                throwException(tr("Illegal value for mandatory attribute ''{0}'' of type double. Got ''{1}''.", name, v));
+                throwException(tr("Illegal value for attribute ''{0}'' of type double. Got ''{1}''.", name, v));
             }
             return d;
         }
@@ -153,10 +153,11 @@ public class OsmHistoryReader {
             Date timestamp = DateUtils.fromString(v);
             HistoryOsmPrimitive primitive = null;
             if (type.equals(OsmPrimitiveType.NODE)) {
-                double lat = getMandatoryAttributeDouble(atts, "lat");
-                double lon = getMandatoryAttributeDouble(atts, "lon");
+                Double lat = getAttributeDouble(atts, "lat");
+                Double lon = getAttributeDouble(atts, "lon");
+                LatLon coord = (lat != null && lon != null) ? new LatLon(lat,lon) : null;
                 primitive = new HistoryNode(
-                        id,version,visible,user,changesetId,timestamp, new LatLon(lat,lon)
+                        id,version,visible,user,changesetId,timestamp,coord
                 );
 
             } else if (type.equals(OsmPrimitiveType.WAY)) {
--- josm.orig/src/org/openstreetmap/josm/data/osm/DataSetMerger.java
+++ josm/src/org/openstreetmap/josm/data/osm/DataSetMerger.java
@@ -178,8 +178,9 @@ public class DataSetMerger {
 
                 List<OsmPrimitive> referrers = target.getReferrers();
                 if (referrers.isEmpty()) {
-                    target.setDeleted(true);
+                    resetPrimitive(target);
                     target.mergeFrom(source);
+                    target.setDeleted(true);
                     it.remove();
                     flag = true;
                 } else {
@@ -202,11 +203,7 @@ public class DataSetMerger {
             // There are some more objects rest in the objectsToDelete set
             // This can be because of cross-referenced relations.
             for (OsmPrimitive osm: objectsToDelete) {
-                if (osm instanceof Way) {
-                    ((Way) osm).setNodes(null);
-                } else if (osm instanceof Relation) {
-                    ((Relation) osm).setMembers(null);
-                }
+                resetPrimitive(osm);
             }
             for (OsmPrimitive osm: objectsToDelete) {
                 osm.setDeleted(true);
@@ -215,6 +212,14 @@ public class DataSetMerger {
         }
     }
 
+    private final void resetPrimitive(OsmPrimitive osm) {
+        if (osm instanceof Way) {
+            ((Way) osm).setNodes(null);
+        } else if (osm instanceof Relation) {
+            ((Relation) osm).setMembers(null);
+        }
+    }
+
     /**
      * Merges the node list of a source way onto its target way.
      *
--- josm.orig/src/org/openstreetmap/josm/data/osm/visitor/paint/WireframeMapRenderer.java
+++ josm/src/org/openstreetmap/josm/data/osm/visitor/paint/WireframeMapRenderer.java
@@ -137,33 +137,33 @@ public class WireframeMapRenderer extend
            time to iterate through list twice, OTOH does not
            require changing the colour while painting... */
         for (final OsmPrimitive osm: data.searchRelations(bbox)) {
-            if (!osm.isDeleted() && !ds.isSelected(osm) && !osm.isDisabledAndHidden()) {
+            if (osm.isDrawable() && !ds.isSelected(osm) && !osm.isDisabledAndHidden()) {
                 osm.visit(this);
             }
         }
 
         for (final OsmPrimitive osm:data.searchWays(bbox)){
-            if (!osm.isDeleted() && !ds.isSelected(osm) && !osm.isDisabledAndHidden() && osm.isTagged()) {
+            if (osm.isDrawable() && !ds.isSelected(osm) && !osm.isDisabledAndHidden() && osm.isTagged()) {
                 osm.visit(this);
             }
         }
         displaySegments();
 
         for (final OsmPrimitive osm:data.searchWays(bbox)){
-            if (!osm.isDeleted() && !ds.isSelected(osm) && !osm.isDisabledAndHidden() && !osm.isTagged()) {
+            if (osm.isDrawable() && !ds.isSelected(osm) && !osm.isDisabledAndHidden() && !osm.isTagged()) {
                 osm.visit(this);
             }
         }
         displaySegments();
         for (final OsmPrimitive osm : data.getSelected()) {
-            if (!osm.isDeleted()) {
+            if (osm.isDrawable()) {
                 osm.visit(this);
             }
         }
         displaySegments();
 
         for (final OsmPrimitive osm: data.searchNodes(bbox)) {
-            if (!osm.isDeleted() && !ds.isSelected(osm) && !osm.isDisabledAndHidden())
+            if (osm.isDrawable() && !ds.isSelected(osm) && !osm.isDisabledAndHidden())
             {
                 osm.visit(this);
             }
@@ -343,7 +343,7 @@ public class WireframeMapRenderer extend
         g.setColor(col);
 
         for (RelationMember m : r.getMembers()) {
-            if (m.getMember().isIncomplete() || m.getMember().isDeleted()) {
+            if (m.getMember().isIncomplete() || !m.getMember().isDrawable()) {
                 continue;
             }
 
@@ -360,7 +360,7 @@ public class WireframeMapRenderer extend
 
                 boolean first = true;
                 for (Node n : m.getWay().getNodes()) {
-                    if (n.isIncomplete() || n.isDeleted()) {
+                    if (!n.isDrawable()) {
                         continue;
                     }
                     Point p = nc.getPoint(n);
--- josm.orig/src/org/openstreetmap/josm/data/validation/tests/DuplicateNode.java
+++ josm/src/org/openstreetmap/josm/data/validation/tests/DuplicateNode.java
@@ -43,35 +43,44 @@ public class DuplicateNode extends Test
 
         double precision = Main.pref.getDouble("validator.duplicatenodes.precision", 0.);
 
-        private LatLon RoundCoord(Node o) {
+        private LatLon roundCoord(LatLon coor) {
             return new LatLon(
-                    Math.round(o.getCoor().lat() / precision) * precision,
-                    Math.round(o.getCoor().lon() / precision) * precision
+                    Math.round(coor.lat() / precision) * precision,
+                    Math.round(coor.lon() / precision) * precision
                     );
         }
 
         @SuppressWarnings("unchecked")
         private LatLon getLatLon(Object o) {
             if (o instanceof Node) {
+                LatLon coor = ((Node) o).getCoor();
+                if (coor == null)
+                    return null;
                 if (precision==0)
-                    return ((Node) o).getCoor().getRoundedToOsmPrecision();
-                return RoundCoord((Node) o);
+                    return coor.getRoundedToOsmPrecision();
+                return roundCoord(coor);
             } else if (o instanceof List<?>) {
+                LatLon coor = ((List<Node>) o).get(0).getCoor();
+                if (coor == null)
+                    return null;
                 if (precision==0)
-                    return ((List<Node>) o).get(0).getCoor().getRoundedToOsmPrecision();
-                return RoundCoord(((List<Node>) o).get(0));
+                    return coor.getRoundedToOsmPrecision();
+                return roundCoord(coor);
             } else
                 throw new AssertionError();
         }
 
         @Override
         public boolean equals(Object k, Object t) {
-            return getLatLon(k).equals(getLatLon(t));
+            LatLon coorK = getLatLon(k);
+            LatLon coorT = getLatLon(t);
+            return coorK == coorT || (coorK != null && coorT != null && coorK.equals(coorT));
         }
 
         @Override
         public int getHashCode(Object k) {
-            return getLatLon(k).hashCode();
+            LatLon coorK = getLatLon(k);
+            return coorK == null ? 0 : coorK.hashCode();
         }
     }