Changeset 18433 in josm for trunk


Ignore:
Timestamp:
2022-04-19T22:29:22+02:00 (3 years ago)
Author:
taylor.smock
Message:

Fix #22024: DataIntegrityProblemException during data upload

This is caused by a race condition between the upload methods and updates to
the relation editor. If the upload takes long enough, the user can cause an
update to the relation editor, which can trigger the problem.

This works around the problem by returning the original relation when the
dataset is locked. This keeps compatibility with the interface method javadocs.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/dialogs/relation/actions/IRelationEditorActionAccess.java

    r18413 r18433  
    7575    default IRelation<?> getChangedRelation() {
    7676        final Relation newRelation;
    77         if (getEditor().getRelation() != null) {
    78             newRelation = new Relation(getEditor().getRelation());
     77        final Relation oldRelation = getEditor().getRelation();
     78        if (oldRelation != null && oldRelation.getDataSet() != null && oldRelation.getDataSet().isLocked()) {
     79            // If the dataset is locked, then we cannot change the relation. See JOSM #22024.
     80            // This is due to the `setMembers` -> `addReferrer` call chain requires that the dataset is not read only.
     81            return oldRelation;
     82        } else if (oldRelation != null) {
     83            newRelation = new Relation(oldRelation);
    7984        } else {
    8085            newRelation = new Relation();
  • trunk/test/unit/org/openstreetmap/josm/gui/dialogs/relation/actions/RelationEditorActionsTest.java

    r17275 r18433  
    22package org.openstreetmap.josm.gui.dialogs.relation.actions;
    33
     4import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
    45import static org.junit.jupiter.api.Assertions.assertEquals;
    56import static org.junit.jupiter.api.Assertions.assertTrue;
     
    1415import org.junit.jupiter.api.Test;
    1516import org.openstreetmap.josm.TestUtils;
     17import org.openstreetmap.josm.data.coor.LatLon;
     18import org.openstreetmap.josm.data.osm.DataSet;
     19import org.openstreetmap.josm.data.osm.Node;
     20import org.openstreetmap.josm.data.osm.Relation;
     21import org.openstreetmap.josm.data.osm.RelationMember;
    1622import org.openstreetmap.josm.gui.ConditionalOptionPaneUtil;
     23import org.openstreetmap.josm.gui.MainApplication;
     24import org.openstreetmap.josm.gui.layer.OsmDataLayer;
    1725import org.openstreetmap.josm.testutils.mockers.JOptionPaneSimpleMocker;
    1826
     
    142150        assertTrue(jopMockerCalled[0]);
    143151    }
     152
     153    /**
     154     * Non-regression test for JOSM #22024.
     155     * This is due to a race condition between uploading and refreshing the relation in the editor.
     156     */
     157    @Test
     158    void testNonRegression22024() {
     159        final DataSet ds = new DataSet();
     160        final Node node = new Node(LatLon.ZERO);
     161        Relation relation = TestUtils.newRelation("type=restriction", new RelationMember("", node));
     162        ds.addPrimitive(node);
     163        ds.addPrimitive(relation);
     164        MainApplication.getLayerManager().prepareLayerForUpload(new OsmDataLayer(ds, "testNonRegression22024", null));
     165        // Sanity check that behavior hasn't changed
     166        assertTrue(ds.isLocked(), "The dataset should be locked when it is being uploaded.");
     167        relationEditorAccess.getEditor().setRelation(relation);
     168        relationEditorAccess.getMemberTableModel().populate(relation);
     169        relationEditorAccess.getTagModel().initFromPrimitive(relation);
     170        relationEditorAccess.getEditor().reloadDataFromRelation();
     171        assertDoesNotThrow(relationEditorAccess::getChangedRelation);
     172    }
    144173}
Note: See TracChangeset for help on using the changeset viewer.