S6856: Support Spring 7 path-segment API versioning#5755
Conversation
| private void reportOrDeferMissingTemplateVariables(UriInfo uri, MappingInfo classMapping, Set<String> unboundVariables) { | ||
| if (springWebVersion != SpringWebVersion.START_FROM_7_0) { | ||
| addPendingIssue(uri.request(), missingTemplateVariablesMessage(unboundVariables)); | ||
| return; | ||
| } | ||
|
|
||
| pendingMappingIssues.add(new PendingMappingIssue( | ||
| context.getInputFile(), | ||
| AnalyzerMessage.textSpanFor(uri.request()), | ||
| Set.copyOf(unboundVariables), | ||
| combinePaths(classMapping.paths(), uri.mapping().paths()), | ||
| classMapping.versioned() || uri.mapping().versioned())); | ||
| } | ||
|
|
||
| private void addPendingIssue(Tree tree, String message) { |
There was a problem hiding this comment.
💡 Quality: All issues buffered to endOfAnalysis even without Spring 7
The refactor now routes every S6856 issue (including the ordinary "Bind method parameter" and template-variable issues) through pendingIssues/pendingMappingIssues and flushes them only in endOfAnalysis, for all Spring versions. Cross-file deferral is only needed for START_FROM_7_0; for the far more common non-Spring-7 case this unnecessarily holds every module's S6856 issues in memory until the end of analysis and reports them via the module context instead of inline.
This is functionally correct (verified endOfAnalysis runs in batch and file-by-file/SonarLint modes), but for the non-Spring-7 path you could report inline to avoid buffering. For example, in reportOrDeferMissingTemplateVariables you already branch on springWebVersion != START_FROM_7_0 — the addPendingIssue calls in that branch and in checkParametersAndPathTemplate could instead call reportIssue(...) directly so no state needs to be retained. Minor; consider only if memory of large modules is a concern.
Only buffer when deferral is actually required (Spring 7); otherwise report inline as before.:
// For non-Spring-7, report inline instead of buffering:
private void reportMissing(Tree tree, String message) {
if (springWebVersion == SpringWebVersion.START_FROM_7_0) {
pendingIssues.add(new AnalyzerMessage(this, context.getInputFile(),
AnalyzerMessage.textSpanFor(tree), message, 0));
} else {
reportIssue(tree, message);
}
}
- Apply fix
Check the box to apply the fix or reply for a change | Was this helpful? React with 👍 / 👎
Code Review 👍 Approved with suggestions 0 resolved / 1 findingsImplements Spring 7 path-segment API versioning support for S6856 to prevent false positives on unbound placeholders. Note that all analysis results are now buffered until the end of the analysis, which may impact performance even for non-Spring 7 projects. 💡 Quality: All issues buffered to endOfAnalysis even without Spring 7📄 java-checks/src/main/java/org/sonar/java/checks/spring/MissingPathVariableAnnotationCheck.java:336-350 📄 java-checks/src/main/java/org/sonar/java/checks/spring/MissingPathVariableAnnotationCheck.java:383-397 The refactor now routes every S6856 issue (including the ordinary "Bind method parameter" and template-variable issues) through This is functionally correct (verified Only buffer when deferral is actually required (Spring 7); otherwise report inline as before.🤖 Prompt for agentsOptionsAuto-apply is off → Gitar will not commit updates to this branch. Comment with these commands to change the behavior for this request:
Was this helpful? React with 👍 / 👎 | Gitar |
|
Hello team, may i get some feedback on this? |
Problem
Spring Framework 7 supports resolving an API version from a request path segment: