Quick revision
The short answer
Spring Framework 6.1 removed LocalVariableTableParameterNameDiscoverer, the fallback that read parameter names from the class file's debug information. Spring now gets names only through Java reflection, which needs the code compiled with the -parameters flag. Spring Boot's Gradle plugin and the Maven starter parent turn that flag on, but a custom build, an IDE compiler or a project without the parent may not, so @PathVariable long id has no name to match. Fix it by enabling -parameters, or by naming the parameter explicitly with @PathVariable("id").
What to remember
In this answer, we saw that Spring needs the names of method parameters to match @PathVariable long id to {id}, and that before 6.1 it could read them from debug information through LocalVariableTableParameterNameDiscoverer. Spring Framework 6.1 removed that fallback, so names now come only from reflection, which needs the -parameters compiler flag. Boot's Gradle plugin and the Maven starter parent set it, custom builds and IDE compilers may not, and explicit names such as @PathVariable("id") work everywhere.
Your turn
Answer it aloud as you would in the interview, or type your answer below. Then show one part at a time and compare.
Spring Framework 6.1 removed LocalVariableTableParameterNameDiscoverer, the fallback that read parameter names from the class file's debug information. Spring now gets names only through Java reflection, which needs the code compiled with the -parameters flag. Spring Boot's Gradle plugin and the Maven starter parent turn that flag on, but a custom build, an IDE compiler or a project without the parent may not, so @PathVariable long id has no name to match. Fix it by enabling -parameters, or by naming the parameter explicitly with @PathVariable("id").
Why this question is asked
Upgrade errors like this one are confusing because the code did not change. The same controller worked for years and now fails, sometimes only in one environment. Interviewers use it to see whether we understand how Spring knows the names of our method parameters at all. In this answer, we will recap how parameter names reach Spring, see what 6.1 removed and why, reproduce the error, and go through the fixes for Maven, Gradle and the IDE.
1A Quick Recap: How Does Spring Know a Parameter's Name?
When we write @PathVariable long id without a value, Spring must match the Java parameter name id to the {id} placeholder in the mapping. But Java does not keep parameter names in compiled code by default. The bytecode knows the method takes a long, not that we called it id.
There are two places a name can come from. The first is the MethodParameters attribute, which javac writes into the class file only when we compile with -parameters; Java reflection then exposes it through Parameter.getName(). The second is the local variable table, part of the debug information that javac writes with -g, which most builds include for stack traces and debuggers. For many years Spring tried reflection first and fell back to reading the debug information with LocalVariableTableParameterNameDiscoverer, so names worked even without -parameters.
2What Changed in Spring Framework 6.1
Spring 6.0 deprecated the debug-information fallback, and 6.1 removed it. Reading the local variable table needed bytecode parsing, did not work for interface methods or abstract methods, and depended on how classes were compiled. Since Java 8 the standard -parameters mechanism exists, so Spring now uses only that, through StandardReflectionParameterNameDiscoverer.
So a project that compiled without -parameters worked on Spring 6.0 and older, often with a deprecation warning in the log, and fails on 6.1 and later. Spring Boot 3.2 was the first Boot version on Framework 6.1, so this often shows up during a Boot 3.1 to 3.2 or later upgrade.
- Annotation has a name?
@PathVariable("id")YesUse that nameNoAsk the parameter name discoverer - Compiled with -parameters?
MethodParametersattribute presentYesReflection returns idNoNo name available - Spring Framework older than 6.1?Debug-information fallback still existsYesRead the name from the local variable tableNoIllegalArgumentException at request time
3 steps in order. Play them, or step through them one at a time.
3Reproducing the Error
Here is a controller that relies on the parameter name, compiled without -parameters.
Notice that the application starts fine. The error appears on the first request to that endpoint, because Spring resolves argument names lazily. That is why it sometimes slips through a build that has no controller tests, and why it can appear in one environment and not another: for example, the IDE's own compiler may not pass -parameters while the Maven build does, or the reverse. The same problem affects @RequestParam, @RequestHeader, @Value on constructor parameters in some cases, and @Param in Spring Data query methods.
4Fix 1: Compile With -parameters
The cleanest fix is to make sure every compilation passes -parameters. In Gradle, the Spring Boot plugin already configures it for JavaCompile tasks. In Maven, the spring-boot-starter-parent POM configures the compiler plugin with parameters set to true. Projects that use their own company parent POM, or import Spring Boot only as a BOM, do not get that and must add it themselves.
After changing the build, do a clean rebuild so no stale class files remain. In IntelliJ IDEA, if the project builds with its own compiler instead of delegating to Maven or Gradle, add -parameters under the Java compiler settings as well.
5Fix 2: Name the Parameters Explicitly
The other fix is to give each annotation its name: @PathVariable("id") long id, @RequestParam("status") String status. This works regardless of how the code was compiled, and some teams prefer it in shared libraries whose consumers build them in unknown ways. The cost is repetition and the risk of a typo that does not match the template.
In most applications, I would fix the build so the flag is always on, and add a @WebMvcTest that calls each endpoint once. That catches the problem in CI, before it reaches an environment.
6Follow-up questions
Why did Spring remove a fallback that worked?
Because the debug-information approach was fragile: it parsed bytecode with ASM, failed for interfaces and abstract methods, and depended on -g being present. The standard -parameters flag has existed since Java 8 and is supported by reflection directly, so Spring standardised on it and removed the extra code path.
Does this affect constructor injection?
Not for normal autowiring by type. It matters where Spring matches by name, for example @Value or @Qualifier resolution that falls back to the parameter name, constructor binding of configuration properties, and Spring Data @Query parameters without @Param. These also need -parameters or explicit names.
7Conclusion
In this answer, we saw that Spring needs the names of method parameters to match @PathVariable long id to {id}, and that before 6.1 it could read them from debug information through LocalVariableTableParameterNameDiscoverer. Spring Framework 6.1 removed that fallback, so names now come only from reflection, which needs the -parameters compiler flag. Boot's Gradle plugin and the Maven starter parent set it, custom builds and IDE compilers may not, and explicit names such as @PathVariable("id") work everywhere.
Open with
Spring has to know that the Java parameter is called id to match it to {id} in the mapping. Java doesn't keep parameter names in bytecode unless you compile with -parameters, which writes the MethodParameters attribute that reflection can read.
Then, if they want more
For years Spring had a fallback, LocalVariableTableParameterNameDiscoverer, which read the names from the debug information that most builds include anyway. Spring 6.0 deprecated it and 6.1 removed it, so now names only come from reflection.
If the code was compiled without -parameters, the app starts fine, but the first request to that endpoint fails with an IllegalArgumentException saying the name isn't specified and that the compiler should use -parameters. Spring Boot normally hides this, because the Gradle plugin and the spring-boot-starter-parent POM turn the flag on.
It breaks when a project uses its own parent POM or only imports the Boot BOM, or when the IDE compiles with its own settings. The fix is to add -parameters to the compiler config, parameters true in the Maven compiler plugin or the compiler argument in Gradle, then rebuild cleanly.
Alternatively I can name each parameter explicitly, like @PathVariable("id"), which works however it's compiled. I'd also add a simple web test per endpoint so this shows up in CI.
About this answer
- Last updated
- 12 November 2026
- Versions it names
- Spring Framework 6, Java 8, Spring Boot 3.2
- Checked
- Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the documentation below. What the checks cover
- Where the question comes from
- Written by Scrivio for practice. It is not taken from an interview.
- Official documentation
- Spring Framework reference, Spring Web MVC
Report an issue with this answer
Copy the line below and send it to the author with what you found. It carries the address of this page.
Issue with "After upgrading to Spring Framework 6.1, @PathVariable long id without a name fails with...": https://scrivio-interview-library.netlify.app/spring-boot/rest-controllers/0a3c48c4cc/