Changeset 18783 in josm for trunk/src/org/openstreetmap


Ignore:
Timestamp:
2023-07-26T22:06:14+02:00 (12 months ago)
Author:
taylor.smock
Message:

Fix #23081: NoSuchElementException in ConflictDialog.ResolveToAction#actionPerformed

This occurs when one of the Resolve to (my|their) versions actions is called
when no conflict is selected.

There are two distinct bugs:

  • isConflictSelected did not check to make certain that the selection index made sense
  • ResolveActions were not enabled/disabled when the popup menu became visible, depending upon whether the current selection was valid
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/dialogs/ConflictDialog.java

    r18778 r18783  
    322322    private synchronized boolean isConflictSelected() {
    323323        final ListSelectionModel selModel = lstConflicts.getSelectionModel();
    324         return selModel.getMinSelectionIndex() >= 0 && selModel.getMaxSelectionIndex() >= selModel.getMinSelectionIndex();
     324        final int minSelectionIndex = selModel.getMinSelectionIndex();
     325        final int maxSelectionIndex = selModel.getMaxSelectionIndex();
     326        final int maxIndex = conflicts.size();
     327        // if minSelectionIndex < 0, nothing is selected
     328        // if minSelectionIndex > maxIndex, then nothing is selected (we are operating with an old selection context, most likely)
     329        // if maxSelectionIndex < minSelectionIndex, _something_ funny is going on. Or there was a typo in the original code.
     330        return minSelectionIndex >= 0 && maxIndex > minSelectionIndex && maxSelectionIndex >= minSelectionIndex;
    325331    }
    326332
     
    369375            btnResolveMy.setVisible(ExpertToggleAction.isExpert());
    370376            btnResolveTheir.setVisible(ExpertToggleAction.isExpert());
     377            ((ResolveAction) btnResolveMy.getAction()).valueChanged(null);
     378            ((ResolveAction) btnResolveTheir.getAction()).valueChanged(null);
    371379        }
    372380
     
    529537                }
    530538            }
    531             UndoRedoHandler.getInstance().add(new SequenceCommand(name, commands));
     539                UndoRedoHandler.getInstance().add(new SequenceCommand(name, commands));
    532540            refreshView();
    533541        }
Note: See TracChangeset for help on using the changeset viewer.