Changeset 8422 in josm


Ignore:
Timestamp:
2015-05-23T11:31:58+02:00 (9 years ago)
Author:
wiktorn
Message:

Change HashMap to ConcurrentHashMap, to avoid ConcurrentModificationException. Closes #11466

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/preferences/ToolbarPreferences.java

    r8395 r8422  
    2525import java.util.Collection;
    2626import java.util.Collections;
    27 import java.util.HashMap;
    2827import java.util.LinkedList;
    2928import java.util.List;
    3029import java.util.Map;
     30import java.util.concurrent.ConcurrentHashMap;
    3131
    3232import javax.swing.AbstractAction;
     
    8383        private String icon = "";
    8484        private ImageIcon ico = null;
    85         private final Map<String, Object> parameters = new HashMap<>();
     85        private final Map<String, Object> parameters = new ConcurrentHashMap<>();
    8686
    8787        public ActionDefinition(Action action) {
     
    209209
    210210                ParameterizedAction parametrizedAction = (ParameterizedAction)action;
    211                 Map<String, ActionParameter<?>> actionParams = new HashMap<>();
     211                Map<String, ActionParameter<?>> actionParams = new ConcurrentHashMap<>();
    212212                for (ActionParameter<?> param: parametrizedAction.getActionParameters()) {
    213213                    actionParams.put(param.getName(), param);
     
    218218                    skip('=');
    219219                    String paramValue = readTillChar(',',')');
    220                     if (paramName.length() > 0) {
     220                    if (paramName.length() > 0 && paramValue.length() > 0) {
    221221                        ActionParameter<?> actionParam = actionParams.get(paramName);
    222222                        if (actionParam != null) {
     
    369369        @Override
    370370        public void setValueAt(Object aValue, int rowIndex, int columnIndex) {
     371            String val = (String) aValue;
     372            int paramIndex = rowIndex;
     373
    371374            if(currentAction.getAction() instanceof AdaptableAction) {
    372375                if (rowIndex == 0) {
    373                      currentAction.setName((String)aValue);
     376                     currentAction.setName(val);
    374377                     return;
    375378                } else if (rowIndex == 1) {
    376                      currentAction.setIcon((String)aValue);
     379                     currentAction.setIcon(val);
    377380                     return;
    378381                } else {
    379                     rowIndex -= 2;
    380                 }
    381             }
    382             ActionParameter<Object> param = getParam(rowIndex);
    383             currentAction.getParameters().put(param.getName(), param.readFromString((String)aValue));
     382                    paramIndex -= 2;
     383                }
     384            }
     385            ActionParameter<Object> param = getParam(paramIndex);
     386
     387            if (param != null && val.length() > 0) {
     388                currentAction.getParameters().put(param.getName(), param.readFromString((String)aValue));
     389            }
    384390        }
    385391
     
    470476     * Value: The action to execute.
    471477     */
    472     private final Map<String, Action> actions = new HashMap<>();
    473     private final Map<String, Action> regactions = new HashMap<>();
     478    private final Map<String, Action> actions = new ConcurrentHashMap<>();
     479    private final Map<String, Action> regactions = new ConcurrentHashMap<>();
    474480
    475481    private final DefaultMutableTreeNode rootActionsNode = new DefaultMutableTreeNode(tr("Actions"));
    476482
    477483    public JToolBar control = new JToolBar();
    478     private final Map<Object, ActionDefinition> buttonActions = new HashMap<>(30);
     484    private final Map<Object, ActionDefinition> buttonActions = new ConcurrentHashMap<>(30);
    479485
    480486    @Override
     
    971977        loadActions();
    972978
    973         Map<String, Action> allActions = new HashMap<>(regactions);
     979        Map<String, Action> allActions = new ConcurrentHashMap<>(regactions);
    974980        allActions.putAll(actions);
    975981        ActionParser actionParser = new ActionParser(allActions);
Note: See TracChangeset for help on using the changeset viewer.