Skip to content

Use explicit @PathVariable names for reliable binding#73

Merged
ondrejfuhrer merged 2 commits into
mainfrom
fix/enable-parameters-compiler-flag
Jun 12, 2026
Merged

Use explicit @PathVariable names for reliable binding#73
ondrejfuhrer merged 2 commits into
mainfrom
fix/enable-parameters-compiler-flag

Conversation

@ondrejfuhrer

@ondrejfuhrer ondrejfuhrer commented Jun 12, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Add explicit names to every @PathVariable annotation (e.g. @PathVariable("id")) in ActivitiesController and SupplierController.

Why

Candidates reported API endpoints failing because path variables couldn't be bound. Without the -parameters compiler flag, Java compiles parameter names to arg0, arg1, etc., so Spring can't match {id} to the id argument when the annotation has no explicit name.

It worked locally because Spring Boot's Gradle plugin (3.2+) sets -parameters automatically and IntelliJ adds it too. The failures came from compile paths that bypass that — non-delegated IDE builds or stale build/ 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 compileJava succeeds
  • Verify @PathVariable endpoints resolve correctly when run via a fresh clone

🤖 Generated with Claude Code

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>
@ondrejfuhrer ondrejfuhrer requested a review from a team as a code owner June 12, 2026 10:05
@ondrejfuhrer ondrejfuhrer requested a review from ctbur June 12, 2026 10:05
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>
@ondrejfuhrer ondrejfuhrer changed the title Enable -parameters compiler flag for reliable PathVariable binding Use explicit @PathVariable names for reliable binding Jun 12, 2026
@ondrejfuhrer ondrejfuhrer merged commit 479b9bd into main Jun 12, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant