Index: trunk/src/org/openstreetmap/josm/actions/JoinAreasAction.java
===================================================================
--- trunk/src/org/openstreetmap/josm/actions/JoinAreasAction.java	(revision 12726)
+++ trunk/src/org/openstreetmap/josm/actions/JoinAreasAction.java	(revision 12728)
@@ -61,4 +61,5 @@
     private final transient LinkedList<Command> cmds = new LinkedList<>();
     private int cmdsCount;
+    private DataSet ds;
     private final transient List<Relation> addedRelations = new LinkedList<>();
 
@@ -538,5 +539,5 @@
             // retrieve effective dataset before joining the ways (which affects the selection, thus, the <ways> collection)
             // Dataset retrieving allows to call this code without relying on Main.getCurrentDataSet(), thus, on a mapview instance
-            DataSet ds = ways.iterator().next().getDataSet();
+            ds = ways.iterator().next().getDataSet();
 
             // Do the job of joining areas
@@ -1539,4 +1540,5 @@
 
         Relation newRel;
+        RelationRole soleOuter;
         switch (multiouters.size()) {
         case 0:
@@ -1544,7 +1546,8 @@
         case 1:
             // Found only one to be part of a multipolygon relation, so just add it back as well
-            newRel = new Relation(multiouters.get(0).rel);
-            newRel.addMember(new RelationMember(multiouters.get(0).role, outer));
-            cmds.add(new ChangeCommand(multiouters.get(0).rel, newRel));
+            soleOuter = multiouters.get(0);
+            newRel = new Relation(soleOuter.rel);
+            newRel.addMember(new RelationMember(soleOuter.role, outer));
+            cmds.add(new ChangeCommand(ds, soleOuter.rel, newRel));
             return;
         default:
@@ -1566,5 +1569,5 @@
             }
             newRel.addMember(new RelationMember("outer", outer));
-            cmds.add(new AddCommand(outer.getDataSet(), newRel));
+            cmds.add(new AddCommand(ds, newRel));
         }
     }
