Index: trunk/src/org/openstreetmap/josm/command/Command.java
===================================================================
--- trunk/src/org/openstreetmap/josm/command/Command.java	(revision 12347)
+++ trunk/src/org/openstreetmap/josm/command/Command.java	(revision 12348)
@@ -338,4 +338,18 @@
     }
 
+    /**
+     * Ensures that all primitives that are participating in this command belong to the affected data set.
+     *
+     * Commands may use this in their update methods to check the consitency of the primitives they operate on.
+     * @throws AssertionError if no {@link DataSet} is set or if any primitive does not belong to that dataset.
+     */
+    protected void ensurePrimitivesAreInDataset() {
+        for (OsmPrimitive primitive : this.getParticipatingPrimitives()) {
+            if (primitive.getDataSet() != this.getAffectedDataSet()) {
+                throw new AssertionError("Primitive is of wrong data set for this command: " + primitive);
+            }
+        }
+    }
+
     @Override
     public int hashCode() {
Index: trunk/src/org/openstreetmap/josm/command/DeleteCommand.java
===================================================================
--- trunk/src/org/openstreetmap/josm/command/DeleteCommand.java	(revision 12347)
+++ trunk/src/org/openstreetmap/josm/command/DeleteCommand.java	(revision 12348)
@@ -168,4 +168,5 @@
     @Override
     public boolean executeCommand() {
+        ensurePrimitivesAreInDataset();
         // Make copy and remove all references (to prevent inconsistent dataset (delete referenced) while command is executed)
         for (OsmPrimitive osm: toDelete) {
@@ -190,4 +191,6 @@
     @Override
     public void undoCommand() {
+        ensurePrimitivesAreInDataset();
+
         for (OsmPrimitive osm: toDelete) {
             osm.setDeleted(false);
Index: trunk/src/org/openstreetmap/josm/command/MoveCommand.java
===================================================================
--- trunk/src/org/openstreetmap/josm/command/MoveCommand.java	(revision 12347)
+++ trunk/src/org/openstreetmap/josm/command/MoveCommand.java	(revision 12348)
@@ -207,4 +207,6 @@
     @Override
     public boolean executeCommand() {
+        ensurePrimitivesAreInDataset();
+
         for (Node n : nodes) {
             // in case #3892 happens again
@@ -222,4 +224,6 @@
     @Override
     public void undoCommand() {
+        ensurePrimitivesAreInDataset();
+
         Iterator<OldNodeState> it = oldState.iterator();
         for (Node n : nodes) {
