Changeset 18783 in josm


Ignore:
Timestamp:
2023-07-26T22:06:14+02:00 (2 years 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
Location:
trunk
Files:
2 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        }
  • trunk/test/unit/org/openstreetmap/josm/gui/dialogs/ConflictDialogTest.java

    r17275 r18783  
    22package org.openstreetmap.josm.gui.dialogs;
    33
     4import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
    45import static org.junit.jupiter.api.Assertions.assertEquals;
    5 import static org.junit.jupiter.api.Assertions.assertNotNull;
    66
    77import java.awt.Color;
    88import java.awt.image.BufferedImage;
    99
    10 import org.junit.jupiter.api.extension.RegisterExtension;
    1110import org.junit.jupiter.api.Test;
    1211import org.openstreetmap.josm.data.coor.LatLon;
     
    1918import org.openstreetmap.josm.gui.dialogs.ConflictDialog.ConflictPainter;
    2019import org.openstreetmap.josm.gui.layer.OsmDataLayer;
    21 import org.openstreetmap.josm.testutils.JOSMTestRules;
    22 
    23 import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
     20import org.openstreetmap.josm.testutils.annotations.Main;
     21import org.openstreetmap.josm.testutils.annotations.Projection;
    2422
    2523/**
    2624 * Unit tests of {@link ConflictDialog} class.
    2725 */
     26@Main
     27@Projection
    2828class ConflictDialogTest {
    29 
    30     /**
    31      * Setup tests
    32      */
    33     @RegisterExtension
    34     @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD")
    35     public JOSMTestRules test = new JOSMTestRules().main().projection();
    36 
    3729    /**
    3830     * Unit test of {@link ConflictDialog#ConflictDialog}.
     
    4032    @Test
    4133    void testConflictDialog() {
    42         assertNotNull(new ConflictDialog());
     34        assertDoesNotThrow(ConflictDialog::new);
    4335    }
    4436
Note: See TracChangeset for help on using the changeset viewer.