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:
@@ -18,7 +18,8 @@ package org.springframework.core;
|
||||
|
||||
/**
|
||||
* 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,
|
||||
* {@link KotlinReflectionParameterNameDiscoverer} is added first in the list and
|
||||
@@ -35,11 +36,20 @@ package org.springframework.core;
|
||||
*/
|
||||
public class DefaultParameterNameDiscoverer extends PrioritizedParameterNameDiscoverer {
|
||||
|
||||
@SuppressWarnings("removal")
|
||||
public DefaultParameterNameDiscoverer() {
|
||||
if (KotlinDetector.isKotlinReflectPresent()) {
|
||||
addDiscoverer(new KotlinReflectionParameterNameDiscoverer());
|
||||
}
|
||||
|
||||
// Recommended approach on Java 8+: compilation with -parameters.
|
||||
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}
|
||||
* (with the "-parameters" compiler flag)
|
||||
*/
|
||||
@Deprecated(since = "6.0.1")
|
||||
@Deprecated(since = "6.0.1", forRemoval = true)
|
||||
public class LocalVariableTableParameterNameDiscoverer implements ParameterNameDiscoverer {
|
||||
|
||||
private static final Log logger = LogFactory.getLog(LocalVariableTableParameterNameDiscoverer.class);
|
||||
@@ -85,7 +85,12 @@ public class LocalVariableTableParameterNameDiscoverer implements ParameterNameD
|
||||
private String[] doGetParameterNames(Executable executable) {
|
||||
Class<?> declaringClass = executable.getDeclaringClass();
|
||||
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");
|
||||
* 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.
|
||||
* <p>Explicitly allow the following:
|
||||
* <ul>
|
||||
* <li>Reading class info via {@link LocalVariableTableParameterNameDiscoverer}.
|
||||
* <li>Locking within {@link ConcurrentReferenceHashMap}.
|
||||
* </ul>
|
||||
* Explicitly allows locking within {@link ConcurrentReferenceHashMap}.
|
||||
* @since 5.2.4
|
||||
*/
|
||||
public static class SpringCoreBlockHoundIntegration implements BlockHoundIntegration {
|
||||
@@ -352,9 +348,6 @@ public class ReactiveAdapterRegistry {
|
||||
public void applyTo(BlockHound.Builder builder) {
|
||||
// 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";
|
||||
builder.allowBlockingCallsInside(className, "doTask");
|
||||
builder.allowBlockingCallsInside(className, "clear");
|
||||
|
||||
Reference in New Issue
Block a user