Use explicit @PathVariable names for reliable binding#73
Merged
Conversation
Add the -parameters flag to all JavaCompile tasks so Spring can bind @PathVariable/@RequestParam by name across every compile path. Previously the flag was only applied implicitly by the Spring Boot Gradle plugin, so builds that bypassed it (non-delegated IDE builds, stale caches) failed to bind path variables at runtime. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Specify the path variable name in each @PathVariable annotation so binding works regardless of whether the -parameters compiler flag is present. This is more defensive than pinning the flag in build.gradle, since it has no dependency on compiler configuration or build path. Revert the build.gradle change from the previous commit. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
@PathVariableannotation (e.g.@PathVariable("id")) inActivitiesControllerandSupplierController.Why
Candidates reported API endpoints failing because path variables couldn't be bound. Without the
-parameterscompiler flag, Java compiles parameter names toarg0,arg1, etc., so Spring can't match{id}to theidargument when the annotation has no explicit name.It worked locally because Spring Boot's Gradle plugin (3.2+) sets
-parametersautomatically and IntelliJ adds it too. The failures came from compile paths that bypass that — non-delegated IDE builds or stalebuild/caches.Specifying the name in the annotation removes the dependency on compiler configuration entirely, which is the most defensive fix — it works on any build path regardless of flags.
Test plan
./gradlew compileJavasucceeds@PathVariableendpoints resolve correctly when run via a fresh clone🤖 Generated with Claude Code