Skip to content

Commit 93a20b9

Browse files
SONARJAVA-5929 S1258 FP on Spring @value annotation (#5393)
1 parent 1b02e55 commit 93a20b9

3 files changed

Lines changed: 18 additions & 1 deletion

File tree

java-checks-test-sources/default/src/main/files/non-compiling/checks/AtLeastOneConstructorCheckSample.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,8 @@ class AtLeastOneConstructorCheckSample {
99
class AtLeastOneConstructorCheckAnnotatedUnknown {
1010
private MyObject foo; // Compliant
1111
}
12+
13+
class WithValueAnnotation {
14+
@Value("${app.field}")
15+
private int field; // Compliant
16+
}

java-checks-test-sources/default/src/main/java/checks/AtLeastOneConstructorCheckSample.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import org.apache.maven.plugins.annotations.Parameter;
1717
import org.codehaus.plexus.component.annotations.Configuration;
1818
import org.codehaus.plexus.component.annotations.Requirement;
19+
import org.springframework.beans.factory.annotation.Value;
1920

2021
class WithoutConstructor { // Noncompliant {{Add a constructor to the class, or provide default values.}}
2122
// ^^^^^^^^^^^^^^^^^^
@@ -163,3 +164,13 @@ class MyLombok { // Compliant, Builder pattern are excluded (Lombok builder)
163164

164165
public int getField(){return field;}
165166
}
167+
168+
class WithValueAnnotation { // Compliant, fields annotated with Spring @Value are excluded
169+
@Value("${app.field}")
170+
private int field;
171+
}
172+
173+
class WithValueAnnotationDefault { // Compliant, fields annotated with Spring @Value are excluded
174+
@Value("${app.field:10}")
175+
private int field;
176+
}

java-checks/src/main/java/org/sonar/java/checks/AtLeastOneConstructorCheck.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,8 @@ public class AtLeastOneConstructorCheck extends IssuableSubscriptionVisitor {
5757
"org.apache.maven.plugins.annotations.Component",
5858
"org.apache.maven.plugins.annotations.Parameter",
5959
"org.codehaus.plexus.component.annotations.Requirement",
60-
"org.codehaus.plexus.component.annotations.Configuration"
60+
"org.codehaus.plexus.component.annotations.Configuration",
61+
"org.springframework.beans.factory.annotation.Value"
6162
);
6263

6364
@Override

0 commit comments

Comments
 (0)