Scrivio Interview library
DebuggingFoundations5 min read · updated 12 November 2026

After upgrading to Spring Framework 6.1, @PathVariable long id without a name fails with an error that the parameter name is not available. Why?

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.

Step throughHow Spring finds the name for @PathVariable long id
  1. Annotation has a name?@PathVariable("id")
    YesUse that nameNoAsk the parameter name discoverer
  2. Compiled with -parameters?MethodParameters attribute present
    YesReflection returns idNoNo name available
  3. Spring Framework older than 6.1?Debug-information fallback still exists
    YesRead 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.

Java
@RestController
@RequestMapping("/orders")
class OrderController {
@GetMapping("/{id}")
OrderDto get(@PathVariable long id) { ... } // no explicit name
}
// GET /orders/42 on Spring Framework 6.1+, compiled without -parameters:
// 500 Internal Server Error
// java.lang.IllegalArgumentException: Name for argument of type [long] not specified,
// and parameter name information not available via reflection.
// Ensure that the compiler uses the '-parameters' flag.

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.

XML
<!-- Maven, when not inheriting from spring-boot-starter-parent -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<parameters>true</parameters>
</configuration>
</plugin>
// Gradle, if the Spring Boot plugin is not applied to this module
tasks.withType(JavaCompile).configureEach {
options.compilerArgs.add("-parameters")
}
// Kotlin: kotlinc has -java-parameters; the Spring Boot plugin sets javaParameters = true

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.

What to say in the interviewAbout 80 seconds aloud

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.
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/