Fix an NPE when a dupe node is deleted

Signed-off-by: Taylor Smock <taylor.smock@kaart.com>
pull/1/head v1.1.3
Taylor Smock 2020-01-16 10:00:52 -07:00
rodzic b79de5274f
commit 96ebe5ed98
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 625F6A74A3E4311A
2 zmienionych plików z 18 dodań i 4 usunięć

Wyświetl plik

@ -35,7 +35,7 @@ public class DuplicateCommand extends AbstractConflationCommand {
}
final List<Command> commands = new ArrayList<>();
if (primitiveConnections[0] instanceof Node) {
if (primitiveConnections[0] instanceof Node && !primitiveConnections[0].isDeleted()) {
final Node replaceNode = (Node) primitiveConnections[0];
final Command tCommand = replaceNode(node, replaceNode);
if (tCommand != null) {
@ -50,6 +50,9 @@ public class DuplicateCommand extends AbstractConflationCommand {
}
}
}
if (commands.isEmpty()) {
commands.add(new ChangePropertyCommand(node, KEY, null));
}
return commands;
}
@ -92,9 +95,6 @@ public class DuplicateCommand extends AbstractConflationCommand {
List<Command> tCommands = duplicateNode(getAffectedDataSet(), tNode);
// We have to execute the command to avoid duplicating the command later. Undo
// occurs later, so that the state doesn't actually change.
if (tCommands.isEmpty()) {
tCommands.add(new ChangePropertyCommand(tNode, KEY, null));
}
tCommands.forEach(Command::executeCommand);
commands.addAll(tCommands);
}

Wyświetl plik

@ -10,6 +10,7 @@ import java.util.Collections;
import org.junit.Rule;
import org.junit.Test;
import org.openstreetmap.josm.command.Command;
import org.openstreetmap.josm.command.DeleteCommand;
import org.openstreetmap.josm.data.coor.LatLon;
import org.openstreetmap.josm.data.osm.DataSet;
import org.openstreetmap.josm.data.osm.Node;
@ -49,6 +50,19 @@ public class DuplicateCommandTest {
assertTrue(dupe1.hasKey(dupe.getKey()));
assertFalse(dupe2.hasKey(dupe.getKey()));
Command deleteDupe2 = DeleteCommand.delete(Collections.singleton(dupe2));
deleteDupe2.executeCommand();
command = dupe.getCommand(Collections.singleton(dupe1));
command.executeCommand();
assertFalse(dupe1.isDeleted());
assertTrue(dupe2.isDeleted());
assertFalse(dupe1.hasKey(dupe.getKey()));
command.undoCommand();
assertFalse(dupe1.isDeleted());
assertTrue(dupe1.hasKey(dupe.getKey()));
assertFalse(dupe2.hasKey(dupe.getKey()));
deleteDupe2.undoCommand();
dupe1.setCoor(new LatLon(1, 1));
command = dupe.getCommand(Collections.singleton(dupe1));