Skip to content

Commit

Permalink
SONARJAVA-4073 S3751 should accept protected and package scope modifiers
Browse files Browse the repository at this point in the history
  • Loading branch information
kkocel authored and quentin-jaquier-sonarsource committed Nov 11, 2021
1 parent fbd6004 commit 69c74ab
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ public void visitNode(Tree tree) {

if (isClassController(methodSymbol)
&& isRequestMappingAnnotated(methodSymbol)
&& !methodSymbol.isPublic()) {
reportIssue(methodTree.simpleName(), "Make this method \"public\".");
&& methodSymbol.isPrivate()) {
reportIssue(methodTree.simpleName(), "Make this method non \"private\".");
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<p>So marking a sensitive method <code>private</code> may seem like a good way to control how such code is called. Unfortunately, not all Spring
frameworks ignore visibility in this way. For instance, if you’ve tried to control web access to your sensitive, <code>private</code>,
<code>@RequestMapping</code> method by marking it <code>@Secured</code> …​ it will still be called, whether or not the user is authorized to access
it. That’s because AOP proxies are not applied to non-public methods.</p>
it. That’s because AOP proxies are not applied to private methods.</p>
<p>In addition to <code>@RequestMapping</code>, this rule also considers the annotations introduced in Spring Framework 4.3: <code>@GetMapping</code>,
<code>@PostMapping</code>, <code>@PutMapping</code>, <code>@DeleteMapping</code>, <code>@PatchMapping</code>.</p>
<h2>Noncompliant Code Example</h2>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"title": "\"@RequestMapping\" methods should be \"public\"",
"title": "\"@RequestMapping\" methods should not be \"private\"",
"type": "CODE_SMELL",
"status": "ready",
"remediation": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public String hello(String greetee) { // Compliant
}

@RequestMapping(value = "/greet", method = GET)
private String greet(String greetee) { // Noncompliant [[sc=18;ec=23]] {{Make this method "public".}}
private String greet(String greetee) { // Noncompliant [[sc=18;ec=23]] {{Make this method non "private".}}
}

@GetMapping
Expand Down Expand Up @@ -63,7 +63,7 @@ public String hello(String greetee) { // Compliant
}

@RequestMapping(value = "/greet", method = GET)
private String greet(String greetee) { // Noncompliant [[sc=18;ec=23]] {{Make this method "public".}}
private String greet(String greetee) { // Noncompliant [[sc=18;ec=23]] {{Make this method non "private".}}
}

@GetMapping public String a() { }
Expand Down

0 comments on commit 69c74ab

Please sign in to comment.