From 823618ba8a5bb6e451d521dc3ddc3b6b7683950d Mon Sep 17 00:00:00 2001 From: ddeya Date: Thu, 11 Aug 2022 16:37:53 +0200 Subject: [PATCH 1/3] PSM-1555 Exempt @RequestAttribute from RequestMappingAnnotation check --- .../errorprone/bugpatterns/RequestMappingAnnotation.java | 3 ++- .../errorprone/bugpatterns/RequestMappingAnnotationTest.java | 4 ++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/RequestMappingAnnotation.java b/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/RequestMappingAnnotation.java index 698b218829..eb6d7b7969 100644 --- a/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/RequestMappingAnnotation.java +++ b/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/RequestMappingAnnotation.java @@ -65,7 +65,8 @@ public final class RequestMappingAnnotation extends BugChecker implements Method isType(ANN_PACKAGE_PREFIX + "PathVariable"), isType(ANN_PACKAGE_PREFIX + "RequestBody"), isType(ANN_PACKAGE_PREFIX + "RequestHeader"), - isType(ANN_PACKAGE_PREFIX + "RequestParam"))), + isType(ANN_PACKAGE_PREFIX + "RequestParam"), + isType(ANN_PACKAGE_PREFIX + "RequestAttribute"))), isSameType("java.io.InputStream"), isSameType("java.time.ZoneId"), isSameType("java.util.Locale"), diff --git a/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/RequestMappingAnnotationTest.java b/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/RequestMappingAnnotationTest.java index 0f38eafa03..03102b00af 100644 --- a/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/RequestMappingAnnotationTest.java +++ b/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/RequestMappingAnnotationTest.java @@ -29,6 +29,7 @@ void identification() { "import org.springframework.web.bind.annotation.RequestHeader;", "import org.springframework.web.bind.annotation.RequestMapping;", "import org.springframework.web.bind.annotation.RequestParam;", + "import org.springframework.web.bind.annotation.RequestAttribute;", "import org.springframework.web.context.request.NativeWebRequest;", "import org.springframework.web.context.request.WebRequest;", "import org.springframework.web.server.ServerWebExchange;", @@ -56,6 +57,9 @@ void identification() { " A properRequestParam(@RequestParam String param);", "", " @RequestMapping", + " A properRequestAttribute(@RequestAttribute String param);", + "", + " @RequestMapping", " A properInputStream(InputStream input);", "", " @RequestMapping", From 9802de97d08f92f3384b06163ec57e510c5c381d Mon Sep 17 00:00:00 2001 From: ddeya Date: Thu, 11 Aug 2022 16:44:17 +0200 Subject: [PATCH 2/3] PSM-1555 Sort imports --- .../errorprone/bugpatterns/RequestMappingAnnotationTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/RequestMappingAnnotationTest.java b/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/RequestMappingAnnotationTest.java index 03102b00af..dcf45338a2 100644 --- a/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/RequestMappingAnnotationTest.java +++ b/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/RequestMappingAnnotationTest.java @@ -25,11 +25,11 @@ void identification() { "import org.springframework.web.bind.annotation.PathVariable;", "import org.springframework.web.bind.annotation.PostMapping;", "import org.springframework.web.bind.annotation.PutMapping;", + "import org.springframework.web.bind.annotation.RequestAttribute;", "import org.springframework.web.bind.annotation.RequestBody;", "import org.springframework.web.bind.annotation.RequestHeader;", "import org.springframework.web.bind.annotation.RequestMapping;", "import org.springframework.web.bind.annotation.RequestParam;", - "import org.springframework.web.bind.annotation.RequestAttribute;", "import org.springframework.web.context.request.NativeWebRequest;", "import org.springframework.web.context.request.WebRequest;", "import org.springframework.web.server.ServerWebExchange;", From 35cf91cf4d8f8f7b072282d88124b0fcf0b7cbc4 Mon Sep 17 00:00:00 2001 From: Rick Ossendrijver Date: Thu, 11 Aug 2022 17:37:35 +0200 Subject: [PATCH 3/3] Suggestions --- .../errorprone/bugpatterns/RequestMappingAnnotation.java | 4 ++-- .../bugpatterns/RequestMappingAnnotationTest.java | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/RequestMappingAnnotation.java b/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/RequestMappingAnnotation.java index eb6d7b7969..d95d46ea04 100644 --- a/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/RequestMappingAnnotation.java +++ b/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/RequestMappingAnnotation.java @@ -63,10 +63,10 @@ public final class RequestMappingAnnotation extends BugChecker implements Method AT_LEAST_ONE, anyOf( isType(ANN_PACKAGE_PREFIX + "PathVariable"), + isType(ANN_PACKAGE_PREFIX + "RequestAttribute"), isType(ANN_PACKAGE_PREFIX + "RequestBody"), isType(ANN_PACKAGE_PREFIX + "RequestHeader"), - isType(ANN_PACKAGE_PREFIX + "RequestParam"), - isType(ANN_PACKAGE_PREFIX + "RequestAttribute"))), + isType(ANN_PACKAGE_PREFIX + "RequestParam"))), isSameType("java.io.InputStream"), isSameType("java.time.ZoneId"), isSameType("java.util.Locale"), diff --git a/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/RequestMappingAnnotationTest.java b/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/RequestMappingAnnotationTest.java index dcf45338a2..bf34c7bee2 100644 --- a/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/RequestMappingAnnotationTest.java +++ b/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/RequestMappingAnnotationTest.java @@ -48,16 +48,16 @@ void identification() { " A properPathVariable(@PathVariable String param);", "", " @PatchMapping", - " A properRequestBody(@RequestBody String body);", + " A properRequestAttribute(@RequestAttribute String attribute);", "", " @PostMapping", - " A properRequestHeader(@RequestHeader String header);", + " A properRequestBody(@RequestBody String body);", "", " @PutMapping", - " A properRequestParam(@RequestParam String param);", + " A properRequestHeader(@RequestHeader String header);", "", " @RequestMapping", - " A properRequestAttribute(@RequestAttribute String param);", + " A properRequestParam(@RequestParam String param);", "", " @RequestMapping", " A properInputStream(InputStream input);",