Index: /trunk/src/org/openstreetmap/josm/io/session/OsmDataSessionExporter.java
===================================================================
--- /trunk/src/org/openstreetmap/josm/io/session/OsmDataSessionExporter.java	(revision 7069)
+++ /trunk/src/org/openstreetmap/josm/io/session/OsmDataSessionExporter.java	(revision 7070)
@@ -56,7 +56,4 @@
     }
 
-    public OsmDataSessionExporter() {
-    }
-
     @Override
     public Collection<Layer> getDependencies() {
Index: /trunk/src/org/openstreetmap/josm/io/session/SessionWriter.java
===================================================================
--- /trunk/src/org/openstreetmap/josm/io/session/SessionWriter.java	(revision 7069)
+++ /trunk/src/org/openstreetmap/josm/io/session/SessionWriter.java	(revision 7070)
@@ -28,8 +28,4 @@
 import javax.xml.transform.stream.StreamResult;
 
-import org.w3c.dom.Document;
-import org.w3c.dom.Element;
-import org.w3c.dom.Text;
-
 import org.openstreetmap.josm.Main;
 import org.openstreetmap.josm.data.coor.EastNorth;
@@ -45,4 +41,7 @@
 import org.openstreetmap.josm.tools.MultiMap;
 import org.openstreetmap.josm.tools.Utils;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.Text;
 
 public class SessionWriter {
@@ -80,5 +79,5 @@
 
     private final List<Layer> layers;
-    private final int active; 
+    private final int active;
     private final Map<Layer, SessionLayerExporter> exporters;
     private final MultiMap<Layer, Layer> dependencies;
@@ -91,5 +90,5 @@
      * @param layers The ordered list of layers to save
      * @param active The index of active layer in {@code layers} (starts to 0). Ignored if set to -1
-     * @param exporters The exprters to use to save layers
+     * @param exporters The exporters to use to save layers
      * @param zip {@code true} if a joz archive has to be created, {@code false otherwise}
      * @since 6271
@@ -208,5 +207,5 @@
             }
             Set<Layer> deps = dependencies.get(layer);
-            if (!deps.isEmpty()) {
+            if (deps != null && !deps.isEmpty()) {
                 List<Integer> depsInt = new ArrayList<>();
                 for (Layer depLayer : deps) {
@@ -247,5 +246,5 @@
     }
 
-    public void write (OutputStream out) throws IOException {
+    public void write(OutputStream out) throws IOException {
         if (zip) {
             zipOut = new ZipOutputStream(new BufferedOutputStream(out));
Index: /trunk/test/unit/org/openstreetmap/josm/io/session/SessionWriterTest.java
===================================================================
--- /trunk/test/unit/org/openstreetmap/josm/io/session/SessionWriterTest.java	(revision 7070)
+++ /trunk/test/unit/org/openstreetmap/josm/io/session/SessionWriterTest.java	(revision 7070)
@@ -0,0 +1,170 @@
+// License: GPL. For details, see LICENSE file.
+package org.openstreetmap.josm.io.session;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.openstreetmap.josm.Main;
+import org.openstreetmap.josm.data.gpx.GpxData;
+import org.openstreetmap.josm.data.osm.DataSet;
+import org.openstreetmap.josm.gui.MainApplication;
+import org.openstreetmap.josm.gui.layer.GpxLayer;
+import org.openstreetmap.josm.gui.layer.Layer;
+import org.openstreetmap.josm.gui.layer.OsmDataLayer;
+import org.openstreetmap.josm.tools.MultiMap;
+
+/**
+ * Unit tests for Session writing.
+ */
+public class SessionWriterTest {
+
+    private static class OsmHeadlessJosExporter extends OsmDataSessionExporter {
+        public OsmHeadlessJosExporter(OsmDataLayer layer) {
+            super(layer);
+        }
+        @Override
+        public boolean requiresZip() {
+            return false;
+        }
+    }
+
+    private static class OsmHeadlessJozExporter extends OsmDataSessionExporter {
+        public OsmHeadlessJozExporter(OsmDataLayer layer) {
+            super(layer);
+        }
+        @Override
+        public boolean requiresZip() {
+            return true;
+        }
+    }
+
+    private static class GpxHeadlessJosExporter extends GpxTracksSessionExporter {
+        public GpxHeadlessJosExporter(GpxLayer layer) {
+            super(layer);
+        }
+
+        @Override
+        public boolean requiresZip() {
+            return false;
+        }
+    }
+
+    private static class GpxHeadlessJozExporter extends GpxTracksSessionExporter {
+        public GpxHeadlessJozExporter(GpxLayer layer) {
+            super(layer);
+        }
+
+        @Override
+        public boolean requiresZip() {
+            return true;
+        }
+    }
+
+    /**
+     * Setup tests.
+     */
+    @BeforeClass
+    public static void setUpBeforeClass() {
+        Main.initApplicationPreferences();
+        Main.determinePlatformHook();
+        Main.preConstructorInit(new HashMap<MainApplication.Option, Collection<String>>());
+        new MainApplication();
+        Main.main.createMapFrame(null, null);
+    }
+
+    private void testWrite(List<Layer> layers, final boolean zip) throws IOException {
+        Map<Layer, SessionLayerExporter> exporters = new HashMap<>();
+        if (zip) {
+            SessionWriter.registerSessionLayerExporter(OsmDataLayer.class, OsmHeadlessJozExporter.class);
+            SessionWriter.registerSessionLayerExporter(GpxLayer.class, GpxHeadlessJozExporter.class);
+        } else {
+            SessionWriter.registerSessionLayerExporter(OsmDataLayer.class, OsmHeadlessJosExporter.class);
+            SessionWriter.registerSessionLayerExporter(GpxLayer.class, GpxHeadlessJosExporter.class);
+        }
+        for (final Layer l : layers) {
+            exporters.put(l, SessionWriter.getSessionLayerExporter(l));
+        }
+        SessionWriter sw = new SessionWriter(layers, -1, exporters, new MultiMap<Layer, Layer>(), zip);
+        File file = new File(System.getProperty("java.io.tmpdir"), getClass().getName()+(zip?".joz":".jos"));
+        try {
+            sw.write(file);
+        } finally {
+            if (file.exists()) {
+                file.delete();
+            }
+        }
+    }
+
+    private OsmDataLayer createOsmLayer() {
+        OsmDataLayer layer = new OsmDataLayer(new DataSet(), null, null);
+        layer.setAssociatedFile(new File("data.osm"));
+        return layer;
+    }
+
+    private GpxLayer createGpxLayer() {
+        GpxLayer layer = new GpxLayer(new GpxData());
+        layer.setAssociatedFile(new File("data.gpx"));
+        return layer;
+    }
+
+    /**
+     * Tests to write an empty .jos file.
+     * @throws IOException if any I/O error occurs
+     */
+    @Test
+    public void testWriteEmptyJos() throws IOException {
+        testWrite(Collections.<Layer>emptyList(), false);
+    }
+
+    /**
+     * Tests to write an empty .joz file.
+     * @throws IOException if any I/O error occurs
+     */
+    @Test
+    public void testWriteEmptyJoz() throws IOException {
+        testWrite(Collections.<Layer>emptyList(), true);
+    }
+
+    /**
+     * Tests to write a .jos file containing OSM data.
+     * @throws IOException if any I/O error occurs
+     */
+    @Test
+    public void testWriteOsmJos() throws IOException {
+        testWrite(Collections.<Layer>singletonList(createOsmLayer()), false);
+    }
+
+    /**
+     * Tests to write a .joz file containing OSM data.
+     * @throws IOException if any I/O error occurs
+     */
+    @Test
+    public void testWriteOsmJoz() throws IOException {
+        testWrite(Collections.<Layer>singletonList(createOsmLayer()), true);
+    }
+
+    /**
+     * Tests to write a .jos file containing GPX data.
+     * @throws IOException if any I/O error occurs
+     */
+    @Test
+    public void testWriteGpxJos() throws IOException {
+        testWrite(Collections.<Layer>singletonList(createGpxLayer()), false);
+    }
+
+    /**
+     * Tests to write a .joz file containing GPX data.
+     * @throws IOException if any I/O error occurs
+     */
+    @Test
+    public void testWriteGpxJoz() throws IOException {
+        testWrite(Collections.<Layer>singletonList(createGpxLayer()), true);
+    }
+}
