Changeset 12348 in josm for trunk


Ignore:
Timestamp:
2017-06-08T23:41:02+02:00 (7 years ago)
Author:
michael2402
Message:

See #13036: Add more consistency checks to move / delete command.

Location:
trunk/src/org/openstreetmap/josm/command
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/command/Command.java

    r11243 r12348  
    338338    }
    339339
     340    /**
     341     * Ensures that all primitives that are participating in this command belong to the affected data set.
     342     *
     343     * Commands may use this in their update methods to check the consitency of the primitives they operate on.
     344     * @throws AssertionError if no {@link DataSet} is set or if any primitive does not belong to that dataset.
     345     */
     346    protected void ensurePrimitivesAreInDataset() {
     347        for (OsmPrimitive primitive : this.getParticipatingPrimitives()) {
     348            if (primitive.getDataSet() != this.getAffectedDataSet()) {
     349                throw new AssertionError("Primitive is of wrong data set for this command: " + primitive);
     350            }
     351        }
     352    }
     353
    340354    @Override
    341355    public int hashCode() {
  • trunk/src/org/openstreetmap/josm/command/DeleteCommand.java

    r11590 r12348  
    168168    @Override
    169169    public boolean executeCommand() {
     170        ensurePrimitivesAreInDataset();
    170171        // Make copy and remove all references (to prevent inconsistent dataset (delete referenced) while command is executed)
    171172        for (OsmPrimitive osm: toDelete) {
     
    190191    @Override
    191192    public void undoCommand() {
     193        ensurePrimitivesAreInDataset();
     194
    192195        for (OsmPrimitive osm: toDelete) {
    193196            osm.setDeleted(false);
  • trunk/src/org/openstreetmap/josm/command/MoveCommand.java

    r11070 r12348  
    207207    @Override
    208208    public boolean executeCommand() {
     209        ensurePrimitivesAreInDataset();
     210
    209211        for (Node n : nodes) {
    210212            // in case #3892 happens again
     
    222224    @Override
    223225    public void undoCommand() {
     226        ensurePrimitivesAreInDataset();
     227
    224228        Iterator<OldNodeState> it = oldState.iterator();
    225229        for (Node n : nodes) {
Note: See TracChangeset for help on using the changeset viewer.