Changeset 14662 in josm


Ignore:
Timestamp:
2019-01-07T19:46:32+01:00 (13 days ago)
Author:
simon04
Message:

see #16874 fix #17180 - NPE in UnGlueAction

Location:
trunk/src/org/openstreetmap/josm
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/actions/UnGlueAction.java

    r14654 r14662  
    178178
    179179    static void update(PropertiesMembershipChoiceDialog dialog, Node existingNode, List<Node> newNodes, Collection<Command> cmds) {
    180         updateMemberships(dialog.getMemberships(), existingNode, newNodes, cmds);
    181         updateProperties(dialog.getTags(), existingNode, newNodes, cmds);
     180        updateMemberships(dialog.getMemberships().orElse(null), existingNode, newNodes, cmds);
     181        updateProperties(dialog.getTags().orElse(null), existingNode, newNodes, cmds);
    182182    }
    183183
     
    213213        List<Command> cmds = new LinkedList<>();
    214214        cmds.add(new AddCommand(selectedNode.getDataSet(), unglued));
    215         if (dialog != null && ExistingBothNew.NEW.equals(dialog.getTags())) {
     215        if (dialog != null && ExistingBothNew.NEW.equals(dialog.getTags().orElse(null))) {
    216216            // unglued node gets the ID and history, thus replace way node with a fresh one
    217217            final Way way = selectedNode.getParentWays().get(0);
     
    219219            newWayNodes.replaceAll(n -> selectedNode.equals(n) ? unglued : n);
    220220            cmds.add(new ChangeNodesCommand(way, newWayNodes));
    221             updateMemberships(dialog.getMemberships().opposite(), selectedNode, Collections.singletonList(unglued), cmds);
    222             updateProperties(dialog.getTags().opposite(), selectedNode, Collections.singletonList(unglued), cmds);
     221            updateMemberships(dialog.getMemberships().map(ExistingBothNew::opposite).orElse(null),
     222                    selectedNode, Collections.singletonList(unglued), cmds);
     223            updateProperties(dialog.getTags().map(ExistingBothNew::opposite).orElse(null),
     224                    selectedNode, Collections.singletonList(unglued), cmds);
    223225            moveSelectedNode = true;
    224226        } else if (dialog != null) {
     
    386388     */
    387389    private static void updateMemberships(ExistingBothNew memberships, Node originalNode, List<Node> newNodes, Collection<Command> cmds) {
    388         if (ExistingBothNew.OLD.equals(memberships)) {
     390        if (memberships == null || ExistingBothNew.OLD.equals(memberships)) {
    389391            return;
    390392        }
  • trunk/src/org/openstreetmap/josm/gui/dialogs/PropertiesMembershipChoiceDialog.java

    r14654 r14662  
    77import java.util.Collection;
    88import java.util.Objects;
     9import java.util.Optional;
    910
    1011import javax.swing.AbstractButton;
     
    113114    /**
    114115     * Returns the tags choice.
    115      * @return the tags choice (can be null)
     116     * @return the tags choice
    116117     */
    117     public ExistingBothNew getTags() {
    118         return tags.getSelected();
     118    public Optional<ExistingBothNew> getTags() {
     119        return Optional.ofNullable(tags).map(ExistingBothNewChoice::getSelected);
    119120    }
    120121
    121122    /**
    122123     * Returns the memberships choice.
    123      * @return the memberships choice (can be null)
     124     * @return the memberships choice
    124125     */
    125     public ExistingBothNew getMemberships() {
    126         return memberships.getSelected();
     126    public Optional<ExistingBothNew> getMemberships() {
     127        return Optional.ofNullable(memberships).map(ExistingBothNewChoice::getSelected);
    127128    }
    128129
Note: See TracChangeset for help on using the changeset viewer.