redhat-developer / redhat-developer/vscode-java
Spring "PathVariable annotation was empty on param" method mapping
Dieses Issue hat noch niemand übernommen.
- Vorherrschende Sprache
- TypeScript
- Sterne
- 2.3k
- Forks
- 546
- Ø Merge
- 20 Std. 1 Min.
- Gemergte PRs (30 T.)
- 11
Beschreibung
I'm trying to test a FeignClient where I've defined a PathVariable using a @PathVariable String urlId but I'm receiving a PathVariable annotation was empty on param 0 when I attempt to run my tests. It works via a gradlew test but not in the VS Code test runner. I can resolve this by explicitly mapping @PathVariable(value = "urlId") String urlId but the documentation defines that as an optional field (https://docs.spring.io/spring-framework/docs/current/javadoc-api/org/springframework/web/bind/annotation/PathVariable.html).
I believe this is something related to the compiler, because gradlew test and IntelliJ can run the tests without the explicit mapping, but it only fails with the error in the VS Code test extension. Reading the spring docs it calls out in the input mapping that if it's compiled with the -parameters flag it will map the input to the method's parameters (https://docs.spring.io/spring-boot/reference/actuator/endpoints.html#actuator.endpoints.implementing-custom.input). I was able to successfully validate this in VS Code by going to the Java > Settings: Url and pointing it to a new settings.pref file I created that only contains the line org.eclipse.jdt.core.compiler.codegen.methodParameters=generate, which allowed the compiler to map without the explicit (value = "urlId") on the annotation. I'm not a huge fan of this approach however, because I'm positive I'm going to forget this every time I setup a new device, so I was wondering if this constituted an issue that could be rolled into the extension so this was supported without having to create a custom settings file any time I need to test a spring project with feign client.
For additional system details I'm running spring boot 3.4.1, with a gradle build it, on Java 21.0.6 (Amazon Corretto 21) on the Java Language Support extension version 1.41.0 (temporarily downgraded from 1.41.1 due to https://github.com/redhat-developer/vscode-java/issues/4002)
Beitragsleitfaden
Erste Schritte
- Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
- Forke das Repository und arbeite in einem Branch.
- Öffne einen Pull Request, der die Issue-Nummer nennt.
Rechercherichtung
Reproduziere den Fehler mit dem beschriebenen Spring Boot- und FeignClient-Setup im VS Code Java test runner und untersuche anschließend, wie die Erweiterung die Generierung von Methodenparametern des JDT-Compilers im Vergleich zu Gradle und IntelliJ konfiguriert. Als erledigt gilt dies, wenn @PathVariable String urlId im VS Code runner ohne einen settings.pref-Workaround pro Gerät funktioniert, einschließlich einer Regressionstestabdeckung, falls der relevante Test-Einstiegspunkt identifiziert wird.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- java, spring, vscode
- Bereich
- developer-experience, tooling
- Issue-Typ
- Bug
- Schwierigkeit
- 4/5
- Geschätzter Aufwand
- 3-5 Tage
- Aktivitätsstatus
- Veraltet
- Klarheit
- Größtenteils klar
- Anfängerfreundlichkeit
- 35/100