Ticket #19436: 19436.2.patch

File 19436.2.patch, 2.2 KB (added by taylor.smock, 13 months ago)

Add non-regression test

  • src/org/openstreetmap/josm/io/remotecontrol/RequestProcessor.java

     
    407407    public static JsonArray getHandlersInfoAsJSON(Collection<String> handlers) {
    408408        JsonArrayBuilder json = Json.createArrayBuilder();
    409409        for (String s : Utils.firstNonNull(handlers, RequestProcessor.handlers.keySet())) {
    410             json.add(getHandlerInfoAsJSON(s));
     410            JsonObject infoAsJson = getHandlerInfoAsJSON(s);
     411            if (infoAsJson != null) {
     412                json.add(infoAsJson);
     413            }
    411414        }
    412415        return json.build();
    413416    }
     
    419422     */
    420423    public static JsonObject getHandlerInfoAsJSON(String cmd) {
    421424        RequestHandler handler;
     425        if (cmd == null) {
     426            return null;
     427        }
     428        if (!cmd.startsWith("/")) {
     429            cmd = new StringBuilder("/").append(cmd).toString();
     430        }
    422431        try {
    423432            Class<?> c = handlers.get(cmd);
    424433            if (c == null) return null;
  • test/unit/org/openstreetmap/josm/io/remotecontrol/RequestProcessorTest.java

     
     1// License: GPL. For details, see LICENSE file.
     2package org.openstreetmap.josm.io.remotecontrol;
     3
     4import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
     5
     6import java.util.Arrays;
     7
     8import org.junit.jupiter.api.Test;
     9
     10/**
     11 * Tests for {@link RequestProcessor}
     12 * @author Taylor Smock
     13 */
     14public class RequestProcessorTest {
     15    /**
     16     * Non-regression test for <a href="https://josm.openstreetmap.de/ticket/19436">#19436</a>
     17     */
     18    @Test
     19    public void testFeaturesDoesNotThrowNPE() {
     20        assertDoesNotThrow(() -> RequestProcessor.getHandlersInfoAsJSON(Arrays.asList("add_node", "/add_node", "", null)));
     21    }
     22}