Index: /applications/editors/josm/plugins/wayselector/build.xml
===================================================================
--- /applications/editors/josm/plugins/wayselector/build.xml	(revision 23099)
+++ /applications/editors/josm/plugins/wayselector/build.xml	(revision 23100)
@@ -31,5 +31,5 @@
 
 	<!-- enter the SVN commit message -->
-	<property name="commit.message" value="Adjust to read-only JOSM selection object" />
+	<property name="commit.message" value="Do not mutate the collection of selected ways. Convert TAB to spaces." />
 	<!-- enter the *lowest* JOSM version this plugin is currently compatible with -->
 	<property name="plugin.main.version" value="3095" />
Index: /applications/editors/josm/plugins/wayselector/src/org/openstreetmap/josm/plugins/wayselector/WaySelection.java
===================================================================
--- /applications/editors/josm/plugins/wayselector/src/org/openstreetmap/josm/plugins/wayselector/WaySelection.java	(revision 23099)
+++ /applications/editors/josm/plugins/wayselector/src/org/openstreetmap/josm/plugins/wayselector/WaySelection.java	(revision 23100)
@@ -18,6 +18,4 @@
  */
 public class WaySelection {
-    /** selected ways */
-    Collection<Way> ways;
     /** outer endpoints of selected ways */
     TreeSet<Node> outerNodes;
@@ -28,8 +26,17 @@
      @param[in] selection a selection of ways
      */
-    public WaySelection(Collection<Way> ways) {
-        this.ways = ways;
-	outerNodes = null;
-	nodes = null;
+    public WaySelection(final Collection<Way> ways) {
+        if (ways.isEmpty()) {
+            // The selection cannot be extended.
+            outerNodes = null;
+            nodes = null;
+        }
+        else {
+            nodes = new TreeSet<Node>();
+            outerNodes = new TreeSet<Node>();
+
+            for (Way way : ways)
+                addNodes(way);
+        }
     }
 
@@ -38,8 +45,8 @@
     private void addNodes(Node node) {
         if (node == null);
-	else if (!nodes.add(node))
-	    outerNodes.remove(node);
-	else
-	    outerNodes.add(node);
+        else if (!nodes.add(node))
+            outerNodes.remove(node);
+        else
+            outerNodes.add(node);
     }
 
@@ -48,5 +55,5 @@
     private void addNodes(Way way) {
         addNodes(way.firstNode());
-	addNodes(way.lastNode());
+        addNodes(way.lastNode());
     }
 
@@ -54,14 +61,5 @@
      @return true if the selection can be extended */
     public boolean canExtend() {
-        if (ways.isEmpty())
-            return false;
-
-        nodes = new TreeSet<Node>();
-        outerNodes = new TreeSet<Node>();
-
-        for (Way way : ways)
-	    addNodes(way);
-
-        return !outerNodes.isEmpty();
+        return outerNodes != null && !outerNodes.isEmpty();
     }
 
@@ -75,10 +73,10 @@
 
         for (Way way : OsmPrimitive.getFilteredList(node.getReferrers(),
-						    Way.class))
-	    if (way.getNodesCount() >= 2 && !selection.contains(way) &&
-		way.isFirstLastNode(node))
+                                                    Way.class))
+            if (way.getNodesCount() >= 2 && !selection.contains(way) &&
+                way.isFirstLastNode(node))
                 foundWays.add(way);
 
-	return foundWays.size() == 1 ? foundWays.first() : null;
+        return foundWays.size() == 1 ? foundWays.first() : null;
     }
 
@@ -86,17 +84,16 @@
      Finds out if the current selection can be extended.
 
-     The members ways, outerNodes, nodes must have been
-     initialized; @see canExtend(). How to update these
-     members when extending the selection, @see extend().
+     The members outerNodes, nodes must have been initialized.
+     How to update these members when extending the selection, @see extend().
      @param selection current selection
      @return a way by which to extend the selection, or null */
     private Way findWay(Collection<OsmPrimitive> selection) {
-	for (Node node : outerNodes) {
-	    Way way = findWay(selection, node);
-	    if (way != null)
-	        return way;
-	}
+        for (Node node : outerNodes) {
+            Way way = findWay(selection, node);
+            if (way != null)
+                return way;
+        }
 
-	return null;
+        return null;
     }
 
@@ -104,36 +101,35 @@
      @param data the data set in which to extend the selection */
     void extend(DataSet data) {
-	Collection<OsmPrimitive> currentSelection;
-	LinkedList<OsmPrimitive> selection;
-	boolean selectionChanged = false;
+        Collection<OsmPrimitive> currentSelection;
+        LinkedList<OsmPrimitive> selection;
+        boolean selectionChanged = false;
         Way way;
 
         if (!canExtend())
-	    return;
+            return;
 
-	currentSelection = data.getSelected();
+        currentSelection = data.getSelected();
 
-	way = findWay(currentSelection);
+        way = findWay(currentSelection);
 
-	if (way == null)
-	    return;
+        if (way == null)
+            return;
 
-	selection = new LinkedList<OsmPrimitive>();
-	for (OsmPrimitive primitive : currentSelection)
-	    selection.add(primitive);
+        selection = new LinkedList<OsmPrimitive>();
+        for (OsmPrimitive primitive : currentSelection)
+            selection.add(primitive);
 
-	do {
-	    if (!selection.add(way))
-	        break;
+        do {
+            if (!selection.add(way))
+                break;
 
-	    selectionChanged = true;
-	    ways.add(way);
-	    addNodes(way);
+            selectionChanged = true;
+            addNodes(way);
 
-	    way = findWay(selection);
-	} while (way != null);
+            way = findWay(selection);
+        } while (way != null);
 
-	if (selectionChanged)
-	    data.setSelected(selection, true);
+        if (selectionChanged)
+            data.setSelected(selection, true);
     }
 }
