Index: trunk/src/org/openstreetmap/josm/actions/mapmode/ExtrudeAction.java
===================================================================
--- trunk/src/org/openstreetmap/josm/actions/mapmode/ExtrudeAction.java	(revision 18986)
+++ trunk/src/org/openstreetmap/josm/actions/mapmode/ExtrudeAction.java	(revision 18987)
@@ -39,5 +39,4 @@
 import org.openstreetmap.josm.data.coor.EastNorth;
 import org.openstreetmap.josm.data.coor.ILatLon;
-import org.openstreetmap.josm.data.osm.DataIntegrityProblemException;
 import org.openstreetmap.josm.data.osm.DataSet;
 import org.openstreetmap.josm.data.osm.Node;
@@ -82,4 +81,5 @@
     private transient WaySegment selectedSegment;
     private transient Node selectedNode;
+    private transient Command lastCommandOnUndoStack;
     private Color mainColor;
     private transient Stroke mainStroke;
@@ -332,4 +332,5 @@
         this.selectedNode = null;
         this.selectedSegment = null;
+        this.lastCommandOnUndoStack = null;
         super.exitMode();
     }
@@ -402,4 +403,5 @@
         // If nothing gets caught, stay in select mode
         if (selectedSegment == null && selectedNode == null) return;
+        lastCommandOnUndoStack = UndoRedoHandler.getInstance().getLastCommand();
 
         if (selectedNode != null) {
@@ -546,11 +548,6 @@
                     addNewNode(e);
                 } else if (e.getPoint().distance(initialMousePos) > initialMoveThreshold && newN1en != null && selectedSegment != null) {
-                    try {
-                        // main extrusion commands
-                        performExtrusion();
-                    } catch (DataIntegrityProblemException ex) {
-                        // Can occur if calling undo while extruding, see #12870
-                        Logging.error(ex);
-                    }
+                    // main extrusion commands
+                    performExtrusion();
                 }
             } else if (mode == Mode.translate || mode == Mode.translate_node) {
@@ -567,4 +564,5 @@
             mapView.removeTemporaryLayer(this);
             selectedSegment = null;
+            lastCommandOnUndoStack = null;
             moveCommand = null;
             mode = Mode.select;
@@ -639,5 +637,11 @@
      */
     private void performExtrusion() {
+        // sanity checks, see #23447 and #12870: don't try to extrude when user pressed undo
+        if (lastCommandOnUndoStack != UndoRedoHandler.getInstance().getLastCommand())
+            return;
         DataSet ds = getLayerManager().getEditDataSet();
+        if (ds.getPrimitiveById(selectedSegment.getWay()) == null || !selectedSegment.isUsable())
+            return;
+
         // create extrusion
         Collection<Command> cmds = new LinkedList<>();
