Index: /trunk/src/org/openstreetmap/josm/actions/AlignInLineAction.java
===================================================================
--- /trunk/src/org/openstreetmap/josm/actions/AlignInLineAction.java	(revision 13107)
+++ /trunk/src/org/openstreetmap/josm/actions/AlignInLineAction.java	(revision 13108)
@@ -173,5 +173,8 @@
 
         try {
-            MainApplication.undoRedo.add(buildCommand());
+            Command cmd = buildCommand(getLayerManager().getEditDataSet());
+            if (cmd != null) {
+                MainApplication.undoRedo.add(cmd);
+            }
         } catch (InvalidSelection except) {
             Logging.debug(except);
@@ -184,10 +187,10 @@
     /**
      * Builds "align in line" command depending on the selected objects.
+     * @param ds data set in which the command operates
      * @return the resulting command to execute to perform action
      * @throws InvalidSelection if a polygon is selected, or if a node is used by 3 or more ways
-     * @since 12562
-     */
-    public Command buildCommand() throws InvalidSelection {
-        DataSet ds = getLayerManager().getEditDataSet();
+     * @since 13108
+     */
+    public Command buildCommand(DataSet ds) throws InvalidSelection {
         List<Node> selectedNodes = new ArrayList<>(ds.getSelectedNodes());
         List<Way> selectedWays = new ArrayList<>(ds.getSelectedWays());
@@ -276,5 +279,5 @@
                 throw new InvalidSelection(tr("Intersection of three or more ways can not be solved. Abort."));
         }
-        return new SequenceCommand(tr("Align Nodes in Line"), cmds);
+        return cmds.isEmpty() ? null : new SequenceCommand(tr("Align Nodes in Line"), cmds);
     }
 
Index: /trunk/test/unit/org/openstreetmap/josm/actions/AlignInLineActionTest.java
===================================================================
--- /trunk/test/unit/org/openstreetmap/josm/actions/AlignInLineActionTest.java	(revision 13107)
+++ /trunk/test/unit/org/openstreetmap/josm/actions/AlignInLineActionTest.java	(revision 13108)
@@ -4,4 +4,5 @@
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
 
 import org.junit.Before;
@@ -16,5 +17,4 @@
 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;
 
@@ -56,5 +56,4 @@
     public void testNodesOpenWay() throws InvalidSelection {
         DataSet dataSet = new DataSet();
-        OsmDataLayer layer = new OsmDataLayer(dataSet, OsmDataLayer.createNewName(), null);
 
         // Create test points, lower left is (0,0).
@@ -67,18 +66,11 @@
         Node point3 = new Node(new EastNorth(1, 1));
 
-        try {
-            MainApplication.getLayerManager().addLayer(layer);
-
-            // Create an open way.
-            createWay(dataSet, point1, point2, point3);
-
-            // Select nodes to align.
-            dataSet.addSelected(point1, point2, point3);
-
-            action.buildCommand().executeCommand();
-        } finally {
-            // Ensure we clean the place before leaving, even if test fails.
-            MainApplication.getLayerManager().removeLayer(layer);
-        }
+        // Create an open way.
+        createWay(dataSet, point1, point2, point3);
+
+        // Select nodes to align.
+        dataSet.addSelected(point1, point2, point3);
+
+        action.buildCommand(dataSet).executeCommand();
 
         // Points 1 and 3 are the extremities and must not have moved. Only point 2 must have moved.
@@ -96,5 +88,4 @@
     public void testNodesClosedWay() throws InvalidSelection {
         DataSet dataSet = new DataSet();
-        OsmDataLayer layer = new OsmDataLayer(dataSet, OsmDataLayer.createNewName(), null);
 
         // Create test points, lower left is (0,0).
@@ -108,17 +99,10 @@
         Node point4 = new Node(new EastNorth(0, 2));
 
-        try {
-            MainApplication.getLayerManager().addLayer(layer);
-
-            // Create a closed way.
-            createWay(dataSet, point1, point2, point3, point4, point1);
-            // Select nodes to align (point1 must be in the second position to exhibit the bug).
-            dataSet.addSelected(point4, point1, point2);
-
-            action.buildCommand().executeCommand();
-        } finally {
-            // Ensure we clean the place before leaving, even if test fails.
-            MainApplication.getLayerManager().removeLayer(layer);
-        }
+        // Create a closed way.
+        createWay(dataSet, point1, point2, point3, point4, point1);
+        // Select nodes to align (point1 must be in the second position to exhibit the bug).
+        dataSet.addSelected(point4, point1, point2);
+
+        action.buildCommand(dataSet).executeCommand();
 
         // Only point 1 must have moved.
@@ -137,5 +121,4 @@
     public void testNodesOpenWays() throws InvalidSelection {
         DataSet dataSet = new DataSet();
-        OsmDataLayer layer = new OsmDataLayer(dataSet, OsmDataLayer.createNewName(), null);
 
         // Create test points, lower left is (0,0).
@@ -149,20 +132,13 @@
         Node point4 = new Node(new EastNorth(2, 0));
 
-        try {
-            MainApplication.getLayerManager().addLayer(layer);
-
-            // Create 2 ways.
-            createWay(dataSet, point1, point2);
-            createWay(dataSet, point3, point4);
-
-            // Select nodes to align.
-            dataSet.addSelected(point1, point2, point3, point4);
-
-            // Points must align between points 1 and 4.
-            action.buildCommand().executeCommand();
-        } finally {
-            // Ensure we clean the place before leaving, even if test fails.
-            MainApplication.getLayerManager().removeLayer(layer);
-        }
+        // Create 2 ways.
+        createWay(dataSet, point1, point2);
+        createWay(dataSet, point3, point4);
+
+        // Select nodes to align.
+        dataSet.addSelected(point1, point2, point3, point4);
+
+        // Points must align between points 1 and 4.
+        action.buildCommand(dataSet).executeCommand();
 
         assertCoordEq(point1, 0, 2);
@@ -173,10 +149,33 @@
 
     /**
+     * Test case: only a two-nodes way selected.
+     * @throws InvalidSelection never
+     */
+    @Test
+    public void testSimpleWay() throws InvalidSelection {
+        DataSet dataSet = new DataSet();
+
+        // Create test points, lower left is (0,0).
+        //
+        // 1 - -
+        // - - 2
+        Node point1 = new Node(new EastNorth(0, 2));
+        Node point2 = new Node(new EastNorth(2, 1));
+
+        // Creates and select a single way.
+        dataSet.addSelected(createWay(dataSet, point1, point2));
+
+        // No command must be created (nothing to do)
+        assertNull(action.buildCommand(dataSet));
+    }
+
+    /**
      * Create a way made of the provided nodes and select nodes.
      *
      * @param dataSet Dataset in which adding nodes.
      * @param nodes List of nodes to add to dataset.
-     */
-    private void createWay(DataSet dataSet, Node... nodes) {
+     * @return created way
+     */
+    private Way createWay(DataSet dataSet, Node... nodes) {
         Way way = new Way();
         dataSet.addPrimitive(way);
@@ -189,4 +188,5 @@
             way.addNode(node);
         }
+        return way;
     }
 
