Skip to content

Commit 37bd6bd

Browse files
SONARJAVA-6014 Add Jakarta's @Inject annotation to the exceptions for S1258 (#5414)
1 parent 50ff7d0 commit 37bd6bd

4 files changed

Lines changed: 23 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": "S6813",
33
"hasTruePositives": true,
4-
"falseNegatives": 64,
4+
"falseNegatives": 65,
55
"falsePositives": 0
66
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package checks;
2+
3+
import jakarta.inject.Inject;
4+
5+
class InjectedService {
6+
}
7+
8+
class JakartaInject {
9+
@jakarta.inject.Inject
10+
private InjectedService myService; // Compliant, fields annotated with Jakarta's @Inject should be ignored.
11+
}
12+
13+
class JakartaImportedInject {
14+
@Inject
15+
private InjectedService myService; // Compliant, fields annotated with Jakarta's @Inject should be ignored.
16+
}

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
@@ -54,12 +54,13 @@ public class AtLeastOneConstructorCheck extends IssuableSubscriptionVisitor {
5454
"javax.annotation.Resource",
5555
"javax.ejb.EJB",
5656
"javax.inject.Inject",
57+
"jakarta.inject.Inject",
5758
"org.apache.maven.plugins.annotations.Component",
5859
"org.apache.maven.plugins.annotations.Parameter",
5960
"org.codehaus.plexus.component.annotations.Requirement",
6061
"org.codehaus.plexus.component.annotations.Configuration",
6162
"org.springframework.beans.factory.annotation.Value"
62-
);
63+
);
6364

6465
@Override
6566
public List<Kind> nodesToVisit() {

java-checks/src/test/java/org/sonar/java/checks/AtLeastOneConstructorCheckTest.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@ void test() {
3030
.onFile(mainCodeSourcesPath("checks/AtLeastOneConstructorCheckSample.java"))
3131
.withCheck(new AtLeastOneConstructorCheck())
3232
.verifyIssues();
33+
CheckVerifier.newVerifier()
34+
.onFile(mainCodeSourcesPath("checks/AtLeastOneConstructorCheckJakartaSample.java"))
35+
.withCheck(new AtLeastOneConstructorCheck())
36+
.verifyNoIssues();
3337
}
3438

3539
@Test

0 commit comments

Comments
 (0)