diff --git a/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/RequestParamType.java b/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/RequestParamType.java index eada0abe492..c74ca1f329d 100644 --- a/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/RequestParamType.java +++ b/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/RequestParamType.java @@ -77,8 +77,8 @@ private static ImmutableList includedClassNames(ErrorProneFlags flags) { private static ImmutableList> getSupportedClasses( ImmutableList inclusions) { return inclusions.stream() - .filter(inclusion -> !inclusion.isEmpty()) .map(String::trim) + .filter(inclusion -> !inclusion.isEmpty()) .map(inclusion -> isSubtypeOf(createClass(inclusion))) .collect(toImmutableList()); } diff --git a/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/RequestParamTypeTest.java b/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/RequestParamTypeTest.java index cb268714985..e024be4dc01 100644 --- a/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/RequestParamTypeTest.java +++ b/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/RequestParamTypeTest.java @@ -17,6 +17,9 @@ final class RequestParamTypeTest { .setArgs( ImmutableList.of( "-XepOpt:RequestParamType:Includes=com.google.common.collect.ImmutableSet")); + private final CompilationTestHelper restrictedWithInvalidFlagCompilationTestHelper = + CompilationTestHelper.newInstance(RequestParamType.class, getClass()) + .setArgs(ImmutableList.of("-XepOpt:RequestParamType:Includes=")); @Test void identification() { @@ -167,4 +170,61 @@ void identificationOfIncludedSubClass() { "}") .doTest(); } + + @Test + void identificationOfInvalidFlag() { + restrictedWithInvalidFlagCompilationTestHelper + .addSourceLines( + "A.java", + "import com.google.common.collect.ImmutableBiMap;", + "import com.google.common.collect.ImmutableList;", + "import com.google.common.collect.ImmutableMap;", + "import com.google.common.collect.ImmutableSet;", + "import java.util.List;", + "import java.util.Map;", + "import java.util.Set;", + "import org.jspecify.annotations.Nullable;", + "import org.springframework.web.bind.annotation.DeleteMapping;", + "import org.springframework.web.bind.annotation.GetMapping;", + "import org.springframework.web.bind.annotation.PostMapping;", + "import org.springframework.web.bind.annotation.PutMapping;", + "import org.springframework.web.bind.annotation.RequestBody;", + "import org.springframework.web.bind.annotation.RequestParam;", + "", + "interface A {", + " @PostMapping", + " A properRequestParam(@RequestBody String body);", + "", + " @GetMapping", + " A properRequestParam(@RequestParam int param);", + "", + " @GetMapping", + " A properRequestParam(@RequestParam List param);", + "", + " @PostMapping", + " A properRequestParam(@RequestBody String body, @RequestParam Set param);", + "", + " @PutMapping", + " A properRequestParam(@RequestBody String body, @RequestParam Map param);", + "", + " @GetMapping", + " // BUG: Diagnostic contains:", + " A get(@RequestParam ImmutableBiMap param);", + "", + " @PostMapping", + " // BUG: Diagnostic contains:", + " A post(@Nullable @RequestParam ImmutableList param);", + "", + " @PutMapping", + " // BUG: Diagnostic contains:", + " A put(@RequestBody String body, @RequestParam ImmutableSet param);", + "", + " @DeleteMapping", + " // BUG: Diagnostic contains:", + " A delete(@RequestBody String body, @RequestParam ImmutableMap param);", + "", + " void negative(ImmutableSet set, ImmutableMap map);", + "}") + .doTest(); + } }