Index: /trunk/src/org/openstreetmap/josm/gui/dialogs/CommandStackDialog.java
===================================================================
--- /trunk/src/org/openstreetmap/josm/gui/dialogs/CommandStackDialog.java	(revision 17771)
+++ /trunk/src/org/openstreetmap/josm/gui/dialogs/CommandStackDialog.java	(revision 17772)
@@ -347,9 +347,8 @@
     /**
      * Return primitives that are affected by some command
-     * @param path GUI elements
-     * @return collection of affected primitives, onluy usable ones
-     */
-    protected static Collection<? extends OsmPrimitive> getAffectedPrimitives(TreePath path) {
-        PseudoCommand c = ((CommandListMutableTreeNode) path.getLastPathComponent()).getCommand();
+     * @param c the command
+     * @return collection of affected primitives, only usable ones
+     */
+    protected static Collection<? extends OsmPrimitive> getAffectedPrimitives(PseudoCommand c) {
         final OsmDataLayer currentLayer = MainApplication.getLayerManager().getEditLayer();
         return new SubclassFilteredCollection<>(
@@ -425,11 +424,6 @@
         @Override
         public void actionPerformed(ActionEvent e) {
-            TreePath path;
-            if (!undoTree.isSelectionEmpty()) {
-                path = undoTree.getSelectionPath();
-            } else if (!redoTree.isSelectionEmpty()) {
-                path = redoTree.getSelectionPath();
-            } else {
-                // see #19514 for a possible cause
+            PseudoCommand command = getSelectedCommand();
+            if (command == null) {
                 return;
             }
@@ -437,5 +431,5 @@
             DataSet dataSet = MainApplication.getLayerManager().getEditDataSet();
             if (dataSet == null) return;
-            dataSet.setSelected(getAffectedPrimitives(path));
+            dataSet.setSelected(getAffectedPrimitives(command));
         }
 
@@ -444,4 +438,21 @@
             setEnabled(!undoTree.isSelectionEmpty() || !redoTree.isSelectionEmpty());
         }
+    }
+
+    /**
+     * Returns the selected undo/redo command
+     * @return the selected undo/redo command or {@code null}
+     */
+    public PseudoCommand getSelectedCommand() {
+        TreePath path;
+        if (!undoTree.isSelectionEmpty()) {
+            path = undoTree.getSelectionPath();
+        } else if (!redoTree.isSelectionEmpty()) {
+            path = redoTree.getSelectionPath();
+        } else {
+            // see #19514 for a possible cause
+            return null;
+        }
+        return path != null ? ((CommandListMutableTreeNode) path.getLastPathComponent()).getCommand() : null;
     }
 
