Retain default LocalVariableTableParameterNameDiscoverer with warn log entries
For a transition period, LocalVariableTableParameterNameDiscoverer logs a warning for each successful resolution attempt now, suggesting that -parameters was missed. See gh-29531 See gh-29559
This commit is contained in:
parent
ed5ab77397
commit
fe5bd6751f
|
@ -18,7 +18,8 @@ package org.springframework.core;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Default implementation of the {@link ParameterNameDiscoverer} strategy interface,
|
* Default implementation of the {@link ParameterNameDiscoverer} strategy interface,
|
||||||
* delegating to the Java 8 standard reflection mechanism.
|
* delegating to the Java 8 standard reflection mechanism, with a deprecated fallback
|
||||||
|
* to {@link LocalVariableTableParameterNameDiscoverer}.
|
||||||
*
|
*
|
||||||
* <p>If a Kotlin reflection implementation is present,
|
* <p>If a Kotlin reflection implementation is present,
|
||||||
* {@link KotlinReflectionParameterNameDiscoverer} is added first in the list and
|
* {@link KotlinReflectionParameterNameDiscoverer} is added first in the list and
|
||||||
|
@ -35,11 +36,20 @@ package org.springframework.core;
|
||||||
*/
|
*/
|
||||||
public class DefaultParameterNameDiscoverer extends PrioritizedParameterNameDiscoverer {
|
public class DefaultParameterNameDiscoverer extends PrioritizedParameterNameDiscoverer {
|
||||||
|
|
||||||
|
@SuppressWarnings("removal")
|
||||||
public DefaultParameterNameDiscoverer() {
|
public DefaultParameterNameDiscoverer() {
|
||||||
if (KotlinDetector.isKotlinReflectPresent()) {
|
if (KotlinDetector.isKotlinReflectPresent()) {
|
||||||
addDiscoverer(new KotlinReflectionParameterNameDiscoverer());
|
addDiscoverer(new KotlinReflectionParameterNameDiscoverer());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Recommended approach on Java 8+: compilation with -parameters.
|
||||||
addDiscoverer(new StandardReflectionParameterNameDiscoverer());
|
addDiscoverer(new StandardReflectionParameterNameDiscoverer());
|
||||||
|
|
||||||
|
// Deprecated fallback to class file parsing for -debug symbols.
|
||||||
|
// Does not work on native images without class file resources.
|
||||||
|
if (!NativeDetector.inNativeImage()) {
|
||||||
|
addDiscoverer(new LocalVariableTableParameterNameDiscoverer());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -56,7 +56,7 @@ import org.springframework.util.ClassUtils;
|
||||||
* @deprecated as of 6.0.1, in favor of {@link StandardReflectionParameterNameDiscoverer}
|
* @deprecated as of 6.0.1, in favor of {@link StandardReflectionParameterNameDiscoverer}
|
||||||
* (with the "-parameters" compiler flag)
|
* (with the "-parameters" compiler flag)
|
||||||
*/
|
*/
|
||||||
@Deprecated(since = "6.0.1")
|
@Deprecated(since = "6.0.1", forRemoval = true)
|
||||||
public class LocalVariableTableParameterNameDiscoverer implements ParameterNameDiscoverer {
|
public class LocalVariableTableParameterNameDiscoverer implements ParameterNameDiscoverer {
|
||||||
|
|
||||||
private static final Log logger = LogFactory.getLog(LocalVariableTableParameterNameDiscoverer.class);
|
private static final Log logger = LogFactory.getLog(LocalVariableTableParameterNameDiscoverer.class);
|
||||||
|
@ -85,7 +85,12 @@ public class LocalVariableTableParameterNameDiscoverer implements ParameterNameD
|
||||||
private String[] doGetParameterNames(Executable executable) {
|
private String[] doGetParameterNames(Executable executable) {
|
||||||
Class<?> declaringClass = executable.getDeclaringClass();
|
Class<?> declaringClass = executable.getDeclaringClass();
|
||||||
Map<Executable, String[]> map = this.parameterNamesCache.computeIfAbsent(declaringClass, this::inspectClass);
|
Map<Executable, String[]> map = this.parameterNamesCache.computeIfAbsent(declaringClass, this::inspectClass);
|
||||||
return (map != NO_DEBUG_INFO_MAP ? map.get(executable) : null);
|
String[] names = (map != NO_DEBUG_INFO_MAP ? map.get(executable) : null);
|
||||||
|
if (names != null && logger.isWarnEnabled()) {
|
||||||
|
logger.warn("Using deprecated '-debug' fallback for parameter name resolution. " +
|
||||||
|
"Compile the affected code with '-parameters' instead: " + executable);
|
||||||
|
}
|
||||||
|
return names;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2021 the original author or authors.
|
* Copyright 2002-2022 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
@ -339,11 +339,7 @@ public class ReactiveAdapterRegistry {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@code BlockHoundIntegration} for spring-core classes.
|
* {@code BlockHoundIntegration} for spring-core classes.
|
||||||
* <p>Explicitly allow the following:
|
* Explicitly allows locking within {@link ConcurrentReferenceHashMap}.
|
||||||
* <ul>
|
|
||||||
* <li>Reading class info via {@link LocalVariableTableParameterNameDiscoverer}.
|
|
||||||
* <li>Locking within {@link ConcurrentReferenceHashMap}.
|
|
||||||
* </ul>
|
|
||||||
* @since 5.2.4
|
* @since 5.2.4
|
||||||
*/
|
*/
|
||||||
public static class SpringCoreBlockHoundIntegration implements BlockHoundIntegration {
|
public static class SpringCoreBlockHoundIntegration implements BlockHoundIntegration {
|
||||||
|
@ -352,9 +348,6 @@ public class ReactiveAdapterRegistry {
|
||||||
public void applyTo(BlockHound.Builder builder) {
|
public void applyTo(BlockHound.Builder builder) {
|
||||||
// Avoid hard references potentially anywhere in spring-core (no need for structural dependency)
|
// Avoid hard references potentially anywhere in spring-core (no need for structural dependency)
|
||||||
|
|
||||||
builder.allowBlockingCallsInside(
|
|
||||||
"org.springframework.core.LocalVariableTableParameterNameDiscoverer", "inspectClass");
|
|
||||||
|
|
||||||
String className = "org.springframework.util.ConcurrentReferenceHashMap$Segment";
|
String className = "org.springframework.util.ConcurrentReferenceHashMap$Segment";
|
||||||
builder.allowBlockingCallsInside(className, "doTask");
|
builder.allowBlockingCallsInside(className, "doTask");
|
||||||
builder.allowBlockingCallsInside(className, "clear");
|
builder.allowBlockingCallsInside(className, "clear");
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2019 the original author or authors.
|
* Copyright 2002-2022 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
@ -34,7 +34,8 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||||
*/
|
*/
|
||||||
class LocalVariableTableParameterNameDiscovererTests {
|
class LocalVariableTableParameterNameDiscovererTests {
|
||||||
|
|
||||||
private final LocalVariableTableParameterNameDiscoverer discoverer = new LocalVariableTableParameterNameDiscoverer();
|
@SuppressWarnings("removal")
|
||||||
|
private final ParameterNameDiscoverer discoverer = new LocalVariableTableParameterNameDiscoverer();
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
|
@ -16,7 +16,6 @@
|
||||||
|
|
||||||
package org.springframework.core;
|
package org.springframework.core;
|
||||||
|
|
||||||
import java.lang.reflect.Method;
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.concurrent.CompletableFuture;
|
import java.util.concurrent.CompletableFuture;
|
||||||
|
|
||||||
|
@ -28,7 +27,6 @@ import reactor.blockhound.BlockHound;
|
||||||
import reactor.core.scheduler.ReactorBlockHoundIntegration;
|
import reactor.core.scheduler.ReactorBlockHoundIntegration;
|
||||||
import reactor.core.scheduler.Schedulers;
|
import reactor.core.scheduler.Schedulers;
|
||||||
|
|
||||||
import org.springframework.tests.sample.objects.TestObject;
|
|
||||||
import org.springframework.util.ConcurrentReferenceHashMap;
|
import org.springframework.util.ConcurrentReferenceHashMap;
|
||||||
|
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
@ -52,11 +50,10 @@ import static org.assertj.core.api.Assertions.assertThatThrownBy;
|
||||||
@DisabledOnJre(value= {JRE.JAVA_18, JRE.JAVA_19}, disabledReason = "BlockHound is not compatible with Java 18+")
|
@DisabledOnJre(value= {JRE.JAVA_18, JRE.JAVA_19}, disabledReason = "BlockHound is not compatible with Java 18+")
|
||||||
class SpringCoreBlockHoundIntegrationTests {
|
class SpringCoreBlockHoundIntegrationTests {
|
||||||
|
|
||||||
|
|
||||||
@BeforeAll
|
@BeforeAll
|
||||||
static void setUp() {
|
static void setup() {
|
||||||
BlockHound.builder()
|
BlockHound.builder()
|
||||||
.with(new ReactorBlockHoundIntegration()) // Reactor non-blocking thread predicate
|
.with(new ReactorBlockHoundIntegration()) // Reactor non-blocking thread predicate
|
||||||
.with(new ReactiveAdapterRegistry.SpringCoreBlockHoundIntegration())
|
.with(new ReactiveAdapterRegistry.SpringCoreBlockHoundIntegration())
|
||||||
.install();
|
.install();
|
||||||
}
|
}
|
||||||
|
@ -68,15 +65,6 @@ class SpringCoreBlockHoundIntegrationTests {
|
||||||
.hasMessageContaining("Blocking call!");
|
.hasMessageContaining("Blocking call!");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
|
||||||
void localVariableTableParameterNameDiscoverer() {
|
|
||||||
testNonBlockingTask(() -> {
|
|
||||||
Method setName = TestObject.class.getMethod("setName", String.class);
|
|
||||||
String[] names = new LocalVariableTableParameterNameDiscoverer().getParameterNames(setName);
|
|
||||||
assertThat(names).containsExactly("name");
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void concurrentReferenceHashMap() {
|
void concurrentReferenceHashMap() {
|
||||||
int size = 10000;
|
int size = 10000;
|
||||||
|
|
Loading…
Reference in New Issue