Skip to content

Commit

Permalink
fix #21550: NPE in org.openstreetmap.josm.gui.tagging.presets.items.P…
Browse files Browse the repository at this point in the history
…resetListEntry.getCount

- add null check (patch by taylor.smock)

git-svn-id: https://josm.openstreetmap.de/svn/trunk@18327 0c6e7542-c601-0410-84e7-c038aed88b3b
  • Loading branch information
GerdP authored and GerdP committed Dec 2, 2021
1 parent d365162 commit 3302678
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
Expand Up @@ -188,7 +188,7 @@ public int hashCode() {
* @return see above
*/
public int getCount() {
Integer count = cms == null ? null : cms.usage.map.get(value);
Integer count = cms == null || cms.usage == null ? null : cms.usage.map.get(value);
return count == null ? 0 : count;
}

Expand Down
@@ -1,6 +1,7 @@
// License: GPL. For details, see LICENSE file.
package org.openstreetmap.josm.gui.tagging.presets.items;

import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
import static org.junit.jupiter.api.Assertions.assertTrue;

import org.junit.jupiter.api.BeforeAll;
Expand All @@ -27,4 +28,13 @@ public static void setUp() {
void testTicket12416() {
assertTrue(new PresetListEntry("", null).getListDisplay(200).contains(" "));
}

/**
* Non-regression test for ticket <a href="https://josm.openstreetmap.de/ticket/21550">#21550</a>
*/
@Test
void testTicket21550() {
final PresetListEntry entry = new PresetListEntry("", new Combo());
assertDoesNotThrow(entry::getCount);
}
}

0 comments on commit 3302678

Please sign in to comment.