Index: trunk/src/org/openstreetmap/josm/actions/JoinAreasAction.java
===================================================================
--- trunk/src/org/openstreetmap/josm/actions/JoinAreasAction.java	(revision 13015)
+++ trunk/src/org/openstreetmap/josm/actions/JoinAreasAction.java	(revision 13016)
@@ -109,5 +109,5 @@
          */
         public Multipolygon(Way way) {
-            outerWay = way;
+            outerWay = Objects.requireNonNull(way, "way");
             innerWays = new ArrayList<>();
         }
@@ -536,9 +536,4 @@
 
         try {
-            // see #11026 - Because <ways> is a dynamic filtered (on ways) of a filtered (on selected objects) collection,
-            // 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
-            ds = ways.iterator().next().getDataSet();
-
             // Do the job of joining areas
             JoinAreasResult result = joinAreas(areas);
@@ -601,4 +596,11 @@
      */
     public JoinAreasResult joinAreas(List<Multipolygon> areas) throws UserCancelException {
+
+        // see #11026 - Because <ways> is a dynamic filtered (on ways) of a filtered (on selected objects) collection,
+        // 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
+        if (!areas.isEmpty()) {
+            ds = areas.iterator().next().getOuterWay().getDataSet();
+        }
 
         boolean hasChanges = false;
