Skip to content

Commit b5eac20

Browse files
SONARJAVA-5324 FP, modify S6856 to support PatchMapping annotation (#5029)
1 parent 7f28869 commit b5eac20

3 files changed

Lines changed: 14 additions & 2 deletions

File tree

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"ruleKey": "S6856",
33
"hasTruePositives": false,
4-
"falseNegatives": 43,
4+
"falseNegatives": 44,
55
"falsePositives": 0
66
}

java-checks-test-sources/default/src/main/java/checks/spring/MissingPathVariableAnnotationCheckSample.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import org.springframework.web.bind.annotation.DeleteMapping;
66
import org.springframework.web.bind.annotation.GetMapping;
77
import org.springframework.web.bind.annotation.ModelAttribute;
8+
import org.springframework.web.bind.annotation.PatchMapping;
89
import org.springframework.web.bind.annotation.PathVariable;
910
import org.springframework.web.bind.annotation.PostMapping;
1011
import org.springframework.web.bind.annotation.PutMapping;
@@ -51,6 +52,11 @@ public String request(String id) {
5152
return "Hello World";
5253
}
5354

55+
@PatchMapping("/{id}") // Noncompliant
56+
public String patch(String id) {
57+
return "Hello World";
58+
}
59+
5460
@PutMapping("/id")
5561
@DeleteMapping("/{id}") // Noncompliant
5662
public String deletePut(String id) {
@@ -84,6 +90,11 @@ public String requestCompliant(@PathVariable String id) {
8490
return "Hello World";
8591
}
8692

93+
@PatchMapping("/{id}")
94+
public String patchCompliant(@PathVariable String id) {
95+
return "Hello World";
96+
}
97+
8798
@GetMapping("/{id}")
8899
@DeleteMapping({"/{id}"})
89100
public String deleteGetCompliant(@PathVariable String id) { // compliant

java-checks/src/main/java/org/sonar/java/checks/spring/MissingPathVariableAnnotationCheck.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,8 @@ public class MissingPathVariableAnnotationCheck extends IssuableSubscriptionVisi
4747
"org.springframework.web.bind.annotation.GetMapping",
4848
"org.springframework.web.bind.annotation.PostMapping",
4949
"org.springframework.web.bind.annotation.PutMapping",
50-
"org.springframework.web.bind.annotation.DeleteMapping");
50+
"org.springframework.web.bind.annotation.DeleteMapping",
51+
"org.springframework.web.bind.annotation.PatchMapping");
5152

5253
@Override
5354
public List<Tree.Kind> nodesToVisit() {

0 commit comments

Comments
 (0)