Index: trunk/src/org/openstreetmap/josm/data/osm/IWaySegment.java
===================================================================
--- trunk/src/org/openstreetmap/josm/data/osm/IWaySegment.java	(revision 19064)
+++ trunk/src/org/openstreetmap/josm/data/osm/IWaySegment.java	(revision 19065)
@@ -18,4 +18,5 @@
  */
 public class IWaySegment<N extends INode, W extends IWay<N>> implements Comparable<IWaySegment<N, W>> {
+    protected static final String NOT_A_SEGMENT = "Node pair is not a single segment of the way!";
 
     private final W way;
@@ -97,5 +98,5 @@
      * @param second second node
      * @return way segment
-     * @throws IllegalArgumentException if the node pair is not part of way
+     * @throws IllegalArgumentException if the node pair is not a single segment of the way
      */
     public static <N extends INode, W extends IWay<N>> IWaySegment<N, W> forNodePair(W way, N first, N second) {
@@ -103,4 +104,6 @@
         while (endIndex > 0) {
             final int indexOfFirst = way.getNodes().subList(0, endIndex).lastIndexOf(first);
+            if (indexOfFirst < 0)
+                break;
             if (second.equals(way.getNode(indexOfFirst + 1))) {
                 return new IWaySegment<>(way, indexOfFirst);
@@ -108,5 +111,5 @@
             endIndex--;
         }
-        throw new IllegalArgumentException("Node pair is not part of way!");
+        throw new IllegalArgumentException(NOT_A_SEGMENT);
     }
 
@@ -162,14 +165,16 @@
     @Override
     public int compareTo(IWaySegment o) {
+        if (o == null)
+            return -1;
         final W thisWay;
         final IWay<?> otherWay;
         try {
             thisWay = toWay();
-            otherWay = o == null ? null : o.toWay();
+            otherWay = o.toWay();
         } catch (ReflectiveOperationException e) {
             Logging.error(e);
             return -1;
         }
-        return o == null ? -1 : (equals(o) ? 0 : thisWay.compareTo(otherWay));
+        return equals(o) ? 0 : thisWay.compareTo(otherWay);
     }
 
Index: trunk/src/org/openstreetmap/josm/data/osm/WaySegment.java
===================================================================
--- trunk/src/org/openstreetmap/josm/data/osm/WaySegment.java	(revision 19064)
+++ trunk/src/org/openstreetmap/josm/data/osm/WaySegment.java	(revision 19065)
@@ -26,5 +26,5 @@
      * @param second second node
      * @return way segment
-     * @throws IllegalArgumentException if the node pair is not part of way
+     * @throws IllegalArgumentException if the node pair is not single a segment of the way
      */
     public static WaySegment forNodePair(Way way, Node first, Node second) {
@@ -32,4 +32,6 @@
         while (endIndex > 0) {
             final int indexOfFirst = way.getNodes().subList(0, endIndex).lastIndexOf(first);
+            if (indexOfFirst < 0)
+                break;
             if (second.equals(way.getNode(indexOfFirst + 1))) {
                 return new WaySegment(way, indexOfFirst);
@@ -37,5 +39,5 @@
             endIndex--;
         }
-        throw new IllegalArgumentException("The node pair is not consecutive part of the way!");
+        throw new IllegalArgumentException(IWaySegment.NOT_A_SEGMENT);
     }
 
