Skip to content

Commit

Permalink
Update reported message (#3233)
Browse files Browse the repository at this point in the history
  • Loading branch information
margarita-nedzelska-sonarsource authored Oct 2, 2020
1 parent 6886440 commit 970d69b
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
@RequestMapping("/home")
public class SpringRequestMappingMethodCheck {

@RequestMapping("/") // Noncompliant [[sc=4;ec=18]] {{Add a "method" parameter to this "@RequestMapping" annotation.}}
@RequestMapping("/") // Noncompliant [[sc=4;ec=18]] {{Make sure allowing safe and unsafe HTTP methods is safe here.}}
String home() {
return "Hello from get";
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ public class SpringRequestMappingMethodCheck extends IssuableSubscriptionVisitor
private static final String REQUEST_MAPPING_CLASS = "org.springframework.web.bind.annotation.RequestMapping";

private static final String REQUEST_METHOD = "method";
public static final String MESSAGE = "Make sure allowing safe and unsafe HTTP methods is safe here.";

@Override
public List<Tree.Kind> nodesToVisit() {
Expand All @@ -58,7 +59,7 @@ public void visitNode(Tree tree) {
findRequestMappingAnnotation(classTree.modifiers())
.flatMap(SpringRequestMappingMethodCheck::findRequestMethods)
.filter(SpringRequestMappingMethodCheck::mixSafeAndUnsafeMethods)
.ifPresent(methods -> reportIssue(methods, "Make sure allowing safe and unsafe HTTP methods is safe here."));
.ifPresent(methods -> reportIssue(methods, MESSAGE));

classTree.members().stream()
.filter(member -> member.is(Tree.Kind.METHOD))
Expand All @@ -73,9 +74,9 @@ private void checkMethod(MethodTree method, Symbol.TypeSymbol classSymbol) {
if (requestMethods.isPresent()) {
requestMethods
.filter(SpringRequestMappingMethodCheck::mixSafeAndUnsafeMethods)
.ifPresent(methods -> reportIssue(methods, "Make sure allowing safe and unsafe HTTP methods is safe here."));
.ifPresent(methods -> reportIssue(methods, MESSAGE));
} else if (requestMappingAnnotation.isPresent() && !inheritRequestMethod(classSymbol)) {
reportIssue(requestMappingAnnotation.get().annotationType(), "Add a \"method\" parameter to this \"@RequestMapping\" annotation.");
reportIssue(requestMappingAnnotation.get().annotationType(), MESSAGE);
}
}

Expand Down

0 comments on commit 970d69b

Please sign in to comment.