Index: /trunk/src/org/openstreetmap/josm/gui/dialogs/relation/actions/IRelationEditorActionAccess.java
===================================================================
--- /trunk/src/org/openstreetmap/josm/gui/dialogs/relation/actions/IRelationEditorActionAccess.java	(revision 18432)
+++ /trunk/src/org/openstreetmap/josm/gui/dialogs/relation/actions/IRelationEditorActionAccess.java	(revision 18433)
@@ -75,6 +75,11 @@
     default IRelation<?> getChangedRelation() {
         final Relation newRelation;
-        if (getEditor().getRelation() != null) {
-            newRelation = new Relation(getEditor().getRelation());
+        final Relation oldRelation = getEditor().getRelation();
+        if (oldRelation != null && oldRelation.getDataSet() != null && oldRelation.getDataSet().isLocked()) {
+            // If the dataset is locked, then we cannot change the relation. See JOSM #22024.
+            // This is due to the `setMembers` -> `addReferrer` call chain requires that the dataset is not read only.
+            return oldRelation;
+        } else if (oldRelation != null) {
+            newRelation = new Relation(oldRelation);
         } else {
             newRelation = new Relation();
Index: /trunk/test/unit/org/openstreetmap/josm/gui/dialogs/relation/actions/RelationEditorActionsTest.java
===================================================================
--- /trunk/test/unit/org/openstreetmap/josm/gui/dialogs/relation/actions/RelationEditorActionsTest.java	(revision 18432)
+++ /trunk/test/unit/org/openstreetmap/josm/gui/dialogs/relation/actions/RelationEditorActionsTest.java	(revision 18433)
@@ -2,4 +2,5 @@
 package org.openstreetmap.josm.gui.dialogs.relation.actions;
 
+import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
 import static org.junit.jupiter.api.Assertions.assertEquals;
 import static org.junit.jupiter.api.Assertions.assertTrue;
@@ -14,5 +15,12 @@
 import org.junit.jupiter.api.Test;
 import org.openstreetmap.josm.TestUtils;
+import org.openstreetmap.josm.data.coor.LatLon;
+import org.openstreetmap.josm.data.osm.DataSet;
+import org.openstreetmap.josm.data.osm.Node;
+import org.openstreetmap.josm.data.osm.Relation;
+import org.openstreetmap.josm.data.osm.RelationMember;
 import org.openstreetmap.josm.gui.ConditionalOptionPaneUtil;
+import org.openstreetmap.josm.gui.MainApplication;
+import org.openstreetmap.josm.gui.layer.OsmDataLayer;
 import org.openstreetmap.josm.testutils.mockers.JOptionPaneSimpleMocker;
 
@@ -142,3 +150,24 @@
         assertTrue(jopMockerCalled[0]);
     }
+
+    /**
+     * Non-regression test for JOSM #22024.
+     * This is due to a race condition between uploading and refreshing the relation in the editor.
+     */
+    @Test
+    void testNonRegression22024() {
+        final DataSet ds = new DataSet();
+        final Node node = new Node(LatLon.ZERO);
+        Relation relation = TestUtils.newRelation("type=restriction", new RelationMember("", node));
+        ds.addPrimitive(node);
+        ds.addPrimitive(relation);
+        MainApplication.getLayerManager().prepareLayerForUpload(new OsmDataLayer(ds, "testNonRegression22024", null));
+        // Sanity check that behavior hasn't changed
+        assertTrue(ds.isLocked(), "The dataset should be locked when it is being uploaded.");
+        relationEditorAccess.getEditor().setRelation(relation);
+        relationEditorAccess.getMemberTableModel().populate(relation);
+        relationEditorAccess.getTagModel().initFromPrimitive(relation);
+        relationEditorAccess.getEditor().reloadDataFromRelation();
+        assertDoesNotThrow(relationEditorAccess::getChangedRelation);
+    }
 }
