Changeset 18313 in josm for trunk/src/org


Ignore:
Timestamp:
2021-11-06T23:09:06+01:00 (2 years ago)
Author:
Don-vip
Message:

fix #21509 - fix potential NPEs related to comboboxes

Location:
trunk/src/org/openstreetmap/josm/gui
Files:
4 edited

Legend:

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

    r18221 r18313  
    434434     */
    435435    public static String getEditItem(AutoCompComboBox<AutoCompletionItem> cb) {
    436         return Utils.removeWhiteSpaces(cb.getEditor().getItem().toString());
     436        return Utils.removeWhiteSpaces(cb.getEditorItemAsString());
    437437    }
    438438
  • trunk/src/org/openstreetmap/josm/gui/tagging/presets/items/Text.java

    r18254 r18313  
    44import static org.openstreetmap.josm.tools.I18n.tr;
    55
    6 import java.util.ArrayList;
    76import java.awt.Color;
    87import java.awt.Component;
     
    1110import java.text.NumberFormat;
    1211import java.text.ParseException;
     12import java.util.ArrayList;
    1313import java.util.Collection;
    1414import java.util.Collections;
     
    223223    private static String getValue(Component comp) {
    224224        if (comp instanceof JosmComboBox) {
    225             return ((JosmComboBox<?>) comp).getEditor().getItem().toString();
     225            return ((JosmComboBox<?>) comp).getEditorItemAsString();
    226226        } else if (comp instanceof JosmTextField) {
    227227            return ((JosmTextField) comp).getText();
  • trunk/src/org/openstreetmap/josm/gui/widgets/HistoryComboBox.java

    r18305 r18313  
    2929     */
    3030    public void addCurrentItemToHistory() {
    31         String newItem = getModel().addTopElement(getEditor().getItem().toString());
    32         getModel().setSelectedItem(newItem);
     31        String item = getEditorItemAsString();
     32        if (item != null) {
     33            getModel().setSelectedItem(getModel().addTopElement(item));
     34        }
    3335    }
    3436}
  • trunk/src/org/openstreetmap/josm/gui/widgets/JosmComboBox.java

    r18280 r18313  
    170170    public JosmTextField getEditorComponent() {
    171171        return (JosmTextField) (editor == null ? null : editor.getEditorComponent());
     172    }
     173
     174    /**
     175     * Returns the string representation of current edited item, or null.
     176     * @return the string representation of current edited item, or null
     177     * @since 18313
     178     */
     179    public String getEditorItemAsString() {
     180        return editor != null && editor.getItem() != null ? editor.getItem().toString() : null;
    172181    }
    173182
Note: See TracChangeset for help on using the changeset viewer.