Index: /trunk/src/org/openstreetmap/josm/actions/AddNodeAction.java
===================================================================
--- /trunk/src/org/openstreetmap/josm/actions/AddNodeAction.java	(revision 12725)
+++ /trunk/src/org/openstreetmap/josm/actions/AddNodeAction.java	(revision 12726)
@@ -12,4 +12,5 @@
 import org.openstreetmap.josm.command.AddCommand;
 import org.openstreetmap.josm.data.coor.LatLon;
+import org.openstreetmap.josm.data.osm.DataSet;
 import org.openstreetmap.josm.data.osm.Node;
 import org.openstreetmap.josm.data.osm.OsmPrimitive;
@@ -66,6 +67,7 @@
 
         // add the node
-        MainApplication.undoRedo.add(new AddCommand(nnew));
-        getLayerManager().getEditDataSet().setSelected(nnew);
+        DataSet ds = getLayerManager().getEditDataSet();
+        MainApplication.undoRedo.add(new AddCommand(ds, nnew));
+        ds.setSelected(nnew);
         MapView mapView = MainApplication.getMap().mapView;
         if (mapView != null && !mapView.getRealBounds().contains(nnew.getCoor())) {
Index: /trunk/src/org/openstreetmap/josm/actions/CreateCircleAction.java
===================================================================
--- /trunk/src/org/openstreetmap/josm/actions/CreateCircleAction.java	(revision 12725)
+++ /trunk/src/org/openstreetmap/josm/actions/CreateCircleAction.java	(revision 12726)
@@ -25,4 +25,5 @@
 import org.openstreetmap.josm.data.coor.EastNorth;
 import org.openstreetmap.josm.data.coor.LatLon;
+import org.openstreetmap.josm.data.osm.DataSet;
 import org.openstreetmap.josm.data.osm.Node;
 import org.openstreetmap.josm.data.osm.OsmPrimitive;
@@ -137,5 +138,6 @@
         }
 
-        Collection<OsmPrimitive> sel = getLayerManager().getEditDataSet().getSelected();
+        DataSet ds = getLayerManager().getEditDataSet();
+        Collection<OsmPrimitive> sel = ds.getSelected();
         List<Node> nodes = OsmPrimitive.getFilteredList(sel, Node.class);
         List<Way> ways = OsmPrimitive.getFilteredList(sel, Way.class);
@@ -222,5 +224,5 @@
                 Node n = new Node(ll);
                 nodesToAdd.add(n);
-                cmds.add(new AddCommand(n));
+                cmds.add(new AddCommand(ds, n));
             }
         }
@@ -234,9 +236,9 @@
             Way newWay = new Way();
             newWay.setNodes(nodesToAdd);
-            cmds.add(new AddCommand(newWay));
+            cmds.add(new AddCommand(ds, newWay));
         } else {
             Way newWay = new Way(existingWay);
             newWay.setNodes(nodesToAdd);
-            cmds.add(new ChangeCommand(existingWay, newWay));
+            cmds.add(new ChangeCommand(ds, existingWay, newWay));
         }
 
Index: /trunk/src/org/openstreetmap/josm/actions/CreateMultipolygonAction.java
===================================================================
--- /trunk/src/org/openstreetmap/josm/actions/CreateMultipolygonAction.java	(revision 12725)
+++ /trunk/src/org/openstreetmap/josm/actions/CreateMultipolygonAction.java	(revision 12726)
@@ -248,5 +248,5 @@
         final String commandName;
         if (existingRelation == null) {
-            list.add(new AddCommand(relation));
+            list.add(new AddCommand(selectedWays.iterator().next().getDataSet(), relation));
             commandName = getName(false);
         } else {
Index: /trunk/src/org/openstreetmap/josm/actions/FollowLineAction.java
===================================================================
--- /trunk/src/org/openstreetmap/josm/actions/FollowLineAction.java	(revision 12725)
+++ /trunk/src/org/openstreetmap/josm/actions/FollowLineAction.java	(revision 12726)
@@ -15,4 +15,5 @@
 import org.openstreetmap.josm.command.SelectCommand;
 import org.openstreetmap.josm.command.SequenceCommand;
+import org.openstreetmap.josm.data.osm.DataSet;
 import org.openstreetmap.josm.data.osm.Node;
 import org.openstreetmap.josm.data.osm.OsmPrimitive;
@@ -20,5 +21,4 @@
 import org.openstreetmap.josm.gui.MainApplication;
 import org.openstreetmap.josm.gui.MapFrame;
-import org.openstreetmap.josm.gui.layer.OsmDataLayer;
 import org.openstreetmap.josm.tools.Shortcut;
 import org.openstreetmap.josm.tools.Utils;
@@ -61,12 +61,12 @@
     @Override
     public void actionPerformed(ActionEvent evt) {
-        OsmDataLayer osmLayer = getLayerManager().getEditLayer();
-        if (osmLayer == null)
+        DataSet ds = getLayerManager().getEditDataSet();
+        if (ds == null)
             return;
         MapFrame map = MainApplication.getMap();
         if (!(map.mapMode instanceof DrawAction)) return; // We are not on draw mode
 
-        Collection<Node> selectedPoints = osmLayer.data.getSelectedNodes();
-        Collection<Way> selectedLines = osmLayer.data.getSelectedWays();
+        Collection<Node> selectedPoints = ds.getSelectedNodes();
+        Collection<Way> selectedLines = ds.getSelectedWays();
         if ((selectedPoints.size() > 1) || (selectedLines.size() != 1)) // Unsuitable selection
             return;
@@ -115,6 +115,6 @@
             }
             MainApplication.undoRedo.add(new SequenceCommand(tr("Follow line"),
-                    new ChangeCommand(follower, newFollower),
-                    new SelectCommand(newFollower.isClosed() // see #10028 - unselect last node when closing a way
+                    new ChangeCommand(ds, follower, newFollower),
+                    new SelectCommand(ds, newFollower.isClosed() // see #10028 - unselect last node when closing a way
                             ? Arrays.<OsmPrimitive>asList(follower)
                             : Arrays.<OsmPrimitive>asList(follower, newPoint)
Index: /trunk/src/org/openstreetmap/josm/actions/JoinNodeWayAction.java
===================================================================
--- /trunk/src/org/openstreetmap/josm/actions/JoinNodeWayAction.java	(revision 12725)
+++ /trunk/src/org/openstreetmap/josm/actions/JoinNodeWayAction.java	(revision 12726)
@@ -24,4 +24,5 @@
 import org.openstreetmap.josm.command.SequenceCommand;
 import org.openstreetmap.josm.data.coor.EastNorth;
+import org.openstreetmap.josm.data.osm.DataSet;
 import org.openstreetmap.josm.data.osm.Node;
 import org.openstreetmap.josm.data.osm.OsmPrimitive;
@@ -84,11 +85,11 @@
         if (!isEnabled())
             return;
-        Collection<Node> selectedNodes = getLayerManager().getEditDataSet().getSelectedNodes();
+        DataSet ds = getLayerManager().getEditDataSet();
+        Collection<Node> selectedNodes = ds.getSelectedNodes();
         Collection<Command> cmds = new LinkedList<>();
         Map<Way, MultiMap<Integer, Node>> data = new HashMap<>();
 
         // If the user has selected some ways, only join the node to these.
-        boolean restrictToSelectedWays =
-                !getLayerManager().getEditDataSet().getSelectedWays().isEmpty();
+        boolean restrictToSelectedWays = !ds.getSelectedWays().isEmpty();
 
         // Planning phase: decide where we'll insert the nodes and put it all in "data"
@@ -155,5 +156,5 @@
             Way wnew = new Way(w);
             wnew.setNodes(wayNodes);
-            cmds.add(new ChangeCommand(w, wnew));
+            cmds.add(new ChangeCommand(ds, w, wnew));
         }
 
Index: /trunk/src/org/openstreetmap/josm/actions/ReverseWayAction.java
===================================================================
--- /trunk/src/org/openstreetmap/josm/actions/ReverseWayAction.java	(revision 12725)
+++ /trunk/src/org/openstreetmap/josm/actions/ReverseWayAction.java	(revision 12726)
@@ -157,5 +157,5 @@
             corrCmds = (new ReverseWayTagCorrector()).execute(w, wnew);
         }
-        return new ReverseWayResult(wnew, corrCmds, new ChangeCommand(w.getDataSet(), w, wnew));
+        return new ReverseWayResult(wnew, corrCmds, new ChangeCommand(w, wnew));
     }
 
Index: /trunk/src/org/openstreetmap/josm/actions/SplitWayAction.java
===================================================================
--- /trunk/src/org/openstreetmap/josm/actions/SplitWayAction.java	(revision 12725)
+++ /trunk/src/org/openstreetmap/josm/actions/SplitWayAction.java	(revision 12726)
@@ -593,5 +593,5 @@
         final Way changedWay = new Way(way);
         changedWay.setNodes(wayToKeep.getNodes());
-        commandList.add(new ChangeCommand(way.getDataSet(), way, changedWay));
+        commandList.add(new ChangeCommand(way, changedWay));
         if (!isMapModeDraw && !newSelection.contains(way)) {
             newSelection.add(way);
Index: /trunk/src/org/openstreetmap/josm/actions/UnGlueAction.java
===================================================================
--- /trunk/src/org/openstreetmap/josm/actions/UnGlueAction.java	(revision 12725)
+++ /trunk/src/org/openstreetmap/josm/actions/UnGlueAction.java	(revision 12726)
@@ -303,5 +303,5 @@
 
         List<Command> cmds = new LinkedList<>();
-        cmds.add(new AddCommand(n));
+        cmds.add(new AddCommand(selectedNode.getDataSet(), n));
         if (dialog != null) {
             dialog.update(selectedNode, Collections.singletonList(n), cmds);
@@ -440,5 +440,5 @@
         Node newNode = new Node(originalNode, true /* clear OSM ID */);
         newNodes.add(newNode);
-        cmds.add(new AddCommand(newNode));
+        cmds.add(new AddCommand(originalNode.getDataSet(), newNode));
 
         List<Node> nn = new ArrayList<>();
@@ -583,5 +583,5 @@
                 if (seen) {
                     Node newNode = new Node(n, true /* clear OSM ID */);
-                    cmds.add(new AddCommand(newNode));
+                    cmds.add(new AddCommand(selectedNode.getDataSet(), newNode));
                     newNodes.add(newNode);
                     addNodes.add(newNode);
Index: /trunk/src/org/openstreetmap/josm/actions/mapmode/DrawAction.java
===================================================================
--- /trunk/src/org/openstreetmap/josm/actions/mapmode/DrawAction.java	(revision 12725)
+++ /trunk/src/org/openstreetmap/josm/actions/mapmode/DrawAction.java	(revision 12726)
@@ -487,5 +487,5 @@
                 return;
             }
-            cmds.add(new AddCommand(n));
+            cmds.add(new AddCommand(ds, n));
 
             if (!ctrl) {
@@ -576,5 +576,5 @@
                     way = new Way();
                     way.addNode(n0);
-                    cmds.add(new AddCommand(way));
+                    cmds.add(new AddCommand(ds, way));
                     wayToSelect = way;
                 } else {
Index: /trunk/src/org/openstreetmap/josm/actions/mapmode/ExtrudeAction.java
===================================================================
--- /trunk/src/org/openstreetmap/josm/actions/mapmode/ExtrudeAction.java	(revision 12725)
+++ /trunk/src/org/openstreetmap/josm/actions/mapmode/ExtrudeAction.java	(revision 12726)
@@ -40,4 +40,5 @@
 import org.openstreetmap.josm.data.coor.EastNorth;
 import org.openstreetmap.josm.data.osm.DataIntegrityProblemException;
+import org.openstreetmap.josm.data.osm.DataSet;
 import org.openstreetmap.josm.data.osm.Node;
 import org.openstreetmap.josm.data.osm.OsmPrimitive;
@@ -592,7 +593,7 @@
             Way wnew = new Way(ws.way);
             wnew.addNode(ws.lowerIndex+1, n);
-            SequenceCommand cmds = new SequenceCommand(tr("Add a new node to an existing way"),
-                    new AddCommand(n), new ChangeCommand(ws.way, wnew));
-            MainApplication.undoRedo.add(cmds);
+            DataSet ds = ws.way.getDataSet();
+            MainApplication.undoRedo.add(new SequenceCommand(tr("Add a new node to an existing way"),
+                    new AddCommand(ds, n), new ChangeCommand(ds, ws.way, wnew)));
         }
     }
@@ -603,5 +604,6 @@
     private void createNewRectangle() {
         if (selectedSegment == null) return;
-        // crete a new rectangle
+        DataSet ds = getLayerManager().getEditDataSet();
+        // create a new rectangle
         Collection<Command> cmds = new LinkedList<>();
         Node third = new Node(newN2en);
@@ -618,12 +620,12 @@
         wnew.addNode(selectedSegment.getFirstNode());
         // undo support
-        cmds.add(new AddCommand(third));
+        cmds.add(new AddCommand(ds, third));
         if (!dualAlignSegmentCollapsed) {
-            cmds.add(new AddCommand(fourth));
-        }
-        cmds.add(new AddCommand(wnew));
+            cmds.add(new AddCommand(ds, fourth));
+        }
+        cmds.add(new AddCommand(ds, wnew));
         Command c = new SequenceCommand(tr("Extrude Way"), cmds);
         MainApplication.undoRedo.add(c);
-        getLayerManager().getEditDataSet().setSelected(wnew);
+        ds.setSelected(wnew);
     }
 
@@ -634,4 +636,5 @@
      */
     private void performExtrusion() {
+        DataSet ds = getLayerManager().getEditDataSet();
         // create extrusion
         Collection<Command> cmds = new LinkedList<>();
@@ -661,5 +664,5 @@
             wnew.removeNode(n1Old);
             wayWasModified = true;
-            cmds.add(new AddCommand(n1New));
+            cmds.add(new AddCommand(ds, n1New));
             changedNodes.add(n1New);
         } else {
@@ -669,5 +672,5 @@
             wayWasModified = true;
             insertionPoint++;
-            cmds.add(new AddCommand(n1New));
+            cmds.add(new AddCommand(ds, n1New));
             changedNodes.add(n1New);
         }
@@ -691,5 +694,5 @@
             wnew.removeNode(n2Old);
             wayWasModified = true;
-            cmds.add(new AddCommand(n2New));
+            cmds.add(new AddCommand(ds, n2New));
             changedNodes.add(n2New);
         } else {
@@ -698,5 +701,5 @@
             wnew.addNode(insertionPoint, n2New);
             wayWasModified = true;
-            cmds.add(new AddCommand(n2New));
+            cmds.add(new AddCommand(ds, n2New));
             changedNodes.add(n2New);
         }
Index: /trunk/src/org/openstreetmap/josm/actions/mapmode/ImproveWayAccuracyAction.java
===================================================================
--- /trunk/src/org/openstreetmap/josm/actions/mapmode/ImproveWayAccuracyAction.java	(revision 12725)
+++ /trunk/src/org/openstreetmap/josm/actions/mapmode/ImproveWayAccuracyAction.java	(revision 12726)
@@ -399,4 +399,5 @@
         }
 
+        DataSet ds = getLayerManager().getEditDataSet();
         updateKeyModifiers(e);
         mousePos = e.getPoint();
@@ -404,5 +405,5 @@
         if (state == State.SELECTING) {
             if (targetWay != null) {
-                getLayerManager().getEditDataSet().setSelected(targetWay.getPrimitiveId());
+                ds.setSelected(targetWay.getPrimitiveId());
                 updateStateByCurrentSelection();
             }
@@ -425,5 +426,5 @@
                 Node virtualNode = new Node(mv.getEastNorth(mousePos.x,
                         mousePos.y));
-                virtualCmds.add(new AddCommand(virtualNode));
+                virtualCmds.add(new AddCommand(ds, virtualNode));
 
                 // Looking for candidateSegment copies in ways that are
Index: /trunk/src/org/openstreetmap/josm/actions/mapmode/ParallelWays.java
===================================================================
--- /trunk/src/org/openstreetmap/josm/actions/mapmode/ParallelWays.java	(revision 12725)
+++ /trunk/src/org/openstreetmap/josm/actions/mapmode/ParallelWays.java	(revision 12726)
@@ -11,8 +11,10 @@
 import java.util.Set;
 
+import org.openstreetmap.josm.Main;
 import org.openstreetmap.josm.command.AddCommand;
 import org.openstreetmap.josm.command.Command;
 import org.openstreetmap.josm.command.SequenceCommand;
 import org.openstreetmap.josm.data.coor.EastNorth;
+import org.openstreetmap.josm.data.osm.DataSet;
 import org.openstreetmap.josm.data.osm.Node;
 import org.openstreetmap.josm.data.osm.NodeGraph;
@@ -186,10 +188,11 @@
 
     private List<Command> makeAddWayAndNodesCommandList() {
+        DataSet ds = Main.main.getEditDataSet();
         List<Command> commands = new ArrayList<>(sortedNodes.size() + ways.size());
         for (int i = 0; i < sortedNodes.size() - (isClosedPath() ? 1 : 0); i++) {
-            commands.add(new AddCommand(sortedNodes.get(i)));
+            commands.add(new AddCommand(ds, sortedNodes.get(i)));
         }
         for (Way w : ways) {
-            commands.add(new AddCommand(w));
+            commands.add(new AddCommand(ds, w));
         }
         return commands;
Index: /trunk/src/org/openstreetmap/josm/actions/mapmode/SelectAction.java
===================================================================
--- /trunk/src/org/openstreetmap/josm/actions/mapmode/SelectAction.java	(revision 12725)
+++ /trunk/src/org/openstreetmap/josm/actions/mapmode/SelectAction.java	(revision 12726)
@@ -1235,11 +1235,12 @@
 
         private void createMiddleNodeFromVirtual(EastNorth currentEN) {
+            DataSet ds = getLayerManager().getEditDataSet();
             Collection<Command> virtualCmds = new LinkedList<>();
-            virtualCmds.add(new AddCommand(virtualNode));
+            virtualCmds.add(new AddCommand(ds, virtualNode));
             for (WaySegment virtualWay : virtualWays) {
                 Way w = virtualWay.way;
                 Way wnew = new Way(w);
                 wnew.addNode(virtualWay.lowerIndex + 1, virtualNode);
-                virtualCmds.add(new ChangeCommand(w, wnew));
+                virtualCmds.add(new ChangeCommand(ds, w, wnew));
             }
             virtualCmds.add(new MoveCommand(virtualNode, startEN, currentEN));
@@ -1248,5 +1249,5 @@
                     virtualWays.size());
             MainApplication.undoRedo.add(new SequenceCommand(text, virtualCmds));
-            getLayerManager().getEditDataSet().setSelected(Collections.singleton((OsmPrimitive) virtualNode));
+            ds.setSelected(Collections.singleton((OsmPrimitive) virtualNode));
             clear();
         }
Index: /trunk/src/org/openstreetmap/josm/command/AddCommand.java
===================================================================
--- /trunk/src/org/openstreetmap/josm/command/AddCommand.java	(revision 12725)
+++ /trunk/src/org/openstreetmap/josm/command/AddCommand.java	(revision 12726)
@@ -36,5 +36,7 @@
      * Creates the command and specify the element to add in the context of the current edit layer, if any.
      * @param osm The primitive to add
+     * @deprecated to be removed end of 2017. Use {@link #AddCommand(DataSet, OsmPrimitive)} instead
      */
+    @Deprecated
     public AddCommand(OsmPrimitive osm) {
         this.osm = Objects.requireNonNull(osm, "osm");
Index: /trunk/src/org/openstreetmap/josm/command/AddPrimitivesCommand.java
===================================================================
--- /trunk/src/org/openstreetmap/josm/command/AddPrimitivesCommand.java	(revision 12725)
+++ /trunk/src/org/openstreetmap/josm/command/AddPrimitivesCommand.java	(revision 12726)
@@ -39,5 +39,7 @@
      * Constructs a new {@code AddPrimitivesCommand} to add data to the current edit layer.
      * @param data The OSM primitives data to add. Must not be {@code null}
-     */
+     * @deprecated to be removed end of 2017. Use {@link #AddPrimitivesCommand(List, DataSet)} instead
+     */
+    @Deprecated
     public AddPrimitivesCommand(List<PrimitiveData> data) {
         this(data, data);
@@ -49,5 +51,7 @@
      * @param toSelect The OSM primitives to select at the end. Can be {@code null}
      * @since 5953
-     */
+     * @deprecated to be removed end of 2017. Use {@link #AddPrimitivesCommand(List, List, DataSet)} instead
+     */
+    @Deprecated
     public AddPrimitivesCommand(List<PrimitiveData> data, List<PrimitiveData> toSelect) {
         init(data, toSelect);
@@ -77,4 +81,14 @@
         super(ds);
         init(data, toSelect);
+    }
+
+    /**
+     * Constructs a new {@code AddPrimitivesCommand} to add data to the given data set.
+     * @param data The OSM primitives data to add and select. Must not be {@code null}
+     * @param ds The target data set. Must not be {@code null}
+     * @since 12726
+     */
+    public AddPrimitivesCommand(List<PrimitiveData> data, DataSet ds) {
+        this(data, data, ds);
     }
 
Index: /trunk/src/org/openstreetmap/josm/command/ChangeCommand.java
===================================================================
--- /trunk/src/org/openstreetmap/josm/command/ChangeCommand.java	(revision 12725)
+++ /trunk/src/org/openstreetmap/josm/command/ChangeCommand.java	(revision 12726)
@@ -30,12 +30,10 @@
 
     /**
-     * Constructs a new {@code ChangeCommand} in the context of the current edit layer, if any.
-     * @param osm The existing primitive to modify
+     * Constructs a new {@code ChangeCommand} in the context of {@code osm} data set.
+     * @param osm The existing primitive to modify. It must belong to a data set
      * @param newOsm The new primitive
      */
     public ChangeCommand(OsmPrimitive osm, OsmPrimitive newOsm) {
-        this.osm = osm;
-        this.newOsm = newOsm;
-        sanityChecks();
+        this(osm.getDataSet(), osm, newOsm);
     }
 
Index: /trunk/src/org/openstreetmap/josm/command/ChangeNodesCommand.java
===================================================================
--- /trunk/src/org/openstreetmap/josm/command/ChangeNodesCommand.java	(revision 12725)
+++ /trunk/src/org/openstreetmap/josm/command/ChangeNodesCommand.java	(revision 12726)
@@ -10,4 +10,5 @@
 import javax.swing.Icon;
 
+import org.openstreetmap.josm.data.osm.DataSet;
 import org.openstreetmap.josm.data.osm.DefaultNameFormatter;
 import org.openstreetmap.josm.data.osm.Node;
@@ -36,4 +37,16 @@
      */
     public ChangeNodesCommand(Way way, List<Node> newNodes) {
+        this(way.getDataSet(), way, newNodes);
+    }
+
+    /**
+     * Constructs a new {@code ChangeNodesCommand}.
+     * @param ds The target data set. Must not be {@code null}
+     * @param way The way to modify
+     * @param newNodes The new list of nodes for the given way
+     * @since 12726
+     */
+    public ChangeNodesCommand(DataSet ds, Way way, List<Node> newNodes) {
+        super(ds);
         this.way = way;
         this.newNodes = newNodes;
Index: /trunk/src/org/openstreetmap/josm/command/ChangePropertyCommand.java
===================================================================
--- /trunk/src/org/openstreetmap/josm/command/ChangePropertyCommand.java	(revision 12725)
+++ /trunk/src/org/openstreetmap/josm/command/ChangePropertyCommand.java	(revision 12726)
@@ -13,4 +13,5 @@
 import java.util.List;
 import java.util.Map;
+import java.util.NoSuchElementException;
 import java.util.Objects;
 import java.util.stream.Collectors;
@@ -72,8 +73,11 @@
      * Creates a command to change multiple tags of multiple objects
      *
-     * @param objects the objects to modify
+     * @param ds The target data set. Must not be {@code null}
+     * @param objects the objects to modify. Must not be empty
      * @param tags the tags to set
-     */
-    public ChangePropertyCommand(Collection<? extends OsmPrimitive> objects, Map<String, String> tags) {
+     * @since 12726
+     */
+    public ChangePropertyCommand(DataSet ds, Collection<? extends OsmPrimitive> objects, Map<String, String> tags) {
+        super(ds);
         this.tags = tags;
         init(objects);
@@ -81,11 +85,26 @@
 
     /**
+     * Creates a command to change multiple tags of multiple objects
+     *
+     * @param objects the objects to modify. Must not be empty, and objects must belong to a data set
+     * @param tags the tags to set
+     * @throws NullPointerException if objects is null or contain null item
+     * @throws NoSuchElementException if objects is empty
+     */
+    public ChangePropertyCommand(Collection<? extends OsmPrimitive> objects, Map<String, String> tags) {
+        this(objects.iterator().next().getDataSet(), objects, tags);
+    }
+
+    /**
      * Creates a command to change one tag of multiple objects
      *
-     * @param objects the objects to modify
+     * @param objects the objects to modify. Must not be empty, and objects must belong to a data set
      * @param key the key of the tag to set
      * @param value the value of the key to set
+     * @throws NullPointerException if objects is null or contain null item
+     * @throws NoSuchElementException if objects is empty
      */
     public ChangePropertyCommand(Collection<? extends OsmPrimitive> objects, String key, String value) {
+        super(objects.iterator().next().getDataSet());
         this.tags = new HashMap<>(1);
         this.tags.put(key, value);
@@ -96,7 +115,8 @@
      * Creates a command to change one tag of one object
      *
-     * @param object the object to modify
+     * @param object the object to modify. Must belong to a data set
      * @param key the key of the tag to set
      * @param value the value of the key to set
+     * @throws NullPointerException if object is null
      */
     public ChangePropertyCommand(OsmPrimitive object, String key, String value) {
@@ -134,6 +154,4 @@
     @Override
     public boolean executeCommand() {
-        if (objects.isEmpty())
-            return true;
         final DataSet dataSet = objects.get(0).getDataSet();
         if (dataSet != null) {
Index: /trunk/src/org/openstreetmap/josm/command/ChangePropertyKeyCommand.java
===================================================================
--- /trunk/src/org/openstreetmap/josm/command/ChangePropertyKeyCommand.java	(revision 12725)
+++ /trunk/src/org/openstreetmap/josm/command/ChangePropertyKeyCommand.java	(revision 12726)
@@ -10,8 +10,10 @@
 import java.util.LinkedList;
 import java.util.List;
+import java.util.NoSuchElementException;
 import java.util.Objects;
 
 import javax.swing.Icon;
 
+import org.openstreetmap.josm.data.osm.DataSet;
 import org.openstreetmap.josm.data.osm.OsmPrimitive;
 import org.openstreetmap.josm.data.validation.util.NameVisitor;
@@ -66,5 +68,5 @@
      * Constructs a new {@code ChangePropertyKeyCommand}.
      *
-     * @param object the object subject to change replacement
+     * @param object the object subject to change replacement. Must not be null, and belong to a data set
      * @param key The key to replace
      * @param newKey the new value of the key
@@ -78,9 +80,25 @@
      * Constructs a new {@code ChangePropertyKeyCommand}.
      *
-     * @param objects all objects subject to change replacement
+     * @param objects all objects subject to change replacement. Must not be null or empty, and objects must belong to a data set
      * @param key The key to replace
      * @param newKey the new value of the key
+     * @throws NullPointerException if objects is null or contain null item
+     * @throws NoSuchElementException if objects is empty
      */
     public ChangePropertyKeyCommand(Collection<? extends OsmPrimitive> objects, String key, String newKey) {
+        this(objects.iterator().next().getDataSet(), objects, key, newKey);
+    }
+
+    /**
+     * Constructs a new {@code ChangePropertyKeyCommand}.
+     *
+     * @param ds The target data set. Must not be {@code null}
+     * @param objects all objects subject to change replacement.
+     * @param key The key to replace
+     * @param newKey the new value of the key
+     * @since 12726
+     */
+    public ChangePropertyKeyCommand(DataSet ds, Collection<? extends OsmPrimitive> objects, String key, String newKey) {
+        super(ds);
         this.objects = new LinkedList<>(objects);
         this.key = key;
Index: /trunk/src/org/openstreetmap/josm/command/ChangeRelationMemberRoleCommand.java
===================================================================
--- /trunk/src/org/openstreetmap/josm/command/ChangeRelationMemberRoleCommand.java	(revision 12725)
+++ /trunk/src/org/openstreetmap/josm/command/ChangeRelationMemberRoleCommand.java	(revision 12726)
@@ -37,17 +37,15 @@
     /**
      * Constructs a new {@code ChangeRelationMemberRoleCommand}.
-     * @param relation The relation to be changed
+     * @param relation The relation to be changed. Must not be null, and belong to a data set
      * @param position Member position
      * @param newRole New role
      */
     public ChangeRelationMemberRoleCommand(Relation relation, int position, String newRole) {
-        this.relation = relation;
-        this.position = position;
-        this.newRole = newRole;
+        this(relation.getDataSet(), relation, position, newRole);
     }
 
     /**
      * Constructs a new {@code ChangeRelationMemberRoleCommand}.
-     * @param dataSet The data set the role is in
+     * @param dataSet The data set the role is in. Must not be {@code null}
      * @param relation The relation to be changed
      * @param position Member position
Index: /trunk/src/org/openstreetmap/josm/command/Command.java
===================================================================
--- /trunk/src/org/openstreetmap/josm/command/Command.java	(revision 12725)
+++ /trunk/src/org/openstreetmap/josm/command/Command.java	(revision 12726)
@@ -147,5 +147,7 @@
     /**
      * Creates a new command in the context of the current edit layer, if any
-     */
+     * @deprecated to be removed end of 2017. Use {@link #Command(DataSet)} instead
+     */
+    @Deprecated
     public Command() {
         this.layer = MainApplication.getLayerManager().getEditLayer();
Index: /trunk/src/org/openstreetmap/josm/command/DeleteCommand.java
===================================================================
--- /trunk/src/org/openstreetmap/josm/command/DeleteCommand.java	(revision 12725)
+++ /trunk/src/org/openstreetmap/josm/command/DeleteCommand.java	(revision 12726)
@@ -75,5 +75,5 @@
         @Override
         public String toString() {
-            return "DeleteChildCommand [osm=" + osm + "]";
+            return "DeleteChildCommand [osm=" + osm + ']';
         }
     }
@@ -88,11 +88,9 @@
      * Constructor. Deletes a collection of primitives in the current edit layer.
      *
-     * @param data the primitives to delete. Must neither be null nor empty.
+     * @param data the primitives to delete. Must neither be null nor empty, and belong to a data set
      * @throws IllegalArgumentException if data is null or empty
      */
     public DeleteCommand(Collection<? extends OsmPrimitive> data) {
-        CheckParameterUtil.ensureParameterNotNull(data, "data");
-        this.toDelete = data;
-        checkConsistency();
+        this(data.iterator().next().getDataSet(), data);
     }
 
Index: /trunk/src/org/openstreetmap/josm/command/MoveCommand.java
===================================================================
--- /trunk/src/org/openstreetmap/josm/command/MoveCommand.java	(revision 12725)
+++ /trunk/src/org/openstreetmap/josm/command/MoveCommand.java	(revision 12726)
@@ -9,4 +9,5 @@
 import java.util.LinkedList;
 import java.util.List;
+import java.util.NoSuchElementException;
 import java.util.Objects;
 
@@ -84,9 +85,12 @@
     /**
      * Constructs a new {@code MoveCommand} and assign the initial object set and movement vector.
-     * @param objects The primitives to move
+     * @param objects The primitives to move. Must neither be null nor empty. Objects must belong to a data set
      * @param x X difference movement. Coordinates are in northern/eastern
      * @param y Y difference movement. Coordinates are in northern/eastern
+     * @throws NullPointerException if objects is null or contain null item
+     * @throws NoSuchElementException if objects is empty
      */
     public MoveCommand(Collection<OsmPrimitive> objects, double x, double y) {
+        super(objects.iterator().next().getDataSet());
         startEN = null;
         saveCheckpoint(); // (0,0) displacement will be saved
Index: /trunk/src/org/openstreetmap/josm/command/RemoveNodesCommand.java
===================================================================
--- /trunk/src/org/openstreetmap/josm/command/RemoveNodesCommand.java	(revision 12725)
+++ /trunk/src/org/openstreetmap/josm/command/RemoveNodesCommand.java	(revision 12726)
@@ -33,8 +33,9 @@
     /**
      * Constructs a new {@code RemoveNodesCommand}.
-     * @param way The way to modify
+     * @param way The way to modify. Must not be null, and belong to a data set
      * @param rmNodes The list of nodes to remove
      */
     public RemoveNodesCommand(Way way, List<Node> rmNodes) {
+        super(way.getDataSet());
         this.way = way;
         this.rmNodes = new HashSet<>(rmNodes);
Index: /trunk/src/org/openstreetmap/josm/command/SelectCommand.java
===================================================================
--- /trunk/src/org/openstreetmap/josm/command/SelectCommand.java	(revision 12725)
+++ /trunk/src/org/openstreetmap/josm/command/SelectCommand.java	(revision 12726)
@@ -28,5 +28,7 @@
      * Constructs a new select command.
      * @param newSelection the primitives to select when executing the command.
+     * @deprecated to be removed end of 2017. Use {@link #SelectCommand(DataSet, Collection)} instead
      */
+    @Deprecated
     public SelectCommand(Collection<OsmPrimitive> newSelection) {
         if (newSelection == null || newSelection.isEmpty()) {
Index: /trunk/src/org/openstreetmap/josm/command/SequenceCommand.java
===================================================================
--- /trunk/src/org/openstreetmap/josm/command/SequenceCommand.java	(revision 12725)
+++ /trunk/src/org/openstreetmap/josm/command/SequenceCommand.java	(revision 12726)
@@ -11,4 +11,5 @@
 import javax.swing.Icon;
 
+import org.openstreetmap.josm.data.osm.DataSet;
 import org.openstreetmap.josm.data.osm.OsmPrimitive;
 import org.openstreetmap.josm.gui.layer.Layer;
@@ -33,4 +34,19 @@
     /**
      * Create the command by specifying the list of commands to execute.
+     * @param ds The target data set. Must not be {@code null}
+     * @param name The description text
+     * @param sequenz The sequence that should be executed
+     * @param continueOnError Determines if the sequence execution should continue after one of its commands fails
+     * @since 12726
+     */
+    public SequenceCommand(DataSet ds, String name, Collection<Command> sequenz, boolean continueOnError) {
+        super(ds);
+        this.name = name;
+        this.sequence = sequenz.toArray(new Command[sequenz.size()]);
+        this.continueOnError = continueOnError;
+    }
+
+    /**
+     * Create the command by specifying the list of commands to execute.
      * @param name The description text
      * @param sequenz The sequence that should be executed. Must not be null or empty
@@ -39,8 +55,5 @@
      */
     public SequenceCommand(String name, Collection<Command> sequenz, boolean continueOnError) {
-        super(sequenz.iterator().next().getAffectedDataSet());
-        this.name = name;
-        this.sequence = sequenz.toArray(new Command[sequenz.size()]);
-        this.continueOnError = continueOnError;
+        this(sequenz.iterator().next().getAffectedDataSet(), name, sequenz, continueOnError);
     }
 
Index: /trunk/src/org/openstreetmap/josm/command/TransformNodesCommand.java
===================================================================
--- /trunk/src/org/openstreetmap/josm/command/TransformNodesCommand.java	(revision 12725)
+++ /trunk/src/org/openstreetmap/josm/command/TransformNodesCommand.java	(revision 12726)
@@ -6,6 +6,6 @@
 import java.util.Collection;
 import java.util.HashMap;
-import java.util.LinkedList;
 import java.util.Map;
+import java.util.NoSuchElementException;
 import java.util.Objects;
 
@@ -28,10 +28,10 @@
      * The nodes to transform.
      */
-    protected Collection<Node> nodes = new LinkedList<>();
+    protected final Collection<Node> nodes;
 
     /**
      * List of all old states of the nodes.
      */
-    protected Map<Node, OldNodeState> oldStates = new HashMap<>();
+    protected final Map<Node, OldNodeState> oldStates = new HashMap<>();
 
     /**
@@ -47,7 +47,10 @@
      * Creates a TransformNodesObject.
      * Find out the impacted nodes and store their initial state.
-     * @param objects objects to fetch nodes from
+     * @param objects objects to fetch nodes from. Must neither be null nor empty. Items must belong to a data set
+     * @throws NullPointerException if objects is null or contain null item
+     * @throws NoSuchElementException if objects is empty
      */
     public TransformNodesCommand(Collection<? extends OsmPrimitive> objects) {
+        super(objects.iterator().next().getDataSet());
         this.nodes = AllNodesVisitor.getAllNodes(objects);
         storeOldState();
Index: /trunk/src/org/openstreetmap/josm/command/conflict/ConflictAddCommand.java
===================================================================
--- /trunk/src/org/openstreetmap/josm/command/conflict/ConflictAddCommand.java	(revision 12725)
+++ /trunk/src/org/openstreetmap/josm/command/conflict/ConflictAddCommand.java	(revision 12726)
@@ -79,5 +79,5 @@
     public void undoCommand() {
         DataSet ds = getAffectedDataSet();
-        if (!Main.main.containsDataSet(ds)) {
+        if (Main.main != null && !Main.main.containsDataSet(ds)) {
             Logging.warn(tr("Layer ''{0}'' does not exist any more. Cannot remove conflict for object ''{1}''.",
                     ds.getName(),
Index: /trunk/src/org/openstreetmap/josm/command/conflict/ConflictResolveCommand.java
===================================================================
--- /trunk/src/org/openstreetmap/josm/command/conflict/ConflictResolveCommand.java	(revision 12725)
+++ /trunk/src/org/openstreetmap/josm/command/conflict/ConflictResolveCommand.java	(revision 12726)
@@ -28,7 +28,9 @@
     /**
      * Constructs a new {@code ConflictResolveCommand} in the context of the current edit layer, if any.
+     * @deprecated to be removed end of 2017. Use {@link #ConflictResolveCommand(DataSet)} instead
      */
+    @Deprecated
     public ConflictResolveCommand() {
-        // Do nothing
+        this(Main.main.getEditDataSet());
     }
 
@@ -81,13 +83,15 @@
 
         DataSet ds = getAffectedDataSet();
-        if (!Main.main.containsDataSet(ds)) {
-            Logging.warn(tr("Cannot undo command ''{0}'' because layer ''{1}'' is not present any more",
-                    this.toString(),
-                    ds.getName()
-            ));
-            return;
+        if (Main.main != null) {
+            if (!Main.main.containsDataSet(ds)) {
+                Logging.warn(tr("Cannot undo command ''{0}'' because layer ''{1}'' is not present any more",
+                        this.toString(),
+                        ds.getName()
+                ));
+                return;
+            }
+
+            Main.main.setEditDataSet(ds);
         }
-
-        Main.main.setEditDataSet(ds);
         reconstituteConflicts();
     }
Index: /trunk/src/org/openstreetmap/josm/command/conflict/CoordinateConflictResolveCommand.java
===================================================================
--- /trunk/src/org/openstreetmap/josm/command/conflict/CoordinateConflictResolveCommand.java	(revision 12725)
+++ /trunk/src/org/openstreetmap/josm/command/conflict/CoordinateConflictResolveCommand.java	(revision 12726)
@@ -34,4 +34,5 @@
      */
     public CoordinateConflictResolveCommand(Conflict<? extends OsmPrimitive> conflict, MergeDecisionType decision) {
+        super(conflict.getMy().getDataSet());
         this.conflict = conflict;
         this.decision = decision;
Index: /trunk/src/org/openstreetmap/josm/command/conflict/DeletedStateConflictResolveCommand.java
===================================================================
--- /trunk/src/org/openstreetmap/josm/command/conflict/DeletedStateConflictResolveCommand.java	(revision 12725)
+++ /trunk/src/org/openstreetmap/josm/command/conflict/DeletedStateConflictResolveCommand.java	(revision 12726)
@@ -34,4 +34,5 @@
      */
     public DeletedStateConflictResolveCommand(Conflict<? extends OsmPrimitive> conflict, MergeDecisionType decision) {
+        super(conflict.getMy().getDataSet());
         this.conflict = conflict;
         this.decision = decision;
Index: /trunk/src/org/openstreetmap/josm/command/conflict/ModifiedConflictResolveCommand.java
===================================================================
--- /trunk/src/org/openstreetmap/josm/command/conflict/ModifiedConflictResolveCommand.java	(revision 12725)
+++ /trunk/src/org/openstreetmap/josm/command/conflict/ModifiedConflictResolveCommand.java	(revision 12726)
@@ -29,4 +29,5 @@
      */
     public ModifiedConflictResolveCommand(Conflict<? extends OsmPrimitive> conflict) {
+        super(conflict.getMy().getDataSet());
         this.conflict = conflict;
     }
Index: /trunk/src/org/openstreetmap/josm/command/conflict/RelationMemberConflictResolverCommand.java
===================================================================
--- /trunk/src/org/openstreetmap/josm/command/conflict/RelationMemberConflictResolverCommand.java	(revision 12725)
+++ /trunk/src/org/openstreetmap/josm/command/conflict/RelationMemberConflictResolverCommand.java	(revision 12726)
@@ -36,4 +36,5 @@
     @SuppressWarnings("unchecked")
     public RelationMemberConflictResolverCommand(Conflict<? extends OsmPrimitive> conflict, List<RelationMember> mergedMembers) {
+        super(conflict.getMy().getDataSet());
         this.conflict = (Conflict<Relation>) conflict;
         this.mergedMembers = mergedMembers;
Index: /trunk/src/org/openstreetmap/josm/command/conflict/TagConflictResolveCommand.java
===================================================================
--- /trunk/src/org/openstreetmap/josm/command/conflict/TagConflictResolveCommand.java	(revision 12725)
+++ /trunk/src/org/openstreetmap/josm/command/conflict/TagConflictResolveCommand.java	(revision 12726)
@@ -50,4 +50,5 @@
      */
     public TagConflictResolveCommand(Conflict<? extends OsmPrimitive> conflict, List<TagMergeItem> mergeItems) {
+        super(conflict.getMy().getDataSet());
         this.conflict = conflict;
         this.mergeItems = mergeItems;
Index: /trunk/src/org/openstreetmap/josm/command/conflict/VersionConflictResolveCommand.java
===================================================================
--- /trunk/src/org/openstreetmap/josm/command/conflict/VersionConflictResolveCommand.java	(revision 12725)
+++ /trunk/src/org/openstreetmap/josm/command/conflict/VersionConflictResolveCommand.java	(revision 12726)
@@ -29,4 +29,5 @@
      */
     public VersionConflictResolveCommand(Conflict<? extends OsmPrimitive> conflict) {
+        super(conflict.getMy().getDataSet());
         this.conflict = conflict;
     }
Index: /trunk/src/org/openstreetmap/josm/command/conflict/WayNodesConflictResolverCommand.java
===================================================================
--- /trunk/src/org/openstreetmap/josm/command/conflict/WayNodesConflictResolverCommand.java	(revision 12725)
+++ /trunk/src/org/openstreetmap/josm/command/conflict/WayNodesConflictResolverCommand.java	(revision 12726)
@@ -36,4 +36,5 @@
     @SuppressWarnings("unchecked")
     public WayNodesConflictResolverCommand(Conflict<? extends OsmPrimitive> conflict, List<Node> mergedNodeList) {
+        super(conflict.getMy().getDataSet());
         this.conflict = (Conflict<Way>) conflict;
         this.mergedNodeList = mergedNodeList;
Index: /trunk/src/org/openstreetmap/josm/data/osm/DataSet.java
===================================================================
--- /trunk/src/org/openstreetmap/josm/data/osm/DataSet.java	(revision 12725)
+++ /trunk/src/org/openstreetmap/josm/data/osm/DataSet.java	(revision 12726)
@@ -263,4 +263,21 @@
 
     /**
+     * Constructs a new {@code DataSet} initially filled with the given primitives.
+     * @param osmPrimitives primitives to add to this data set
+     * @since 12726
+     */
+    public DataSet(OsmPrimitive... osmPrimitives) {
+        this();
+        beginUpdate();
+        try {
+            for (OsmPrimitive o : osmPrimitives) {
+                addPrimitive(o);
+            }
+        } finally {
+            endUpdate();
+        }
+    }
+
+    /**
      * Adds a new data source.
      * @param source data source to add
Index: /trunk/src/org/openstreetmap/josm/data/osm/Node.java
===================================================================
--- /trunk/src/org/openstreetmap/josm/data/osm/Node.java	(revision 12725)
+++ /trunk/src/org/openstreetmap/josm/data/osm/Node.java	(revision 12726)
@@ -106,4 +106,5 @@
      * @return the east north coordinates or {@code null} if #is
      */
+    @Override
     public EastNorth getEastNorth() {
         return getEastNorth(Main.getProjection());
Index: /trunk/src/org/openstreetmap/josm/data/validation/tests/UnconnectedWays.java
===================================================================
--- /trunk/src/org/openstreetmap/josm/data/validation/tests/UnconnectedWays.java	(revision 12725)
+++ /trunk/src/org/openstreetmap/josm/data/validation/tests/UnconnectedWays.java	(revision 12726)
@@ -168,5 +168,5 @@
         mindist = Main.pref.getDouble(PREFIX + ".node_way_distance", 10.0);
         minmiddledist = Main.pref.getDouble(PREFIX + ".way_way_distance", 0.0);
-        DataSet dataSet = Main.main.getEditDataSet();
+        DataSet dataSet = Main.main != null ? Main.main.getEditDataSet() : null;
         dsArea = dataSet == null ? null : dataSet.getDataSourceArea();
     }
Index: /trunk/src/org/openstreetmap/josm/gui/MainApplication.java
===================================================================
--- /trunk/src/org/openstreetmap/josm/gui/MainApplication.java	(revision 12725)
+++ /trunk/src/org/openstreetmap/josm/gui/MainApplication.java	(revision 12726)
@@ -197,4 +197,24 @@
     public static UndoRedoHandler undoRedo;
 
+    private static final LayerChangeListener undoRedoCleaner = new LayerChangeListener() {
+        @Override
+        public void layerRemoving(LayerRemoveEvent e) {
+            Layer layer = e.getRemovedLayer();
+            if (layer instanceof OsmDataLayer) {
+                undoRedo.clean(((OsmDataLayer) layer).data);
+            }
+        }
+
+        @Override
+        public void layerOrderChanged(LayerOrderChangeEvent e) {
+            // Do nothing
+        }
+
+        @Override
+        public void layerAdded(LayerAddEvent e) {
+            // Do nothing
+        }
+    };
+
     /**
      * Listener that sets the enabled state of undo/redo menu entries.
@@ -220,23 +240,5 @@
         this.mainFrame = mainFrame;
         undoRedo = super.undoRedo;
-        getLayerManager().addLayerChangeListener(new LayerChangeListener() {
-            @Override
-            public void layerRemoving(LayerRemoveEvent e) {
-                Layer layer = e.getRemovedLayer();
-                if (layer instanceof OsmDataLayer) {
-                    undoRedo.clean(((OsmDataLayer) layer).data);
-                }
-            }
-
-            @Override
-            public void layerOrderChanged(LayerOrderChangeEvent e) {
-                // Do nothing
-            }
-
-            @Override
-            public void layerAdded(LayerAddEvent e) {
-                // Do nothing
-            }
-        });
+        getLayerManager().addLayerChangeListener(undoRedoCleaner);
     }
 
Index: /trunk/src/org/openstreetmap/josm/gui/dialogs/properties/PropertiesDialog.java
===================================================================
--- /trunk/src/org/openstreetmap/josm/gui/dialogs/properties/PropertiesDialog.java	(revision 12725)
+++ /trunk/src/org/openstreetmap/josm/gui/dialogs/properties/PropertiesDialog.java	(revision 12726)
@@ -77,7 +77,7 @@
 import org.openstreetmap.josm.data.osm.event.DatasetEventManager;
 import org.openstreetmap.josm.data.osm.event.DatasetEventManager.FireMode;
+import org.openstreetmap.josm.data.osm.event.SelectionEventManager;
 import org.openstreetmap.josm.data.osm.search.SearchCompiler;
 import org.openstreetmap.josm.data.osm.search.SearchSetting;
-import org.openstreetmap.josm.data.osm.event.SelectionEventManager;
 import org.openstreetmap.josm.data.preferences.StringProperty;
 import org.openstreetmap.josm.gui.ConditionalOptionPaneUtil;
Index: /trunk/src/org/openstreetmap/josm/gui/dialogs/relation/actions/SavingAction.java
===================================================================
--- /trunk/src/org/openstreetmap/josm/gui/dialogs/relation/actions/SavingAction.java	(revision 12725)
+++ /trunk/src/org/openstreetmap/josm/gui/dialogs/relation/actions/SavingAction.java	(revision 12726)
@@ -103,9 +103,10 @@
      */
     protected void applyExistingNonConflictingRelation(TagEditorModel tagEditorModel) {
-        Relation editedRelation = new Relation(editor.getRelation());
+        Relation originRelation = editor.getRelation();
+        Relation editedRelation = new Relation(originRelation);
         tagEditorModel.applyToPrimitive(editedRelation);
         memberTableModel.applyToRelation(editedRelation);
-        if (!editedRelation.hasEqualSemanticAttributes(editor.getRelation(), false)) {
-            MainApplication.undoRedo.add(new ChangeCommand(editor.getRelation(), editedRelation));
+        if (!editedRelation.hasEqualSemanticAttributes(originRelation, false)) {
+            MainApplication.undoRedo.add(new ChangeCommand(originRelation, editedRelation));
         }
     }
Index: /trunk/src/org/openstreetmap/josm/gui/io/TagSettingsPanel.java
===================================================================
--- /trunk/src/org/openstreetmap/josm/gui/io/TagSettingsPanel.java	(revision 12725)
+++ /trunk/src/org/openstreetmap/josm/gui/io/TagSettingsPanel.java	(revision 12726)
@@ -158,5 +158,5 @@
     class ChangesetReviewChangeListener implements ChangeListener {
 
-        private final String key = "review_requested";
+        private static final String KEY = "review_requested";
 
         @Override
@@ -164,7 +164,7 @@
             if (e.getSource() instanceof ChangesetReviewModel) {
                 boolean newState = ((ChangesetReviewModel) e.getSource()).isReviewRequested();
-                boolean oldState = "yes".equals(Optional.ofNullable(getTagEditorValue(key)).orElse(""));
+                boolean oldState = "yes".equals(Optional.ofNullable(getTagEditorValue(KEY)).orElse(""));
                 if (oldState != newState) {
-                    setProperty(key, newState ? "yes" : null);
+                    setProperty(KEY, newState ? "yes" : null);
                 }
             }
Index: /trunk/src/org/openstreetmap/josm/io/remotecontrol/handler/AddNodeHandler.java
===================================================================
--- /trunk/src/org/openstreetmap/josm/io/remotecontrol/handler/AddNodeHandler.java	(revision 12725)
+++ /trunk/src/org/openstreetmap/josm/io/remotecontrol/handler/AddNodeHandler.java	(revision 12726)
@@ -12,4 +12,5 @@
 import org.openstreetmap.josm.command.AddCommand;
 import org.openstreetmap.josm.data.coor.LatLon;
+import org.openstreetmap.josm.data.osm.DataSet;
 import org.openstreetmap.josm.data.osm.Node;
 import org.openstreetmap.josm.data.osm.OsmPrimitive;
@@ -96,11 +97,12 @@
         }
 
+        DataSet ds = MainApplication.getLayerManager().getEditDataSet();
         if (node == null) {
             node = new Node(ll);
             // Now execute the commands to add this node.
-            MainApplication.undoRedo.add(new AddCommand(node));
+            MainApplication.undoRedo.add(new AddCommand(ds, node));
         }
 
-        MainApplication.getLayerManager().getEditDataSet().setSelected(node);
+        ds.setSelected(node);
         if (PermissionPrefWithDefault.CHANGE_VIEWPORT.isAllowed()) {
             AutoScaleAction.autoScale("selection");
Index: /trunk/src/org/openstreetmap/josm/io/remotecontrol/handler/AddWayHandler.java
===================================================================
--- /trunk/src/org/openstreetmap/josm/io/remotecontrol/handler/AddWayHandler.java	(revision 12725)
+++ /trunk/src/org/openstreetmap/josm/io/remotecontrol/handler/AddWayHandler.java	(revision 12726)
@@ -19,4 +19,5 @@
 import org.openstreetmap.josm.command.SequenceCommand;
 import org.openstreetmap.josm.data.coor.LatLon;
+import org.openstreetmap.josm.data.osm.DataSet;
 import org.openstreetmap.josm.data.osm.Node;
 import org.openstreetmap.josm.data.osm.OsmPrimitive;
@@ -148,5 +149,5 @@
             nd = new Node(ll);
             // Now execute the commands to add this node.
-            commands.add(new AddCommand(nd));
+            commands.add(new AddCommand(Main.main.getEditDataSet(), nd));
             addedNodes.put(ll, nd);
         }
@@ -166,7 +167,8 @@
         }
         allCoordinates.clear();
-        commands.add(new AddCommand(way));
+        DataSet ds = MainApplication.getLayerManager().getEditDataSet();
+        commands.add(new AddCommand(ds, way));
         MainApplication.undoRedo.add(new SequenceCommand(tr("Add way"), commands));
-        MainApplication.getLayerManager().getEditDataSet().setSelected(way);
+        ds.setSelected(way);
         if (PermissionPrefWithDefault.CHANGE_VIEWPORT.isAllowed()) {
             AutoScaleAction.autoScale("selection");
Index: /trunk/src/org/openstreetmap/josm/tools/Geometry.java
===================================================================
--- /trunk/src/org/openstreetmap/josm/tools/Geometry.java	(revision 12725)
+++ /trunk/src/org/openstreetmap/josm/tools/Geometry.java	(revision 12726)
@@ -228,5 +228,5 @@
             newWay.setNodes(newNodes[pos]);
 
-            cmds.add(new ChangeCommand(way, newWay));
+            cmds.add(new ChangeCommand(dataset, way, newWay));
         }
 
Index: /trunk/test/unit/org/openstreetmap/josm/TestUtils.java
===================================================================
--- /trunk/test/unit/org/openstreetmap/josm/TestUtils.java	(revision 12725)
+++ /trunk/test/unit/org/openstreetmap/josm/TestUtils.java	(revision 12726)
@@ -22,4 +22,5 @@
 
 import org.openstreetmap.josm.command.Command;
+import org.openstreetmap.josm.data.osm.DataSet;
 import org.openstreetmap.josm.data.osm.Node;
 import org.openstreetmap.josm.data.osm.OsmPrimitive;
@@ -257,8 +258,9 @@
     /**
      * Creates a new empty command.
+     * @param ds data set
      * @return a new empty command
      */
-    public static Command newCommand() {
-        return new Command() {
+    public static Command newCommand(DataSet ds) {
+        return new Command(ds) {
             @Override
             public String getDescriptionText() {
Index: /trunk/test/unit/org/openstreetmap/josm/actions/CreateMultipolygonActionTest.java
===================================================================
--- /trunk/test/unit/org/openstreetmap/josm/actions/CreateMultipolygonActionTest.java	(revision 12725)
+++ /trunk/test/unit/org/openstreetmap/josm/actions/CreateMultipolygonActionTest.java	(revision 12726)
@@ -17,7 +17,7 @@
 import org.openstreetmap.josm.data.osm.RelationMember;
 import org.openstreetmap.josm.data.osm.Way;
+import org.openstreetmap.josm.data.osm.search.SearchCompiler;
 import org.openstreetmap.josm.data.osm.search.SearchParseError;
 import org.openstreetmap.josm.data.osm.search.SearchSetting;
-import org.openstreetmap.josm.data.osm.search.SearchCompiler;
 import org.openstreetmap.josm.io.OsmReader;
 import org.openstreetmap.josm.testutils.JOSMTestRules;
@@ -42,5 +42,8 @@
         Map<String, String> refToRole = new TreeMap<>();
         for (RelationMember i : relation.getMembers()) {
-            refToRole.put(i.getMember().get("ref"), i.getRole());
+            String ref = i.getMember().get("ref");
+            if (ref != null) {
+                refToRole.put(ref, i.getRole());
+            }
         }
         return refToRole;
Index: /trunk/test/unit/org/openstreetmap/josm/actions/SplitWayActionTest.java
===================================================================
--- /trunk/test/unit/org/openstreetmap/josm/actions/SplitWayActionTest.java	(revision 12725)
+++ /trunk/test/unit/org/openstreetmap/josm/actions/SplitWayActionTest.java	(revision 12726)
@@ -162,5 +162,4 @@
     void doTestRouteRelation(final boolean wayIsReversed, final int indexOfWayToKeep) {
         final DataSet dataSet = new DataSet();
-        final OsmDataLayer layer = new OsmDataLayer(dataSet, OsmDataLayer.createNewName(), null);
         final Node n1 = new Node(new LatLon(1, 0));
         final Node n2 = new Node(new LatLon(2, 0));
@@ -197,5 +196,5 @@
             };
         final SplitWayAction.SplitWayResult result = SplitWayAction.splitWay(
-                layer, w2, SplitWayAction.buildSplitChunks(w2, Arrays.asList(n3, n4, n5)), new ArrayList<OsmPrimitive>(), strategy);
+                w2, SplitWayAction.buildSplitChunks(w2, Arrays.asList(n3, n4, n5)), new ArrayList<OsmPrimitive>(), strategy);
         MainApplication.undoRedo.add(result.getCommand());
 
Index: /trunk/test/unit/org/openstreetmap/josm/command/AddCommandTest.java
===================================================================
--- /trunk/test/unit/org/openstreetmap/josm/command/AddCommandTest.java	(revision 12725)
+++ /trunk/test/unit/org/openstreetmap/josm/command/AddCommandTest.java	(revision 12726)
@@ -16,5 +16,4 @@
 import org.openstreetmap.josm.data.osm.User;
 import org.openstreetmap.josm.data.osm.Way;
-import org.openstreetmap.josm.gui.MainApplication;
 import org.openstreetmap.josm.gui.layer.OsmDataLayer;
 import org.openstreetmap.josm.testutils.JOSMTestRules;
@@ -41,32 +40,28 @@
     @Test
     public void testAdd() {
-        OsmDataLayer layer1 = new OsmDataLayer(new DataSet(), "l1", null);
-        MainApplication.getLayerManager().addLayer(layer1);
-        assertArrayEquals(new Object[0], layer1.data.allPrimitives().toArray());
+        DataSet ds = new DataSet();
+        assertArrayEquals(new Object[0], ds.allPrimitives().toArray());
 
         Node osm = new Node(LatLon.ZERO);
-        assertTrue(new AddCommand(osm).executeCommand());
+        assertTrue(new AddCommand(ds, osm).executeCommand());
 
-        assertArrayEquals(new Object[] {osm}, layer1.data.allPrimitives().toArray());
-        assertArrayEquals(new Object[] {osm}, layer1.data.allModifiedPrimitives().toArray());
+        assertArrayEquals(new Object[] {osm}, ds.allPrimitives().toArray());
+        assertArrayEquals(new Object[] {osm}, ds.allModifiedPrimitives().toArray());
         assertTrue(osm.isModified());
     }
 
     /**
-     * Tests if the add command respects the layer.
+     * Tests if the add command respects the data set.
      */
     @Test
     public void testAddToLayer() {
-        OsmDataLayer layer1 = new OsmDataLayer(new DataSet(), "l1", null);
-        OsmDataLayer layer2 = new OsmDataLayer(new DataSet(), "l1", null);
-
-        MainApplication.getLayerManager().addLayer(layer1);
-        MainApplication.getLayerManager().addLayer(layer2);
+        DataSet ds1 = new DataSet();
+        DataSet ds2 = new DataSet();
 
         Node osm = new Node(LatLon.ZERO);
-        assertTrue(new AddCommand(layer2, osm).executeCommand());
+        assertTrue(new AddCommand(ds2, osm).executeCommand());
 
-        assertArrayEquals(new Object[0], layer1.data.allPrimitives().toArray());
-        assertArrayEquals(new Object[] {osm}, layer2.data.allPrimitives().toArray());
+        assertArrayEquals(new Object[0], ds1.allPrimitives().toArray());
+        assertArrayEquals(new Object[] {osm}, ds2.allPrimitives().toArray());
     }
 
@@ -76,14 +71,12 @@
     @Test
     public void testUndo() {
-        OsmDataLayer layer1 = new OsmDataLayer(new DataSet(), "l1", null);
-        MainApplication.getLayerManager().addLayer(layer1);
         Node osm = new Node(LatLon.ZERO);
-        layer1.data.addPrimitive(osm);
+        DataSet ds = new DataSet(osm);
 
-        AddCommand command = new AddCommand(new Node(LatLon.ZERO));
+        AddCommand command = new AddCommand(ds, new Node(LatLon.ZERO));
         command.executeCommand();
 
         command.undoCommand();
-        assertArrayEquals(new Object[] {osm}, layer1.data.allPrimitives().toArray());
+        assertArrayEquals(new Object[] {osm}, ds.allPrimitives().toArray());
     }
 
@@ -95,5 +88,5 @@
         Node osm = new Node(LatLon.ZERO);
 
-        assertArrayEquals(new Object[] {osm}, new AddCommand(osm).getParticipatingPrimitives().toArray());
+        assertArrayEquals(new Object[] {osm}, new AddCommand(new DataSet(), osm).getParticipatingPrimitives().toArray());
     }
 
@@ -108,5 +101,5 @@
         ArrayList<OsmPrimitive> deleted = new ArrayList<>();
         ArrayList<OsmPrimitive> added = new ArrayList<>();
-        new AddCommand(osm).fillModifiedData(modified, deleted, added);
+        new AddCommand(new DataSet(), osm).fillModifiedData(modified, deleted, added);
         assertArrayEquals(new Object[] {}, modified.toArray());
         assertArrayEquals(new Object[] {}, deleted.toArray());
@@ -127,7 +120,8 @@
         relation.put("name", "xy");
 
-        assertTrue(new AddCommand(node).getDescriptionText().matches("Add node.*xy.*"));
-        assertTrue(new AddCommand(way).getDescriptionText().matches("Add way.*xy.*"));
-        assertTrue(new AddCommand(relation).getDescriptionText().matches("Add relation.*xy.*"));
+        DataSet ds = new DataSet();
+        assertTrue(new AddCommand(ds, node).getDescriptionText().matches("Add node.*xy.*"));
+        assertTrue(new AddCommand(ds, way).getDescriptionText().matches("Add way.*xy.*"));
+        assertTrue(new AddCommand(ds, relation).getDescriptionText().matches("Add relation.*xy.*"));
     }
 
Index: /trunk/test/unit/org/openstreetmap/josm/command/AddPrimitivesCommandTest.java
===================================================================
--- /trunk/test/unit/org/openstreetmap/josm/command/AddPrimitivesCommandTest.java	(revision 12725)
+++ /trunk/test/unit/org/openstreetmap/josm/command/AddPrimitivesCommandTest.java	(revision 12726)
@@ -23,5 +23,4 @@
 import org.openstreetmap.josm.data.osm.Way;
 import org.openstreetmap.josm.data.osm.WayData;
-import org.openstreetmap.josm.gui.MainApplication;
 import org.openstreetmap.josm.gui.layer.OsmDataLayer;
 import org.openstreetmap.josm.testutils.JOSMTestRules;
@@ -48,12 +47,11 @@
     @Test
     public void testAdd() {
-        OsmDataLayer layer1 = new OsmDataLayer(new DataSet(), "l1", null);
-        MainApplication.getLayerManager().addLayer(layer1);
-
-        List<PrimitiveData> testData = createTestData();
-        assertTrue(new AddPrimitivesCommand(testData).executeCommand());
-
-        testContainsTestData(layer1);
-        assertEquals(3, layer1.data.getAllSelected().size());
+        DataSet ds = new DataSet();
+
+        List<PrimitiveData> testData = createTestData();
+        assertTrue(new AddPrimitivesCommand(testData, ds).executeCommand());
+
+        testContainsTestData(ds);
+        assertEquals(3, ds.getAllSelected().size());
     }
 
@@ -63,35 +61,31 @@
     @Test
     public void testAddSetSelection() {
-        OsmDataLayer layer1 = new OsmDataLayer(new DataSet(), "l1", null);
-        MainApplication.getLayerManager().addLayer(layer1);
-
-        List<PrimitiveData> testData = createTestData();
-        assertTrue(new AddPrimitivesCommand(testData, testData.subList(2, 3)).executeCommand());
-
-        testContainsTestData(layer1);
-
-        assertEquals(1, layer1.data.getAllSelected().size());
-        assertEquals(1, layer1.data.getSelectedWays().size());
-    }
-
-    /**
-     * Tests if the add command respects the layer.
+        DataSet ds = new DataSet();
+
+        List<PrimitiveData> testData = createTestData();
+        assertTrue(new AddPrimitivesCommand(testData, testData.subList(2, 3), ds).executeCommand());
+
+        testContainsTestData(ds);
+
+        assertEquals(1, ds.getAllSelected().size());
+        assertEquals(1, ds.getSelectedWays().size());
+    }
+
+    /**
+     * Tests if the add command respects the data set.
      */
     @Test
     public void testAddToLayer() {
-        OsmDataLayer layer1 = new OsmDataLayer(new DataSet(), "l1", null);
-        OsmDataLayer layer2 = new OsmDataLayer(new DataSet(), "l1", null);
-
-        MainApplication.getLayerManager().addLayer(layer1);
-        MainApplication.getLayerManager().addLayer(layer2);
-
-        List<PrimitiveData> testData = createTestData();
-        assertTrue(new AddPrimitivesCommand(testData, testData.subList(2, 3), layer1).executeCommand());
-
-        testContainsTestData(layer1);
-        assertTrue(layer2.data.allPrimitives().isEmpty());
-
-        assertEquals(1, layer1.data.getAllSelected().size());
-        assertEquals(1, layer1.data.getSelectedWays().size());
+        DataSet ds1 = new DataSet();
+        DataSet ds2 = new DataSet();
+
+        List<PrimitiveData> testData = createTestData();
+        assertTrue(new AddPrimitivesCommand(testData, testData.subList(2, 3), ds1).executeCommand());
+
+        testContainsTestData(ds1);
+        assertTrue(ds2.allPrimitives().isEmpty());
+
+        assertEquals(1, ds1.getAllSelected().size());
+        assertEquals(1, ds1.getSelectedWays().size());
     }
 
@@ -101,17 +95,16 @@
     @Test
     public void testAddIgnoresExisting() {
-        OsmDataLayer layer1 = new OsmDataLayer(new DataSet(), "l1", null);
-        MainApplication.getLayerManager().addLayer(layer1);
-
-        List<PrimitiveData> testData = createTestData();
-        assertTrue(new AddPrimitivesCommand(testData).executeCommand());
-        assertEquals(2, layer1.data.getNodes().size());
-        assertEquals(1, layer1.data.getWays().size());
+        DataSet ds = new DataSet();
+
+        List<PrimitiveData> testData = createTestData();
+        assertTrue(new AddPrimitivesCommand(testData, ds).executeCommand());
+        assertEquals(2, ds.getNodes().size());
+        assertEquals(1, ds.getWays().size());
 
         testData.set(2, createTestNode(7));
-        assertTrue(new AddPrimitivesCommand(testData).executeCommand());
-
-        assertEquals(3, layer1.data.getNodes().size());
-        assertEquals(1, layer1.data.getWays().size());
+        assertTrue(new AddPrimitivesCommand(testData, ds).executeCommand());
+
+        assertEquals(3, ds.getNodes().size());
+        assertEquals(1, ds.getWays().size());
     }
 
@@ -121,12 +114,11 @@
     @Test
     public void testDescription() {
-        OsmDataLayer layer1 = new OsmDataLayer(new DataSet(), "l1", null);
-        MainApplication.getLayerManager().addLayer(layer1);
+        DataSet ds = new DataSet();
 
         List<PrimitiveData> testData = createTestData();
         NodeData data2 = createTestNode(7);
 
-        AddPrimitivesCommand command1 = new AddPrimitivesCommand(testData);
-        AddPrimitivesCommand command2 = new AddPrimitivesCommand(Arrays.<PrimitiveData>asList(data2));
+        AddPrimitivesCommand command1 = new AddPrimitivesCommand(testData, ds);
+        AddPrimitivesCommand command2 = new AddPrimitivesCommand(Arrays.<PrimitiveData>asList(data2), ds);
 
         assertEquals("Added 3 objects", command1.getDescriptionText());
@@ -146,16 +138,15 @@
     @Test
     public void testUndo() {
-        OsmDataLayer layer1 = new OsmDataLayer(new DataSet(), "l1", null);
-        MainApplication.getLayerManager().addLayer(layer1);
-
-        List<PrimitiveData> testData = createTestData();
-
-        AddPrimitivesCommand command = new AddPrimitivesCommand(testData);
+        DataSet ds = new DataSet();
+
+        List<PrimitiveData> testData = createTestData();
+
+        AddPrimitivesCommand command = new AddPrimitivesCommand(testData, ds);
 
         assertTrue(command.executeCommand());
 
-        assertEquals(3, layer1.data.allPrimitives().size());
-        assertEquals(1, layer1.data.getWays().size());
-        Way way = layer1.data.getWays().iterator().next();
+        assertEquals(3, ds.allPrimitives().size());
+        assertEquals(1, ds.getWays().size());
+        Way way = ds.getWays().iterator().next();
 
         for (int i = 0; i < 2; i++) {
@@ -163,13 +154,13 @@
             command.undoCommand();
 
-            assertEquals(0, layer1.data.allPrimitives().size());
-            assertEquals(0, layer1.data.getWays().size());
+            assertEquals(0, ds.allPrimitives().size());
+            assertEquals(0, ds.getWays().size());
 
             // redo
             assertTrue(command.executeCommand());
 
-            assertEquals(3, layer1.data.allPrimitives().size());
-            assertEquals(1, layer1.data.getWays().size());
-            assertSame(way, layer1.data.getWays().iterator().next());
+            assertEquals(3, ds.allPrimitives().size());
+            assertEquals(1, ds.getWays().size());
+            assertSame(way, ds.getWays().iterator().next());
         }
     }
@@ -181,21 +172,20 @@
     @Test
     public void testUndoIgnoresExisting() {
-        OsmDataLayer layer1 = new OsmDataLayer(new DataSet(), "l1", null);
-        MainApplication.getLayerManager().addLayer(layer1);
-
-        List<PrimitiveData> testData = createTestData();
-
-        assertTrue(new AddPrimitivesCommand(testData).executeCommand());
-        assertEquals(2, layer1.data.getNodes().size());
-        assertEquals(1, layer1.data.getWays().size());
+        DataSet ds = new DataSet();
+
+        List<PrimitiveData> testData = createTestData();
+
+        assertTrue(new AddPrimitivesCommand(testData, ds).executeCommand());
+        assertEquals(2, ds.getNodes().size());
+        assertEquals(1, ds.getWays().size());
 
         testData.set(2, createTestNode(7));
 
-        AddPrimitivesCommand command = new AddPrimitivesCommand(testData);
+        AddPrimitivesCommand command = new AddPrimitivesCommand(testData, ds);
 
         assertTrue(command.executeCommand());
 
-        assertEquals(3, layer1.data.getNodes().size());
-        assertEquals(1, layer1.data.getWays().size());
+        assertEquals(3, ds.getNodes().size());
+        assertEquals(1, ds.getWays().size());
 
         for (int i = 0; i < 2; i++) {
@@ -203,12 +193,12 @@
             command.undoCommand();
 
-            assertEquals(2, layer1.data.getNodes().size());
-            assertEquals(1, layer1.data.getWays().size());
+            assertEquals(2, ds.getNodes().size());
+            assertEquals(1, ds.getWays().size());
 
             // redo
             assertTrue(command.executeCommand());
 
-            assertEquals(3, layer1.data.getNodes().size());
-            assertEquals(1, layer1.data.getWays().size());
+            assertEquals(3, ds.getNodes().size());
+            assertEquals(1, ds.getWays().size());
         }
     }
@@ -219,13 +209,12 @@
     @Test
     public void testParticipatingPrimitives() {
-        OsmDataLayer layer1 = new OsmDataLayer(new DataSet(), "l1", null);
-        MainApplication.getLayerManager().addLayer(layer1);
-
-        List<PrimitiveData> testData = createTestData();
-        AddPrimitivesCommand command = new AddPrimitivesCommand(testData);
+        DataSet ds = new DataSet();
+
+        List<PrimitiveData> testData = createTestData();
+        AddPrimitivesCommand command = new AddPrimitivesCommand(testData, ds);
         assertTrue(command.executeCommand());
 
         assertEquals(3, command.getParticipatingPrimitives().size());
-        HashSet<OsmPrimitive> should = new HashSet<>(layer1.data.allPrimitives());
+        HashSet<OsmPrimitive> should = new HashSet<>(ds.allPrimitives());
         assertEquals(should, new HashSet<>(command.getParticipatingPrimitives()));
 
@@ -245,5 +234,5 @@
 
         List<PrimitiveData> testData = createTestData();
-        new AddPrimitivesCommand(testData).fillModifiedData(modified, deleted, added);
+        new AddPrimitivesCommand(testData, new DataSet()).fillModifiedData(modified, deleted, added);
 
         assertArrayEquals(new Object[] {}, modified.toArray());
@@ -252,19 +241,19 @@
     }
 
-    private void testContainsTestData(OsmDataLayer layer1) {
-        assertEquals(3, layer1.data.allPrimitives().size());
-        assertEquals(2, layer1.data.getNodes().size());
-        assertEquals(1, layer1.data.getWays().size());
-        assertEquals(3, layer1.data.allModifiedPrimitives().size());
-        for (OsmPrimitive n : layer1.data.allPrimitives()) {
+    private void testContainsTestData(DataSet data) {
+        assertEquals(3, data.allPrimitives().size());
+        assertEquals(2, data.getNodes().size());
+        assertEquals(1, data.getWays().size());
+        assertEquals(3, data.allModifiedPrimitives().size());
+        for (OsmPrimitive n : data.allPrimitives()) {
             assertEquals("test", n.get("test"));
             assertTrue(n.isModified());
         }
 
-        for (Node n : layer1.data.getNodes()) {
+        for (Node n : data.getNodes()) {
             assertEquals(LatLon.ZERO, n.getCoor());
         }
 
-        for (Way w : layer1.data.getWays()) {
+        for (Way w : data.getWays()) {
             assertEquals(2, w.getNodes().size());
             assertEquals(5, w.getNode(0).getId());
Index: /trunk/test/unit/org/openstreetmap/josm/command/ChangeCommandTest.java
===================================================================
--- /trunk/test/unit/org/openstreetmap/josm/command/ChangeCommandTest.java	(revision 12725)
+++ /trunk/test/unit/org/openstreetmap/josm/command/ChangeCommandTest.java	(revision 12726)
@@ -142,8 +142,9 @@
         Relation relation = new Relation();
         relation.put("name", "xy");
+        DataSet ds = new DataSet(node, way, relation);
 
-        assertTrue(new ChangeCommand(node, node).getDescriptionText().matches("Change node.*xy.*"));
-        assertTrue(new ChangeCommand(way, way).getDescriptionText().matches("Change way.*xy.*"));
-        assertTrue(new ChangeCommand(relation, relation).getDescriptionText().matches("Change relation.*xy.*"));
+        assertTrue(new ChangeCommand(ds, node, node).getDescriptionText().matches("Change node.*xy.*"));
+        assertTrue(new ChangeCommand(ds, way, way).getDescriptionText().matches("Change way.*xy.*"));
+        assertTrue(new ChangeCommand(ds, relation, relation).getDescriptionText().matches("Change relation.*xy.*"));
     }
 
Index: /trunk/test/unit/org/openstreetmap/josm/command/ChangeNodesCommandTest.java
===================================================================
--- /trunk/test/unit/org/openstreetmap/josm/command/ChangeNodesCommandTest.java	(revision 12725)
+++ /trunk/test/unit/org/openstreetmap/josm/command/ChangeNodesCommandTest.java	(revision 12726)
@@ -115,7 +115,7 @@
         way.addNode(node);
         way.put("name", "xy");
-
+        DataSet ds = new DataSet(node, way);
         assertTrue(
-                new ChangeNodesCommand(way, Arrays.asList(node)).getDescriptionText().matches("Change nodes of.*xy.*"));
+                new ChangeNodesCommand(ds, way, Arrays.asList(node)).getDescriptionText().matches("Change nodes of.*xy.*"));
     }
 
Index: /trunk/test/unit/org/openstreetmap/josm/command/ChangePropertyCommandTest.java
===================================================================
--- /trunk/test/unit/org/openstreetmap/josm/command/ChangePropertyCommandTest.java	(revision 12725)
+++ /trunk/test/unit/org/openstreetmap/josm/command/ChangePropertyCommandTest.java	(revision 12726)
@@ -201,9 +201,8 @@
         tagsRemove.put("existing", "");
 
-        Way way = new Way();
-        way.addNode(node1);
+        Way way = testData.createWay(20, node1);
         way.put("name", "xy");
         way.put("existing", "existing");
-        Relation relation = new Relation();
+        Relation relation = testData.createRelation(30);
         relation.put("name", "xy");
         relation.put("existing", "existing");
Index: /trunk/test/unit/org/openstreetmap/josm/command/CommandTest.java
===================================================================
--- /trunk/test/unit/org/openstreetmap/josm/command/CommandTest.java	(revision 12725)
+++ /trunk/test/unit/org/openstreetmap/josm/command/CommandTest.java	(revision 12726)
@@ -2,10 +2,6 @@
 package org.openstreetmap.josm.command;
 
-import static org.junit.Assert.assertSame;
+import java.util.Arrays;
 
-import java.util.Arrays;
-import java.util.Collection;
-
-import org.junit.Before;
 import org.junit.Rule;
 import org.junit.Test;
@@ -13,5 +9,4 @@
 import org.openstreetmap.josm.data.osm.DataSet;
 import org.openstreetmap.josm.data.osm.Node;
-import org.openstreetmap.josm.data.osm.OsmPrimitive;
 import org.openstreetmap.josm.data.osm.Relation;
 import org.openstreetmap.josm.data.osm.RelationMember;
@@ -37,27 +32,4 @@
     @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD")
     public JOSMTestRules test = new JOSMTestRules().preferences().i18n();
-    private CommandTestData testData;
-
-    /**
-     * Set up the test data.
-     */
-    @Before
-    public void createTestData() {
-        testData = new CommandTestData();
-    }
-
-    /**
-     * Test {@link Command#getLayer()}
-     * @deprecated to be removed end of 2017
-     */
-    @Test
-    @Deprecated
-    public void testGetLayer() {
-        OsmDataLayer layer2 = new OsmDataLayer(new DataSet(), "test", null);
-        Command command = new NopCommand();
-        Command command2 = new NopCommand(layer2.data);
-        assertSame(testData.layer, command.getLayer());
-        assertSame(layer2, command2.getLayer());
-    }
 
     /**
@@ -75,25 +47,4 @@
             .suppress(Warning.NONFINAL_FIELDS)
             .verify();
-    }
-
-    private static final class NopCommand extends Command {
-        NopCommand() {
-            super();
-        }
-
-        NopCommand(DataSet dataset) {
-            super(dataset);
-        }
-
-        @Override
-        public String getDescriptionText() {
-            return "";
-        }
-
-        @Override
-        public void fillModifiedData(Collection<OsmPrimitive> modified, Collection<OsmPrimitive> deleted,
-                Collection<OsmPrimitive> added) {
-            // nop
-        }
     }
 
Index: /trunk/test/unit/org/openstreetmap/josm/command/DeleteCommandTest.java
===================================================================
--- /trunk/test/unit/org/openstreetmap/josm/command/DeleteCommandTest.java	(revision 12725)
+++ /trunk/test/unit/org/openstreetmap/josm/command/DeleteCommandTest.java	(revision 12726)
@@ -11,4 +11,5 @@
 import java.util.Collection;
 import java.util.List;
+import java.util.NoSuchElementException;
 
 import org.junit.Before;
@@ -113,9 +114,9 @@
      */
     @Test
-    public void testDelteNodesInWay() {
+    public void testDeleteNodesInWay() {
         testData.existingNode.removeAll();
         // That untagged node should be deleted.
         testData.existingNode2.removeAll();
-        DeleteCommand.delete(testData.layer, Arrays.asList(testData.existingWay), true, true).executeCommand();
+        DeleteCommand.delete(Arrays.asList(testData.existingWay), true, true).executeCommand();
 
         assertTrue(testData.existingWay.isDeleted());
@@ -137,5 +138,5 @@
         way2.setNodes(Arrays.asList(node2, node3, node4));
         testData.layer.data.addPrimitive(way2);
-        DeleteCommand.delete(testData.layer, Arrays.asList(way1, way2), true, true).executeCommand();
+        DeleteCommand.delete(Arrays.asList(way1, way2), true, true).executeCommand();
 
         assertTrue(way1.isDeleted());
@@ -167,5 +168,5 @@
      * Test that {@link DeleteCommand} checks for non-empty list
      */
-    @Test(expected = IllegalArgumentException.class)
+    @Test(expected = NoSuchElementException.class)
     public void testConsistencyNonEmpty() {
         new DeleteCommand(Arrays.<OsmPrimitive>asList());
@@ -175,5 +176,5 @@
      * Test that {@link DeleteCommand} checks for non-null list
      */
-    @Test(expected = IllegalArgumentException.class)
+    @Test(expected = NullPointerException.class)
     public void testConsistencyNonNull() {
         new DeleteCommand((Collection<OsmPrimitive>) null);
Index: /trunk/test/unit/org/openstreetmap/josm/command/MoveCommandTest.java
===================================================================
--- /trunk/test/unit/org/openstreetmap/josm/command/MoveCommandTest.java	(revision 12725)
+++ /trunk/test/unit/org/openstreetmap/josm/command/MoveCommandTest.java	(revision 12726)
@@ -248,5 +248,5 @@
         Node node = new Node(LatLon.ZERO);
         node.put("name", "xy");
-
+        new DataSet(node);
         List<OsmPrimitive> nodeList = Arrays.<OsmPrimitive>asList(node);
         assertTrue(new MoveCommand(nodeList, 1, 2).getDescriptionText().matches("Move 1 node"));
Index: /trunk/test/unit/org/openstreetmap/josm/command/RotateCommandTest.java
===================================================================
--- /trunk/test/unit/org/openstreetmap/josm/command/RotateCommandTest.java	(revision 12725)
+++ /trunk/test/unit/org/openstreetmap/josm/command/RotateCommandTest.java	(revision 12726)
@@ -55,4 +55,5 @@
         Node n2 = new Node(new EastNorth(-1, 0));
         Node n3 = new Node(new EastNorth(-9, -10));
+        new DataSet(n1, n2, n3);
         RotateCommand rotate = new RotateCommand(Arrays.asList(n1, n2, n3), new EastNorth(0, 0));
         rotate.setRotationAngle(Math.PI / 4);
@@ -73,4 +74,5 @@
         Node n2 = new Node(new EastNorth(-1, 0));
         Node n3 = new Node(new EastNorth(-9, -10));
+        new DataSet(n1, n2, n3);
         RotateCommand rotate = new RotateCommand(Arrays.asList(n1, n2, n3), new EastNorth(0, 0));
         rotate.setRotationAngle(Math.PI / 4);
Index: /trunk/test/unit/org/openstreetmap/josm/command/ScaleCommandTest.java
===================================================================
--- /trunk/test/unit/org/openstreetmap/josm/command/ScaleCommandTest.java	(revision 12725)
+++ /trunk/test/unit/org/openstreetmap/josm/command/ScaleCommandTest.java	(revision 12726)
@@ -55,4 +55,5 @@
         Node n2 = new Node(new EastNorth(-1, 0));
         Node n3 = new Node(new EastNorth(-9, -10));
+        new DataSet(n1, n2, n3);
         ScaleCommand scale = new ScaleCommand(Arrays.asList(n1, n2, n3), new EastNorth(0, 0));
         scale.setScalingFactor(2.5);
@@ -73,4 +74,5 @@
         Node n2 = new Node(new EastNorth(-1, 0));
         Node n3 = new Node(new EastNorth(-9, -10));
+        new DataSet(n1, n2, n3);
         ScaleCommand scale = new ScaleCommand(Arrays.asList(n1, n2, n3), new EastNorth(0, 0));
         scale.setScalingFactor(2.5);
Index: /trunk/test/unit/org/openstreetmap/josm/command/SelectCommandTest.java
===================================================================
--- /trunk/test/unit/org/openstreetmap/josm/command/SelectCommandTest.java	(revision 12725)
+++ /trunk/test/unit/org/openstreetmap/josm/command/SelectCommandTest.java	(revision 12726)
@@ -50,5 +50,5 @@
     @Test
     public void testExecute() {
-        SelectCommand command = new SelectCommand(Arrays.asList(testData.existingNode, testData.existingWay));
+        SelectCommand command = new SelectCommand(testData.layer.data, Arrays.asList(testData.existingNode, testData.existingWay));
 
         testData.layer.data.setSelected(Arrays.asList(testData.existingNode2));
@@ -67,5 +67,5 @@
     public void testExecuteAfterModify() {
         List<OsmPrimitive> list = new ArrayList<>(Arrays.asList(testData.existingNode, testData.existingWay));
-        SelectCommand command = new SelectCommand(list);
+        SelectCommand command = new SelectCommand(testData.layer.data, list);
 
         list.remove(testData.existingNode);
@@ -84,5 +84,5 @@
     @Test
     public void testUndo() {
-        SelectCommand command = new SelectCommand(Arrays.asList(testData.existingNode, testData.existingWay));
+        SelectCommand command = new SelectCommand(testData.layer.data, Arrays.asList(testData.existingNode, testData.existingWay));
         testData.layer.data.setSelected(Arrays.asList(testData.existingNode2));
 
@@ -110,5 +110,5 @@
         ArrayList<OsmPrimitive> deleted = new ArrayList<>();
         ArrayList<OsmPrimitive> added = new ArrayList<>();
-        SelectCommand command = new SelectCommand(Arrays.asList(testData.existingNode, testData.existingWay));
+        SelectCommand command = new SelectCommand(testData.layer.data, Arrays.asList(testData.existingNode, testData.existingWay));
         command.fillModifiedData(modified, deleted, added);
         // intentionally empty.
@@ -123,5 +123,5 @@
     @Test
     public void testGetParticipatingPrimitives() {
-        SelectCommand command = new SelectCommand(Arrays.asList(testData.existingNode));
+        SelectCommand command = new SelectCommand(testData.layer.data, Arrays.asList(testData.existingNode));
         command.executeCommand();
         assertArrayEquals(new Object[] {testData.existingNode}, command.getParticipatingPrimitives().toArray());
@@ -133,11 +133,12 @@
     @Test
     public void testDescription() {
-        assertTrue(new SelectCommand(Arrays.<OsmPrimitive>asList(testData.existingNode))
+        DataSet ds = testData.layer.data;
+        assertTrue(new SelectCommand(ds, Arrays.<OsmPrimitive>asList(testData.existingNode))
                 .getDescriptionText().matches("Selected 1 object"));
-        assertTrue(new SelectCommand(Arrays.asList(testData.existingNode, testData.existingWay))
+        assertTrue(new SelectCommand(ds, Arrays.asList(testData.existingNode, testData.existingWay))
                 .getDescriptionText().matches("Selected 2 objects"));
-        assertTrue(new SelectCommand(Arrays.<OsmPrimitive>asList())
+        assertTrue(new SelectCommand(ds, Arrays.<OsmPrimitive>asList())
                 .getDescriptionText().matches("Selected 0 objects"));
-        assertTrue(new SelectCommand(null)
+        assertTrue(new SelectCommand(ds, null)
                 .getDescriptionText().matches("Selected 0 objects"));
     }
Index: /trunk/test/unit/org/openstreetmap/josm/command/SequenceCommandTest.java
===================================================================
--- /trunk/test/unit/org/openstreetmap/josm/command/SequenceCommandTest.java	(revision 12725)
+++ /trunk/test/unit/org/openstreetmap/josm/command/SequenceCommandTest.java	(revision 12726)
@@ -12,4 +12,5 @@
 import java.util.Arrays;
 import java.util.Collection;
+import java.util.Collections;
 
 import org.junit.Before;
@@ -54,6 +55,7 @@
     @Test
     public void testExecute() {
-        final TestCommand command1 = new TestCommand(Arrays.<OsmPrimitive>asList(testData.existingNode));
-        TestCommand command2 = new TestCommand(Arrays.<OsmPrimitive>asList(testData.existingNode2)) {
+        DataSet ds = new DataSet();
+        final TestCommand command1 = new TestCommand(ds, Arrays.<OsmPrimitive>asList(testData.existingNode));
+        TestCommand command2 = new TestCommand(ds, Arrays.<OsmPrimitive>asList(testData.existingNode2)) {
             @Override
             public boolean executeCommand() {
@@ -75,6 +77,7 @@
     @Test
     public void testUndo() {
-        final TestCommand command2 = new TestCommand(Arrays.<OsmPrimitive>asList(testData.existingNode2));
-        TestCommand command1 = new TestCommand(Arrays.<OsmPrimitive>asList(testData.existingNode)) {
+        DataSet ds = new DataSet();
+        final TestCommand command2 = new TestCommand(ds, Arrays.<OsmPrimitive>asList(testData.existingNode2));
+        TestCommand command1 = new TestCommand(ds, Arrays.<OsmPrimitive>asList(testData.existingNode)) {
             @Override
             public void undoCommand() {
@@ -103,7 +106,8 @@
     @Test
     public void testExecuteRollback() {
-        TestCommand command1 = new TestCommand(null);
-        FailingCommand command2 = new FailingCommand();
-        TestCommand command3 = new TestCommand(null);
+        DataSet ds = new DataSet();
+        TestCommand command1 = new TestCommand(ds, null);
+        FailingCommand command2 = new FailingCommand(ds);
+        TestCommand command3 = new TestCommand(ds, null);
         SequenceCommand command = new SequenceCommand("seq", Arrays.<Command>asList(command1, command2, command3));
         assertFalse(command.executeCommand());
@@ -119,7 +123,8 @@
     @Test
     public void testContinueOnErrors() {
-        TestCommand command1 = new TestCommand(null);
-        FailingCommand command2 = new FailingCommand();
-        TestCommand command3 = new TestCommand(null);
+        DataSet ds = new DataSet();
+        TestCommand command1 = new TestCommand(ds, null);
+        FailingCommand command2 = new FailingCommand(ds);
+        TestCommand command3 = new TestCommand(ds, null);
         SequenceCommand command = new SequenceCommand("seq", Arrays.<Command>asList(command1, command2, command3), true);
         assertTrue(command.executeCommand());
@@ -137,9 +142,10 @@
     @Test
     public void testGetLastCommand() {
-        final TestCommand command1 = new TestCommand(Arrays.<OsmPrimitive>asList(testData.existingNode));
-        final TestCommand command2 = new TestCommand(Arrays.<OsmPrimitive>asList(testData.existingNode2));
-
-        assertEquals(command2, new SequenceCommand("seq", command1, command2).getLastCommand());
-        assertNull(new SequenceCommand("seq").getLastCommand());
+        DataSet ds = new DataSet();
+        final TestCommand command1 = new TestCommand(ds, Arrays.<OsmPrimitive>asList(testData.existingNode));
+        final TestCommand command2 = new TestCommand(ds, Arrays.<OsmPrimitive>asList(testData.existingNode2));
+
+        assertEquals(command2, new SequenceCommand(ds, "seq", Arrays.asList(command1, command2), false).getLastCommand());
+        assertNull(new SequenceCommand(ds, "seq", Collections.emptyList(), false).getLastCommand());
     }
 
@@ -149,7 +155,8 @@
     @Test
     public void testFillModifiedData() {
-        Command command1 = new TestCommand(Arrays.<OsmPrimitive>asList(testData.existingNode));
-        Command command2 = new TestCommand(Arrays.<OsmPrimitive>asList(testData.existingNode2));
-        Command command3 = new TestCommand(Arrays.<OsmPrimitive>asList(testData.existingWay)) {
+        DataSet ds = new DataSet();
+        Command command1 = new TestCommand(ds, Arrays.<OsmPrimitive>asList(testData.existingNode));
+        Command command2 = new TestCommand(ds, Arrays.<OsmPrimitive>asList(testData.existingNode2));
+        Command command3 = new TestCommand(ds, Arrays.<OsmPrimitive>asList(testData.existingWay)) {
             @Override
             public void fillModifiedData(Collection<OsmPrimitive> modified, Collection<OsmPrimitive> deleted,
@@ -158,5 +165,5 @@
             }
         };
-        Command command4 = new TestCommand(Arrays.<OsmPrimitive>asList(testData.existingRelation)) {
+        Command command4 = new TestCommand(ds, Arrays.<OsmPrimitive>asList(testData.existingRelation)) {
             @Override
             public void fillModifiedData(Collection<OsmPrimitive> modified, Collection<OsmPrimitive> deleted,
@@ -181,6 +188,7 @@
     @Test
     public void testGetParticipatingPrimitives() {
-        Command command1 = new TestCommand(Arrays.<OsmPrimitive>asList(testData.existingNode));
-        Command command2 = new TestCommand(Arrays.<OsmPrimitive>asList(testData.existingNode2));
+        DataSet ds = new DataSet();
+        Command command1 = new TestCommand(ds, Arrays.<OsmPrimitive>asList(testData.existingNode));
+        Command command2 = new TestCommand(ds, Arrays.<OsmPrimitive>asList(testData.existingNode2));
 
         SequenceCommand command = new SequenceCommand("seq", command1, command2);
@@ -197,5 +205,5 @@
     @Test
     public void testDescription() {
-        assertTrue(new SequenceCommand("test").getDescriptionText().matches("Sequence: test"));
+        assertTrue(new SequenceCommand(new DataSet(), "test", Collections.emptyList(), false).getDescriptionText().matches("Sequence: test"));
     }
 
@@ -205,7 +213,8 @@
     @Test
     public void testEqualsContract() {
+        DataSet ds = new DataSet();
         EqualsVerifier.forClass(SequenceCommand.class).usingGetClass()
             .withPrefabValues(Command.class,
-                new AddCommand(new Node(1)), new AddCommand(new Node(2)))
+                new AddCommand(ds, new Node(1)), new AddCommand(ds, new Node(2)))
             .withPrefabValues(DataSet.class,
                     new DataSet(), new DataSet())
@@ -222,6 +231,6 @@
         protected boolean executed;
 
-        TestCommand(Collection<? extends OsmPrimitive> primitives) {
-            super();
+        TestCommand(DataSet ds, Collection<? extends OsmPrimitive> primitives) {
+            super(ds);
             this.primitives = primitives;
         }
@@ -266,6 +275,6 @@
     private static class FailingCommand extends TestCommand {
 
-        FailingCommand() {
-            super(null);
+        FailingCommand(DataSet ds) {
+            super(ds, null);
         }
 
@@ -286,6 +295,4 @@
             return "FailingCommand";
         }
-
-    }
-
+    }
 }
Index: /trunk/test/unit/org/openstreetmap/josm/command/conflict/ConflictAddCommandTest.java
===================================================================
--- /trunk/test/unit/org/openstreetmap/josm/command/conflict/ConflictAddCommandTest.java	(revision 12725)
+++ /trunk/test/unit/org/openstreetmap/josm/command/conflict/ConflictAddCommandTest.java	(revision 12726)
@@ -6,8 +6,8 @@
 import static org.junit.Assert.assertTrue;
 
-import org.junit.After;
 import org.junit.Before;
 import org.junit.Rule;
 import org.junit.Test;
+import org.openstreetmap.josm.command.CommandTest.CommandTestData;
 import org.openstreetmap.josm.data.conflict.Conflict;
 import org.openstreetmap.josm.data.osm.DataSet;
@@ -15,5 +15,4 @@
 import org.openstreetmap.josm.data.osm.User;
 import org.openstreetmap.josm.data.osm.Way;
-import org.openstreetmap.josm.gui.MainApplication;
 import org.openstreetmap.josm.gui.layer.OsmDataLayer;
 import org.openstreetmap.josm.testutils.JOSMTestRules;
@@ -28,6 +27,4 @@
 public class ConflictAddCommandTest {
 
-    private OsmDataLayer layer;
-
     /**
      * Setup test.
@@ -36,4 +33,5 @@
     @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD")
     public JOSMTestRules test = new JOSMTestRules().platform();
+    private CommandTestData testData;
 
     /**
@@ -42,14 +40,5 @@
     @Before
     public void setUp() {
-        layer = new OsmDataLayer(new DataSet(), null, null);
-        MainApplication.getLayerManager().addLayer(layer);
-    }
-
-    /**
-     * Cleanup test resources.
-     */
-    @After
-    public void tearDown() {
-        MainApplication.getLayerManager().removeLayer(layer);
+        testData = new CommandTestData();
     }
 
@@ -59,6 +48,6 @@
     @Test
     public void testExecuteUndoCommand() {
-        DataSet ds = MainApplication.getLayerManager().getEditDataSet();
-        Conflict<Node> conflict = new Conflict<>(new Node(), new Node());
+        DataSet ds = testData.layer.data;
+        Conflict<Node> conflict = new Conflict<>(testData.existingNode, testData.existingNode2);
         ConflictAddCommand cmd = new ConflictAddCommand(ds, conflict);
         assertTrue(cmd.executeCommand());
@@ -75,7 +64,6 @@
     @Test
     public void testGetDescriptionIcon() {
-        OsmDataLayer layer = MainApplication.getLayerManager().getEditLayer();
-        Conflict<Node> conflict = new Conflict<>(new Node(), new Node());
-        assertNotNull(new ConflictAddCommand(layer, conflict).getDescriptionIcon());
+        Conflict<Node> conflict = new Conflict<>(testData.existingNode, testData.existingNode2);
+        assertNotNull(new ConflictAddCommand(testData.layer.data, conflict).getDescriptionIcon());
     }
 
Index: /trunk/test/unit/org/openstreetmap/josm/command/conflict/CoordinateConflictResolveCommandTest.java
===================================================================
--- /trunk/test/unit/org/openstreetmap/josm/command/conflict/CoordinateConflictResolveCommandTest.java	(revision 12725)
+++ /trunk/test/unit/org/openstreetmap/josm/command/conflict/CoordinateConflictResolveCommandTest.java	(revision 12726)
@@ -6,8 +6,8 @@
 import static org.junit.Assert.assertTrue;
 
-import org.junit.After;
 import org.junit.Before;
 import org.junit.Rule;
 import org.junit.Test;
+import org.openstreetmap.josm.command.CommandTest.CommandTestData;
 import org.openstreetmap.josm.data.conflict.Conflict;
 import org.openstreetmap.josm.data.coor.LatLon;
@@ -16,5 +16,4 @@
 import org.openstreetmap.josm.data.osm.User;
 import org.openstreetmap.josm.data.osm.Way;
-import org.openstreetmap.josm.gui.MainApplication;
 import org.openstreetmap.josm.gui.conflict.pair.MergeDecisionType;
 import org.openstreetmap.josm.gui.layer.OsmDataLayer;
@@ -30,5 +29,5 @@
 public class CoordinateConflictResolveCommandTest {
 
-    private OsmDataLayer layer;
+    private CommandTestData testData;
 
     /**
@@ -44,18 +43,9 @@
     @Before
     public void setUp() {
-        layer = new OsmDataLayer(new DataSet(), null, null);
-        MainApplication.getLayerManager().addLayer(layer);
+        testData = new CommandTestData();
     }
 
-    /**
-     * Cleanup test resources.
-     */
-    @After
-    public void tearDown() {
-        MainApplication.getLayerManager().removeLayer(layer);
-    }
-
-    private static Conflict<Node> createConflict() {
-        return new Conflict<>(new Node(LatLon.ZERO), new Node(new LatLon(50, 50)));
+    private Conflict<Node> createConflict() {
+        return new Conflict<>(testData.existingNode, testData.existingNode2);
     }
 
Index: /trunk/test/unit/org/openstreetmap/josm/data/validation/tests/MapCSSTagCheckerTest.java
===================================================================
--- /trunk/test/unit/org/openstreetmap/josm/data/validation/tests/MapCSSTagCheckerTest.java	(revision 12725)
+++ /trunk/test/unit/org/openstreetmap/josm/data/validation/tests/MapCSSTagCheckerTest.java	(revision 12726)
@@ -25,5 +25,5 @@
 import org.openstreetmap.josm.command.PseudoCommand;
 import org.openstreetmap.josm.command.SequenceCommand;
-import org.openstreetmap.josm.data.osm.Node;
+import org.openstreetmap.josm.data.osm.DataSet;
 import org.openstreetmap.josm.data.osm.OsmPrimitive;
 import org.openstreetmap.josm.data.osm.OsmUtils;
@@ -82,6 +82,7 @@
         assertEquals("fixAdd: natural=wetland", check.fixCommands.get(1).toString());
         assertEquals("fixAdd: wetland=marsh", check.fixCommands.get(2).toString());
-        final Node n1 = new Node();
-        n1.put("natural", "marsh");
+        final OsmPrimitive n1 = OsmUtils.createPrimitive("node natural=marsh");
+        final OsmPrimitive n2 = OsmUtils.createPrimitive("node natural=wood");
+        new DataSet(n1, n2);
         assertTrue(check.test(n1));
         assertEquals("deprecated", check.getErrorForPrimitive(n1).getMessage());
@@ -90,6 +91,4 @@
         assertEquals("Sequence: Fix of natural=marsh is deprecated", check.fixPrimitive(n1).getDescriptionText());
         assertEquals("{natural=}", ((ChangePropertyCommand) check.fixPrimitive(n1).getChildren().iterator().next()).getTags().toString());
-        final Node n2 = new Node();
-        n2.put("natural", "wood");
         assertFalse(check.test(n2));
         assertEquals("The key is natural and the value is marsh",
@@ -109,4 +108,5 @@
                 "fixAdd: \"highway=construction\";\n" +
                 "}")).parseChecks.get(0);
+        new DataSet(p);
         final Command command = check.fixPrimitive(p);
         assertTrue(command instanceof SequenceCommand);
Index: /trunk/test/unit/org/openstreetmap/josm/gui/conflict/pair/ConflictResolverTest.java
===================================================================
--- /trunk/test/unit/org/openstreetmap/josm/gui/conflict/pair/ConflictResolverTest.java	(revision 12725)
+++ /trunk/test/unit/org/openstreetmap/josm/gui/conflict/pair/ConflictResolverTest.java	(revision 12726)
@@ -5,4 +5,6 @@
 import static org.junit.Assert.assertNotNull;
 
+import java.util.NoSuchElementException;
+
 import org.junit.Rule;
 import org.junit.Test;
@@ -10,4 +12,5 @@
 import org.openstreetmap.josm.data.conflict.Conflict;
 import org.openstreetmap.josm.data.coor.LatLon;
+import org.openstreetmap.josm.data.osm.DataSet;
 import org.openstreetmap.josm.data.osm.Node;
 import org.openstreetmap.josm.data.osm.Relation;
@@ -32,5 +35,5 @@
      * Unit test of {@link ConflictResolver#buildResolveCommand} - empty case.
      */
-    @Test
+    @Test(expected = NoSuchElementException.class)
     public void testBuildResolveCommandEmpty() {
         assertNotNull(new ConflictResolver().buildResolveCommand());
@@ -47,4 +50,5 @@
         Node n2 = new Node(LatLon.NORTH_POLE);
         n2.put("source", "theirs");
+        new DataSet(n1, n2);
         resolver.populate(new Conflict<>(n1, n2));
         resolver.decideRemaining(MergeDecisionType.KEEP_MINE);
@@ -62,4 +66,5 @@
         Way w2 = new Way();
         w2.put("source", "theirs");
+        new DataSet(w1, w2);
         resolver.populate(new Conflict<>(w1, w2));
         resolver.decideRemaining(MergeDecisionType.KEEP_MINE);
@@ -77,4 +82,5 @@
         Relation r2 = new Relation();
         r2.put("source", "theirs");
+        new DataSet(r1, r2);
         resolver.populate(new Conflict<>(r1, r2));
         resolver.decideRemaining(MergeDecisionType.KEEP_MINE);
Index: /trunk/test/unit/org/openstreetmap/josm/gui/datatransfer/OsmTransferHandlerTest.java
===================================================================
--- /trunk/test/unit/org/openstreetmap/josm/gui/datatransfer/OsmTransferHandlerTest.java	(revision 12725)
+++ /trunk/test/unit/org/openstreetmap/josm/gui/datatransfer/OsmTransferHandlerTest.java	(revision 12726)
@@ -64,4 +64,5 @@
     public void testPasteTags() {
         Node n = new Node(LatLon.ZERO);
+        new DataSet(n);
 
         ClipboardUtils.copyString("test=ok");
Index: /trunk/test/unit/org/openstreetmap/josm/gui/dialogs/CommandStackDialogTest.java
===================================================================
--- /trunk/test/unit/org/openstreetmap/josm/gui/dialogs/CommandStackDialogTest.java	(revision 12725)
+++ /trunk/test/unit/org/openstreetmap/josm/gui/dialogs/CommandStackDialogTest.java	(revision 12726)
@@ -46,9 +46,10 @@
     @Test
     public void testCommandStackDialogNotEmpty() {
-        OsmDataLayer layer = new OsmDataLayer(new DataSet(), "", null);
+        DataSet ds = new DataSet();
+        OsmDataLayer layer = new OsmDataLayer(ds, "", null);
         MainApplication.getLayerManager().addLayer(layer);
         try {
-            Command cmd1 = TestUtils.newCommand();
-            Command cmd2 = TestUtils.newCommand();
+            Command cmd1 = TestUtils.newCommand(ds);
+            Command cmd2 = TestUtils.newCommand(ds);
             MainApplication.undoRedo.add(cmd1);
             MainApplication.undoRedo.add(cmd2);
