Changeset 18327 in josm


Ignore:
Timestamp:
2021-12-02T09:54:09+01:00 (3 years ago)
Author:
GerdP
Message:

fix #21550: NPE in org.openstreetmap.josm.gui.tagging.presets.items.PresetListEntry.getCount

  • add null check (patch by taylor.smock)
Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/tagging/presets/items/PresetListEntry.java

    r18257 r18327  
    189189     */
    190190    public int getCount() {
    191         Integer count = cms == null ? null : cms.usage.map.get(value);
     191        Integer count = cms == null || cms.usage == null ? null : cms.usage.map.get(value);
    192192        return count == null ? 0 : count;
    193193    }
  • trunk/test/unit/org/openstreetmap/josm/gui/tagging/presets/items/PresetListEntryTest.java

    r18254 r18327  
    22package org.openstreetmap.josm.gui.tagging.presets.items;
    33
     4import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
    45import static org.junit.jupiter.api.Assertions.assertTrue;
    56
     
    2829        assertTrue(new PresetListEntry("", null).getListDisplay(200).contains(" "));
    2930    }
     31
     32    /**
     33     * Non-regression test for ticket <a href="https://josm.openstreetmap.de/ticket/21550">#21550</a>
     34     */
     35    @Test
     36    void testTicket21550() {
     37        final PresetListEntry entry = new PresetListEntry("", new Combo());
     38        assertDoesNotThrow(entry::getCount);
     39    }
    3040}
Note: See TracChangeset for help on using the changeset viewer.