Changeset 18876 in josm


Ignore:
Timestamp:
2023-10-24T15:50:05+02:00 (8 months ago)
Author:
taylor.smock
Message:

See #23238: Some MapCSS functions cause NPEs when part of fixAdd

JOSM_Search doesn't trigger the issue unless the search string is non-empty.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/mappaint/mapcss/Functions.java

    r18875 r18876  
    629629     */
    630630    public static boolean has_tag_key(final Environment env, String key) {
    631         return env.osm != null ? env.osm.hasKey(key) : false;
     631        return env.osm != null && env.osm.hasKey(key);
    632632    }
    633633
     
    852852     */
    853853    public static Boolean JOSM_search(final Environment env, String searchStr) {
     854        if (env.osm == null) {
     855            return null;
     856        }
    854857        Match m;
    855858        try {
  • trunk/test/unit/org/openstreetmap/josm/gui/mappaint/mapcss/FunctionsTest.java

    r18875 r18876  
    260260    /**
    261261     * Non-regression test for #23238: NPE when env.osm is null
     262     * @see #testNonRegression23238JOSMSearch()
    262263     */
    263264    @ParameterizedTest
     
    288289        }
    289290    }
     291
     292    /**
     293     * Non-regression test for #23238: NPE when env.osm is null and {@link Functions#JOSM_search(Environment, String)}
     294     * has a non-empty search string.
     295     * @see #testNonRegression23238(Method)
     296     */
     297    @Test
     298    void testNonRegression23238JOSMSearch() {
     299        assertDoesNotThrow(() -> Functions.JOSM_search(new Environment(), "foobar"));
     300    }
    290301}
Note: See TracChangeset for help on using the changeset viewer.