Index: applications/editors/josm/plugins/utilsplugin2/src/edu/princeton/cs/algs4/DijkstraSP.java
===================================================================
--- applications/editors/josm/plugins/utilsplugin2/src/edu/princeton/cs/algs4/DijkstraSP.java	(revision 28222)
+++ applications/editors/josm/plugins/utilsplugin2/src/edu/princeton/cs/algs4/DijkstraSP.java	(revision 28298)
@@ -48,8 +48,12 @@
         pq = new IndexMinPQ<Double>(G.V());
         pq.insert(s, distTo[s]);
+        int count = 0;
         while (!pq.isEmpty()) {
             int v = pq.delMin();
             for (DirectedEdge e : G.adj(v))
                 relax(e);
+            count++;
+            if (count > G.V())
+                throw new RuntimeException("Exceeded limit");
         }
 
Index: applications/editors/josm/plugins/utilsplugin2/src/org/openstreetmap/josm/plugins/utilsplugin2/replacegeometry/ReplaceGeometryUtils.java
===================================================================
--- applications/editors/josm/plugins/utilsplugin2/src/org/openstreetmap/josm/plugins/utilsplugin2/replacegeometry/ReplaceGeometryUtils.java	(revision 28222)
+++ applications/editors/josm/plugins/utilsplugin2/src/org/openstreetmap/josm/plugins/utilsplugin2/replacegeometry/ReplaceGeometryUtils.java	(revision 28298)
@@ -293,17 +293,28 @@
                     }
                 }
-                AssignmentProblem assignment = new AssignmentProblem(cost);
-                for (int i = 0; i < N; i++) {
-                    int nIdx = i;
-                    int gIdx = assignment.sol(i);
-                    if (cost[nIdx][gIdx] != Double.MAX_VALUE) {
-                        nodeAssoc.put(geometryPool.get(gIdx), nodePool.get(nIdx));
+                AssignmentProblem assignment;
+                try {
+                    assignment = new AssignmentProblem(cost);
+                    for (int i = 0; i < N; i++) {
+                        int nIdx = i;
+                        int gIdx = assignment.sol(i);
+                        if (cost[nIdx][gIdx] != Double.MAX_VALUE) {
+                            nodeAssoc.put(geometryPool.get(gIdx), nodePool.get(nIdx));
+                        }
                     }
-                }
-                // node will be moved, remove from pool
-                for (Node n : nodeAssoc.values()) {
-                    nodePool.remove(n);
-                }
-            } else { // use simple, faster, but less robust assignment method
+                    // node will be moved, remove from pool
+                    for (Node n : nodeAssoc.values()) {
+                        nodePool.remove(n);
+                    }
+                }
+                catch (Exception e) {
+                    useRobust = false;
+                    JOptionPane.showMessageDialog(Main.parent,
+                            tr("Exceeded iteration limit for robust method, using simpler method."),
+                            TITLE, JOptionPane.WARNING_MESSAGE);
+                    nodeAssoc = new HashMap<Node, Node>();
+                }
+            }
+            if (!useRobust) { // use simple, faster, but less robust assignment method
                 for (Node n : geometryPool) {
                     Node nearest = findNearestNode(n, nodePool);
