Skip to content

Commit 459e8a1

Browse files
committed
Deprecate LocalVariableTableParameterNameDiscoverer completely
LocalVariableTableParameterNameDiscoverer is not registered by default anymore now. Java sources should be compiled with `-parameters` instead (available since Java 8). Also retaining standard Java parameter names for all of Spring's Kotlin sources now. Closes gh-29531
1 parent 7e52b80 commit 459e8a1

File tree

13 files changed

+37
-40
lines changed

13 files changed

+37
-40
lines changed

buildSrc/src/main/java/org/springframework/build/KotlinConventions.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ private void configure(KotlinCompile compile) {
3838
kotlinOptions.setApiVersion("1.7");
3939
kotlinOptions.setLanguageVersion("1.7");
4040
kotlinOptions.setJvmTarget("17");
41+
kotlinOptions.setJavaParameters(true);
4142
kotlinOptions.setAllWarningsAsErrors(true);
4243
List<String> freeCompilerArgs = new ArrayList<>(compile.getKotlinOptions().getFreeCompilerArgs());
4344
freeCompilerArgs.addAll(List.of("-Xsuppress-version-warnings", "-Xjsr305=strict", "-opt-in=kotlin.RequiresOptIn"));

framework-docs/src/docs/asciidoc/web/webflux.adoc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1532,8 +1532,8 @@ register support for any other data type.
15321532
See <<webflux-ann-typeconversion>> and <<webflux-ann-initbinder>>.
15331533

15341534
URI variables can be named explicitly (for example, `@PathVariable("customId")`), but you can
1535-
leave that detail out if the names are the same and you compile your code with debugging
1536-
information or with the `-parameters` compiler flag on Java 8.
1535+
leave that detail out if the names are the same and you compile your code with the `-parameters`
1536+
compiler flag.
15371537

15381538
The syntax `{*varName}` declares a URI variable that matches zero or more remaining path
15391539
segments. For example `/resources/{*path}` matches all files under `/resources/`, and the

framework-docs/src/docs/asciidoc/web/webmvc.adoc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1699,8 +1699,8 @@ register support for any other data type.
16991699
See <<mvc-ann-typeconversion>> and <<mvc-ann-initbinder>>.
17001700

17011701
You can explicitly name URI variables (for example, `@PathVariable("customId")`), but you can
1702-
leave that detail out if the names are the same and your code is compiled with debugging
1703-
information or with the `-parameters` compiler flag on Java 8.
1702+
leave that detail out if the names are the same and your code is compiled with the `-parameters`
1703+
compiler flag.
17041704

17051705
The syntax `{varName:regex}` declares a URI variable with a regular expression that has
17061706
syntax of `{varName:regex}`. For example, given URL `"/spring-web-3.0.5.jar"`, the following method

spring-beans/src/test/java/org/springframework/beans/factory/support/QualifierAnnotationAutowireBeanFactoryTests.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2021 the original author or authors.
2+
* Copyright 2002-2022 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -27,7 +27,7 @@
2727
import org.springframework.beans.factory.annotation.Qualifier;
2828
import org.springframework.beans.factory.config.ConstructorArgumentValues;
2929
import org.springframework.beans.factory.config.DependencyDescriptor;
30-
import org.springframework.core.LocalVariableTableParameterNameDiscoverer;
30+
import org.springframework.core.DefaultParameterNameDiscoverer;
3131
import org.springframework.core.MethodParameter;
3232
import org.springframework.util.ClassUtils;
3333

@@ -148,7 +148,7 @@ public void testAutowireCandidateWithConstructorDescriptor() throws Exception {
148148
lbf.registerBeanDefinition(MARK, person2);
149149
MethodParameter param = new MethodParameter(QualifiedTestBean.class.getDeclaredConstructor(Person.class), 0);
150150
DependencyDescriptor qualifiedDescriptor = new DependencyDescriptor(param, false);
151-
param.initParameterNameDiscovery(new LocalVariableTableParameterNameDiscoverer());
151+
param.initParameterNameDiscovery(new DefaultParameterNameDiscoverer());
152152
assertThat(param.getParameterName()).isEqualTo("tpb");
153153
assertThat(lbf.isAutowireCandidate(JUERGEN, null)).isTrue();
154154
assertThat(lbf.isAutowireCandidate(JUERGEN, qualifiedDescriptor)).isTrue();
@@ -174,9 +174,9 @@ public void testAutowireCandidateWithMethodDescriptor() throws Exception {
174174
new MethodParameter(QualifiedTestBean.class.getDeclaredMethod("autowireNonqualified", Person.class), 0);
175175
DependencyDescriptor qualifiedDescriptor = new DependencyDescriptor(qualifiedParam, false);
176176
DependencyDescriptor nonqualifiedDescriptor = new DependencyDescriptor(nonqualifiedParam, false);
177-
qualifiedParam.initParameterNameDiscovery(new LocalVariableTableParameterNameDiscoverer());
177+
qualifiedParam.initParameterNameDiscovery(new DefaultParameterNameDiscoverer());
178178
assertThat(qualifiedParam.getParameterName()).isEqualTo("tpb");
179-
nonqualifiedParam.initParameterNameDiscovery(new LocalVariableTableParameterNameDiscoverer());
179+
nonqualifiedParam.initParameterNameDiscovery(new DefaultParameterNameDiscoverer());
180180
assertThat(nonqualifiedParam.getParameterName()).isEqualTo("tpb");
181181
assertThat(lbf.isAutowireCandidate(JUERGEN, null)).isTrue();
182182
assertThat(lbf.isAutowireCandidate(JUERGEN, nonqualifiedDescriptor)).isTrue();

spring-core/src/main/java/org/springframework/core/DefaultParameterNameDiscoverer.java

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,7 @@
1818

1919
/**
2020
* Default implementation of the {@link ParameterNameDiscoverer} strategy interface,
21-
* using the Java 8 standard reflection mechanism (if available), and falling back
22-
* to the ASM-based {@link LocalVariableTableParameterNameDiscoverer} (when not in
23-
* a native image) for checking debug information in the class file.
21+
* delegating to the Java 8 standard reflection mechanism.
2422
*
2523
* <p>If a Kotlin reflection implementation is present,
2624
* {@link KotlinReflectionParameterNameDiscoverer} is added first in the list and
@@ -33,7 +31,6 @@
3331
* @author Sam Brannen
3432
* @since 4.0
3533
* @see StandardReflectionParameterNameDiscoverer
36-
* @see LocalVariableTableParameterNameDiscoverer
3734
* @see KotlinReflectionParameterNameDiscoverer
3835
*/
3936
public class DefaultParameterNameDiscoverer extends PrioritizedParameterNameDiscoverer {
@@ -43,9 +40,6 @@ public DefaultParameterNameDiscoverer() {
4340
addDiscoverer(new KotlinReflectionParameterNameDiscoverer());
4441
}
4542
addDiscoverer(new StandardReflectionParameterNameDiscoverer());
46-
if (!NativeDetector.inNativeImage()) {
47-
addDiscoverer(new LocalVariableTableParameterNameDiscoverer());
48-
}
4943
}
5044

5145
}

spring-core/src/main/java/org/springframework/core/LocalVariableTableParameterNameDiscoverer.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,9 @@
5353
* @author Chris Beams
5454
* @author Sam Brannen
5555
* @since 2.0
56+
* @deprecated as of 6.0.1, in favor of {@link StandardReflectionParameterNameDiscoverer}
5657
*/
58+
@Deprecated
5759
public class LocalVariableTableParameterNameDiscoverer implements ParameterNameDiscoverer {
5860

5961
private static final Log logger = LogFactory.getLog(LocalVariableTableParameterNameDiscoverer.class);

spring-messaging/src/test/java/org/springframework/messaging/handler/annotation/support/PayloadMethodArgumentResolverTests.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2019 the original author or authors.
2+
* Copyright 2002-2022 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -26,7 +26,7 @@
2626
import org.junit.jupiter.api.BeforeEach;
2727
import org.junit.jupiter.api.Test;
2828

29-
import org.springframework.core.LocalVariableTableParameterNameDiscoverer;
29+
import org.springframework.core.DefaultParameterNameDiscoverer;
3030
import org.springframework.core.MethodParameter;
3131
import org.springframework.core.annotation.SynthesizingMethodParameter;
3232
import org.springframework.messaging.Message;
@@ -81,7 +81,7 @@ public void setup() throws Exception {
8181
this.paramAnnotatedRequired = new SynthesizingMethodParameter(payloadMethod, 2);
8282
this.paramWithSpelExpression = new SynthesizingMethodParameter(payloadMethod, 3);
8383
this.paramValidated = new SynthesizingMethodParameter(payloadMethod, 4);
84-
this.paramValidated.initParameterNameDiscovery(new LocalVariableTableParameterNameDiscoverer());
84+
this.paramValidated.initParameterNameDiscovery(new DefaultParameterNameDiscoverer());
8585
this.paramValidatedNotAnnotated = new SynthesizingMethodParameter(payloadMethod, 5);
8686
this.paramNotAnnotated = new SynthesizingMethodParameter(payloadMethod, 6);
8787
}

spring-messaging/src/test/java/org/springframework/messaging/handler/invocation/ResolvableMethod.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2019 the original author or authors.
2+
* Copyright 2002-2022 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -39,7 +39,7 @@
3939
import org.springframework.cglib.proxy.Enhancer;
4040
import org.springframework.cglib.proxy.Factory;
4141
import org.springframework.cglib.proxy.MethodProxy;
42-
import org.springframework.core.LocalVariableTableParameterNameDiscoverer;
42+
import org.springframework.core.DefaultParameterNameDiscoverer;
4343
import org.springframework.core.MethodIntrospector;
4444
import org.springframework.core.MethodParameter;
4545
import org.springframework.core.ParameterNameDiscoverer;
@@ -131,7 +131,7 @@ public class ResolvableMethod {
131131

132132
private static final SpringObjenesis objenesis = new SpringObjenesis();
133133

134-
private static final ParameterNameDiscoverer nameDiscoverer = new LocalVariableTableParameterNameDiscoverer();
134+
private static final ParameterNameDiscoverer nameDiscoverer = new DefaultParameterNameDiscoverer();
135135

136136
// Matches ValueConstants.DEFAULT_NONE (spring-web and spring-messaging)
137137
private static final String DEFAULT_VALUE_NONE = "\n\t\t\n\t\t\n\uE000\uE001\uE002\n\t\t\t\t\n";

spring-web/src/test/java/org/springframework/web/method/annotation/InitBinderDataBinderFactoryTests.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121

2222
import org.junit.jupiter.api.Test;
2323

24-
import org.springframework.core.LocalVariableTableParameterNameDiscoverer;
24+
import org.springframework.core.DefaultParameterNameDiscoverer;
2525
import org.springframework.core.convert.ConversionService;
2626
import org.springframework.format.support.DefaultFormattingConversionService;
2727
import org.springframework.web.bind.WebDataBinder;
@@ -128,7 +128,7 @@ private WebDataBinderFactory createFactory(String methodName, Class<?>... parame
128128
InvocableHandlerMethod handlerMethod = new InvocableHandlerMethod(handler, method);
129129
handlerMethod.setHandlerMethodArgumentResolvers(this.argumentResolvers);
130130
handlerMethod.setDataBinderFactory(new DefaultDataBinderFactory(null));
131-
handlerMethod.setParameterNameDiscoverer(new LocalVariableTableParameterNameDiscoverer());
131+
handlerMethod.setParameterNameDiscoverer(new DefaultParameterNameDiscoverer());
132132

133133
return new InitBinderDataBinderFactory(
134134
Collections.singletonList(handlerMethod), this.bindingInitializer);

spring-web/src/test/java/org/springframework/web/method/annotation/ModelFactoryTests.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2019 the original author or authors.
2+
* Copyright 2002-2022 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -22,7 +22,7 @@
2222
import org.junit.jupiter.api.BeforeEach;
2323
import org.junit.jupiter.api.Test;
2424

25-
import org.springframework.core.LocalVariableTableParameterNameDiscoverer;
25+
import org.springframework.core.DefaultParameterNameDiscoverer;
2626
import org.springframework.ui.Model;
2727
import org.springframework.ui.ModelMap;
2828
import org.springframework.validation.BindingResult;
@@ -252,7 +252,7 @@ private ModelFactory createModelFactory(String methodName, Class<?>... parameter
252252
InvocableHandlerMethod modelMethod = createHandlerMethod(methodName, parameterTypes);
253253
modelMethod.setHandlerMethodArgumentResolvers(resolvers);
254254
modelMethod.setDataBinderFactory(null);
255-
modelMethod.setParameterNameDiscoverer(new LocalVariableTableParameterNameDiscoverer());
255+
modelMethod.setParameterNameDiscoverer(new DefaultParameterNameDiscoverer());
256256

257257
return new ModelFactory(Collections.singletonList(modelMethod), null, this.attributeHandler);
258258
}

spring-web/src/testFixtures/java/org/springframework/web/testfixture/method/ResolvableMethod.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2019 the original author or authors.
2+
* Copyright 2002-2022 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -39,7 +39,7 @@
3939
import org.springframework.cglib.proxy.Enhancer;
4040
import org.springframework.cglib.proxy.Factory;
4141
import org.springframework.cglib.proxy.MethodProxy;
42-
import org.springframework.core.LocalVariableTableParameterNameDiscoverer;
42+
import org.springframework.core.DefaultParameterNameDiscoverer;
4343
import org.springframework.core.MethodIntrospector;
4444
import org.springframework.core.MethodParameter;
4545
import org.springframework.core.ParameterNameDiscoverer;
@@ -130,7 +130,7 @@ public class ResolvableMethod {
130130

131131
private static final SpringObjenesis objenesis = new SpringObjenesis();
132132

133-
private static final ParameterNameDiscoverer nameDiscoverer = new LocalVariableTableParameterNameDiscoverer();
133+
private static final ParameterNameDiscoverer nameDiscoverer = new DefaultParameterNameDiscoverer();
134134

135135
// Matches ValueConstants.DEFAULT_NONE (spring-web and spring-messaging)
136136
private static final String DEFAULT_VALUE_NONE = "\n\t\t\n\t\t\n\uE000\uE001\uE002\n\t\t\t\t\n";

spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/InitBinderBindingContextTests.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323

2424
import org.junit.jupiter.api.Test;
2525

26-
import org.springframework.core.LocalVariableTableParameterNameDiscoverer;
26+
import org.springframework.core.DefaultParameterNameDiscoverer;
2727
import org.springframework.core.ReactiveAdapterRegistry;
2828
import org.springframework.core.convert.ConversionService;
2929
import org.springframework.format.support.DefaultFormattingConversionService;
@@ -131,7 +131,7 @@ private BindingContext createBindingContext(String methodName, Class<?>... param
131131

132132
SyncInvocableHandlerMethod handlerMethod = new SyncInvocableHandlerMethod(handler, method);
133133
handlerMethod.setArgumentResolvers(new ArrayList<>(this.argumentResolvers));
134-
handlerMethod.setParameterNameDiscoverer(new LocalVariableTableParameterNameDiscoverer());
134+
handlerMethod.setParameterNameDiscoverer(new DefaultParameterNameDiscoverer());
135135

136136
return new InitBinderBindingContext(this.bindingInitializer, Collections.singletonList(handlerMethod));
137137
}

spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/RequestPartMethodArgumentResolverTests.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
import org.junit.jupiter.api.BeforeEach;
3333
import org.junit.jupiter.api.Test;
3434

35-
import org.springframework.core.LocalVariableTableParameterNameDiscoverer;
35+
import org.springframework.core.DefaultParameterNameDiscoverer;
3636
import org.springframework.core.MethodParameter;
3737
import org.springframework.core.annotation.SynthesizingMethodParameter;
3838
import org.springframework.http.HttpInputMessage;
@@ -137,28 +137,28 @@ public InputStream getInputStream() throws IOException {
137137

138138
Method method = ReflectionUtils.findMethod(getClass(), "handle", (Class<?>[]) null);
139139
paramRequestPart = new SynthesizingMethodParameter(method, 0);
140-
paramRequestPart.initParameterNameDiscovery(new LocalVariableTableParameterNameDiscoverer());
140+
paramRequestPart.initParameterNameDiscovery(new DefaultParameterNameDiscoverer());
141141
paramNamedRequestPart = new SynthesizingMethodParameter(method, 1);
142142
paramValidRequestPart = new SynthesizingMethodParameter(method, 2);
143143
paramMultipartFile = new SynthesizingMethodParameter(method, 3);
144144
paramMultipartFileList = new SynthesizingMethodParameter(method, 4);
145145
paramMultipartFileArray = new SynthesizingMethodParameter(method, 5);
146146
paramInt = new SynthesizingMethodParameter(method, 6);
147147
paramMultipartFileNotAnnot = new SynthesizingMethodParameter(method, 7);
148-
paramMultipartFileNotAnnot.initParameterNameDiscovery(new LocalVariableTableParameterNameDiscoverer());
148+
paramMultipartFileNotAnnot.initParameterNameDiscovery(new DefaultParameterNameDiscoverer());
149149
paramPart = new SynthesizingMethodParameter(method, 8);
150-
paramPart.initParameterNameDiscovery(new LocalVariableTableParameterNameDiscoverer());
150+
paramPart.initParameterNameDiscovery(new DefaultParameterNameDiscoverer());
151151
paramPartList = new SynthesizingMethodParameter(method, 9);
152152
paramPartArray = new SynthesizingMethodParameter(method, 10);
153153
paramRequestParamAnnot = new SynthesizingMethodParameter(method, 11);
154154
optionalMultipartFile = new SynthesizingMethodParameter(method, 12);
155-
optionalMultipartFile.initParameterNameDiscovery(new LocalVariableTableParameterNameDiscoverer());
155+
optionalMultipartFile.initParameterNameDiscovery(new DefaultParameterNameDiscoverer());
156156
optionalMultipartFileList = new SynthesizingMethodParameter(method, 13);
157-
optionalMultipartFileList.initParameterNameDiscovery(new LocalVariableTableParameterNameDiscoverer());
157+
optionalMultipartFileList.initParameterNameDiscovery(new DefaultParameterNameDiscoverer());
158158
optionalPart = new SynthesizingMethodParameter(method, 14);
159-
optionalPart.initParameterNameDiscovery(new LocalVariableTableParameterNameDiscoverer());
159+
optionalPart.initParameterNameDiscovery(new DefaultParameterNameDiscoverer());
160160
optionalPartList = new SynthesizingMethodParameter(method, 15);
161-
optionalPartList.initParameterNameDiscovery(new LocalVariableTableParameterNameDiscoverer());
161+
optionalPartList.initParameterNameDiscovery(new DefaultParameterNameDiscoverer());
162162
optionalRequestPart = new SynthesizingMethodParameter(method, 16);
163163
}
164164

0 commit comments

Comments
 (0)