SONARJAVA-6491: Implement S8911 - Methods annotated with @Startup should be non-static, non-producer, and parameter-free#5694
Conversation
| "ruleKey": "S6813", | ||
| "hasTruePositives": true, | ||
| "falseNegatives": 65, | ||
| "falseNegatives": 66, |
There was a problem hiding this comment.
💡 Quality: S6813 false-negative baseline increased (65->66) without explanation
diff_S6813.json records an increase in falseNegatives from 65 to 66, and a new diff_S8899.json plus the bump of rulesNotReporting from 19 to 20 are added. These are autoscan baseline changes for rules (S6813, S8899) that are unrelated to the S8911 feature this PR claims to implement.
The +1 false negative for S6813 likely stems from the new test sources added for S8911 (e.g. the mock io.quarkus.runtime.Startup / Jakarta test sample) introducing a Spring/CDI construct that S6813 no longer detects in no-binaries (autoscan) mode. This is plausibly a legitimate baseline update, but the commit message only mentions "updated autoscan test baselines" without explaining the root cause. Please confirm the new false negative is expected behavior (a true autoscan limitation) and not an actual regression introduced by the added test code, and document the reason in the PR.
Was this helpful? React with 👍 / 👎
7474c91 to
f20a9ac
Compare
b6d365b to
93ac858
Compare
… with individual diff files
…eporting count from 20 to 19
Code Review 👍 Approved with suggestions 3 resolved / 4 findingsImplements rule S8911 to enforce CDI requirements for 💡 Quality: S6813 false-negative baseline increased (65->66) without explanation📄 its/autoscan/src/test/resources/autoscan/diffs/diff_S6813.json:4 📄 its/autoscan/src/test/resources/autoscan/diffs/diff_S8899.json:1-6 📄 its/autoscan/src/test/java/org/sonar/java/it/AutoScanTest.java:201
The +1 false negative for S6813 likely stems from the new test sources added for S8911 (e.g. the mock ✅ 3 resolved✅ Bug: S8911 not added to Sonar_way_profile.json
✅ Quality: activateLicense() removed only from AutoScanTest, inconsistent with other ITs
✅ Quality: Build artifacts (MANIFEST.MF, .class files) committed to source control
🤖 Prompt for agentsOptionsAuto-apply is off → Gitar will not commit updates to this branch. Comment with these commands to change:
Was this helpful? React with 👍 / 👎 | Gitar |
|




Summary
This PR implements rule S8911 to detect methods annotated with
@Startup(fromio.quarkus.runtime.Startup) that violate CDI initialization requirements by being static, having parameters, or being annotated with@Produces.Rule Behavior
The rule detects methods annotated with
@Startupthat:static(static methods cannot be managed by CDI lifecycle)@Produces(producer methods serve a different purpose than initialization)Implementation Approach
The implementation follows the pattern established by
ScheduledOnlyOnNoArgMethodCheck(S7184):IssuableSubscriptionVisitorto subscribe toTree.Kind.METHODnodes@Startupannotation (io.quarkus.runtime.Startup)@Startupis present, checks for three violations:methodTree.symbol().isStatic())!methodTree.parameters().isEmpty())@Producesannotation (checking forjakarta.enterprise.inject.Produces)@Startupannotation for contextTest Coverage
The test file covers:
Noncompliant patterns:
@Startup@Startupand parameters@Startupand@ProducesCompliant patterns:
@Startup(valid usage)@Injectfields) instead of parameters@Startupannotation (static, producer, or parameterized methods are OK)@Startup(access level doesn't matter for this rule)Additional Changes
io.quarkus.runtime.Startupannotation injava-checks-test-sources/default/src/main/java/io/quarkus/runtime/Startup.javafollowing the pattern used for other external dependencies (similar toio.realm.RealmConfiguration)jakarta.enterprise.cdi-apiandjavax.inject) already available in the test sources pomResources
🤖 Generated with Claude Code