Merge branch '6.1.x'

This commit is contained in:
Juergen Hoeller 2024-10-16 11:36:30 +02:00
commit fb6a6892ef
12 changed files with 72 additions and 118 deletions

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2023 the original author or authors. * Copyright 2002-2024 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.
@ -29,9 +29,11 @@ import org.springframework.util.ObjectUtils;
/** /**
* A simple descriptor for an injection point, pointing to a method/constructor * A simple descriptor for an injection point, pointing to a method/constructor
* parameter or a field. Exposed by {@link UnsatisfiedDependencyException}. * parameter or a field.
* Also available as an argument for factory methods, reacting to the *
* requesting injection point for building a customized bean instance. * <p>Exposed by {@link UnsatisfiedDependencyException}. Also available as an
* argument for factory methods, reacting to the requesting injection point
* for building a customized bean instance.
* *
* @author Juergen Hoeller * @author Juergen Hoeller
* @since 4.3 * @since 4.3

View File

@ -64,8 +64,8 @@ class DefaultBeanRegistrationCodeFragments implements BeanRegistrationCodeFragme
private final Supplier<InstantiationDescriptor> instantiationDescriptor; private final Supplier<InstantiationDescriptor> instantiationDescriptor;
DefaultBeanRegistrationCodeFragments(BeanRegistrationsCode beanRegistrationsCode, DefaultBeanRegistrationCodeFragments(
RegisteredBean registeredBean, BeanRegistrationsCode beanRegistrationsCode, RegisteredBean registeredBean,
BeanDefinitionMethodGeneratorFactory beanDefinitionMethodGeneratorFactory) { BeanDefinitionMethodGeneratorFactory beanDefinitionMethodGeneratorFactory) {
this.beanRegistrationsCode = beanRegistrationsCode; this.beanRegistrationsCode = beanRegistrationsCode;

View File

@ -148,10 +148,10 @@ public class DependencyDescriptor extends InjectionPoint implements Serializable
this.parameterTypes = original.parameterTypes; this.parameterTypes = original.parameterTypes;
this.parameterIndex = original.parameterIndex; this.parameterIndex = original.parameterIndex;
this.fieldName = original.fieldName; this.fieldName = original.fieldName;
this.containingClass = original.containingClass;
this.required = original.required; this.required = original.required;
this.eager = original.eager; this.eager = original.eager;
this.nestingLevel = original.nestingLevel; this.nestingLevel = original.nestingLevel;
this.containingClass = original.containingClass;
} }

View File

@ -518,8 +518,8 @@ public class DefaultListableBeanFactory extends AbstractAutowireCapableBeanFacto
return namedBean.getBeanInstance(); return namedBean.getBeanInstance();
} }
BeanFactory parent = getParentBeanFactory(); BeanFactory parent = getParentBeanFactory();
if (parent instanceof DefaultListableBeanFactory dlfb) { if (parent instanceof DefaultListableBeanFactory dlbf) {
return dlfb.resolveBean(requiredType, args, nonUniqueAsNull); return dlbf.resolveBean(requiredType, args, nonUniqueAsNull);
} }
else if (parent != null) { else if (parent != null) {
ObjectProvider<T> parentProvider = parent.getBeanProvider(requiredType); ObjectProvider<T> parentProvider = parent.getBeanProvider(requiredType);

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2023 the original author or authors. * Copyright 2002-2024 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.
@ -45,11 +45,13 @@ public final class AccessControl {
private final Visibility visibility; private final Visibility visibility;
AccessControl(Class<?> target, Visibility visibility) { AccessControl(Class<?> target, Visibility visibility) {
this.target = target; this.target = target;
this.visibility = visibility; this.visibility = visibility;
} }
/** /**
* Create an {@link AccessControl} for the given member. This considers the * Create an {@link AccessControl} for the given member. This considers the
* member modifier, parameter types, return types and any enclosing classes. * member modifier, parameter types, return types and any enclosing classes.
@ -68,8 +70,7 @@ public final class AccessControl {
* @return the {@link AccessControl} for the type * @return the {@link AccessControl} for the type
*/ */
public static AccessControl forResolvableType(ResolvableType resolvableType) { public static AccessControl forResolvableType(ResolvableType resolvableType) {
return new AccessControl(resolvableType.toClass(), return new AccessControl(resolvableType.toClass(), Visibility.forResolvableType(resolvableType));
Visibility.forResolvableType(resolvableType));
} }
/** /**
@ -87,8 +88,8 @@ public final class AccessControl {
* @return the lowest {@link AccessControl} from the candidates * @return the lowest {@link AccessControl} from the candidates
*/ */
public static AccessControl lowest(AccessControl... candidates) { public static AccessControl lowest(AccessControl... candidates) {
int index = Visibility.lowestIndex(Arrays.stream(candidates) int index = Visibility.lowestIndex(
.map(AccessControl::getVisibility).toArray(Visibility[]::new)); Arrays.stream(candidates).map(AccessControl::getVisibility).toArray(Visibility[]::new));
return candidates[index]; return candidates[index];
} }
@ -125,6 +126,7 @@ public final class AccessControl {
return this.target.getPackageName().equals(type.packageName()); return this.target.getPackageName().equals(type.packageName());
} }
/** /**
* Access visibility types as determined by the <a href= * Access visibility types as determined by the <a href=
* "https://docs.oracle.com/javase/tutorial/java/javaOO/accesscontrol.html">modifiers</a> * "https://docs.oracle.com/javase/tutorial/java/javaOO/accesscontrol.html">modifiers</a>
@ -270,6 +272,6 @@ public final class AccessControl {
} }
return index; return index;
} }
} }
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2023 the original author or authors. * Copyright 2002-2024 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.
@ -28,21 +28,22 @@ import org.springframework.lang.Nullable;
* @author Brian Clozel * @author Brian Clozel
* @since 6.0 * @since 6.0
*/ */
public class JavaSerializationHint implements ConditionalHint { public final class JavaSerializationHint implements ConditionalHint {
private final TypeReference type; private final TypeReference type;
@Nullable @Nullable
private final TypeReference reachableType; private final TypeReference reachableType;
JavaSerializationHint(Builder builder) { JavaSerializationHint(Builder builder) {
this.type = builder.type; this.type = builder.type;
this.reachableType = builder.reachableType; this.reachableType = builder.reachableType;
} }
/** /**
* Return the {@link TypeReference type} that needs to be serialized using * Return the {@link TypeReference type} that needs to be serialized using Java serialization at runtime.
* Java serialization at runtime.
* @return a {@link Serializable} type * @return a {@link Serializable} type
*/ */
public TypeReference getType() { public TypeReference getType() {
@ -56,16 +57,9 @@ public class JavaSerializationHint implements ConditionalHint {
} }
@Override @Override
public boolean equals(@Nullable Object o) { public boolean equals(@Nullable Object other) {
if (this == o) { return (this == other || (other instanceof JavaSerializationHint that &&
return true; this.type.equals(that.type) && Objects.equals(this.reachableType, that.reachableType)));
}
if (o == null || getClass() != o.getClass()) {
return false;
}
JavaSerializationHint that = (JavaSerializationHint) o;
return this.type.equals(that.type)
&& Objects.equals(this.reachableType, that.reachableType);
} }
@Override @Override
@ -84,16 +78,13 @@ public class JavaSerializationHint implements ConditionalHint {
@Nullable @Nullable
private TypeReference reachableType; private TypeReference reachableType;
Builder(TypeReference type) { Builder(TypeReference type) {
this.type = type; this.type = type;
} }
/** /**
* Make this hint conditional on the fact that the specified type * Make this hint conditional on the fact that the specified type can be resolved.
* can be resolved. * @param reachableType the type that should be reachable for this hint to apply
* @param reachableType the type that should be reachable for this
* hint to apply
* @return {@code this}, to facilitate method chaining * @return {@code this}, to facilitate method chaining
*/ */
public Builder onReachableType(TypeReference reachableType) { public Builder onReachableType(TypeReference reachableType) {
@ -108,6 +99,6 @@ public class JavaSerializationHint implements ConditionalHint {
JavaSerializationHint build() { JavaSerializationHint build() {
return new JavaSerializationHint(this); return new JavaSerializationHint(this);
} }
} }
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2023 the original author or authors. * Copyright 2002-2024 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.
@ -62,6 +62,7 @@ public final class JdkProxyHint implements ConditionalHint {
return new Builder().proxiedInterfaces(proxiedInterfaces); return new Builder().proxiedInterfaces(proxiedInterfaces);
} }
/** /**
* Return the interfaces to be proxied. * Return the interfaces to be proxied.
* @return the interfaces that the proxy should implement * @return the interfaces that the proxy should implement
@ -77,16 +78,10 @@ public final class JdkProxyHint implements ConditionalHint {
} }
@Override @Override
public boolean equals(@Nullable Object o) { public boolean equals(@Nullable Object other) {
if (this == o) { return (this == other || (other instanceof JdkProxyHint that &&
return true; this.proxiedInterfaces.equals(that.proxiedInterfaces) &&
} Objects.equals(this.reachableType, that.reachableType)));
if (o == null || getClass() != o.getClass()) {
return false;
}
JdkProxyHint that = (JdkProxyHint) o;
return this.proxiedInterfaces.equals(that.proxiedInterfaces)
&& Objects.equals(this.reachableType, that.reachableType);
} }
@Override @Override
@ -105,7 +100,6 @@ public final class JdkProxyHint implements ConditionalHint {
@Nullable @Nullable
private TypeReference reachableType; private TypeReference reachableType;
Builder() { Builder() {
this.proxiedInterfaces = new LinkedList<>(); this.proxiedInterfaces = new LinkedList<>();
} }
@ -131,10 +125,8 @@ public final class JdkProxyHint implements ConditionalHint {
} }
/** /**
* Make this hint conditional on the fact that the specified type * Make this hint conditional on the fact that the specified type can be resolved.
* can be resolved. * @param reachableType the type that should be reachable for this hint to apply
* @param reachableType the type that should be reachable for this
* hint to apply
* @return {@code this}, to facilitate method chaining * @return {@code this}, to facilitate method chaining
*/ */
public Builder onReachableType(TypeReference reachableType) { public Builder onReachableType(TypeReference reachableType) {
@ -160,7 +152,6 @@ public final class JdkProxyHint implements ConditionalHint {
} }
return TypeReference.listOf(proxiedInterfaces); return TypeReference.listOf(proxiedInterfaces);
} }
} }
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2023 the original author or authors. * Copyright 2002-2024 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.
@ -41,9 +41,9 @@ public final class ResourceBundleHint implements ConditionalHint {
this.reachableType = builder.reachableType; this.reachableType = builder.reachableType;
} }
/** /**
* Return the {@code baseName} of the resource bundle. * Return the {@code baseName} of the resource bundle.
* @return the base name
*/ */
public String getBaseName() { public String getBaseName() {
return this.baseName; return this.baseName;
@ -56,16 +56,9 @@ public final class ResourceBundleHint implements ConditionalHint {
} }
@Override @Override
public boolean equals(@Nullable Object o) { public boolean equals(@Nullable Object other) {
if (this == o) { return (this == other || (other instanceof ResourceBundleHint that &&
return true; this.baseName.equals(that.baseName) && Objects.equals(this.reachableType, that.reachableType)));
}
if (o == null || getClass() != o.getClass()) {
return false;
}
ResourceBundleHint that = (ResourceBundleHint) o;
return this.baseName.equals(that.baseName)
&& Objects.equals(this.reachableType, that.reachableType);
} }
@Override @Override
@ -73,6 +66,7 @@ public final class ResourceBundleHint implements ConditionalHint {
return Objects.hash(this.baseName, this.reachableType); return Objects.hash(this.baseName, this.reachableType);
} }
/** /**
* Builder for {@link ResourceBundleHint}. * Builder for {@link ResourceBundleHint}.
*/ */
@ -88,10 +82,8 @@ public final class ResourceBundleHint implements ConditionalHint {
} }
/** /**
* Make this hint conditional on the fact that the specified type * Make this hint conditional on the fact that the specified type can be resolved.
* can be resolved. * @param reachableType the type that should be reachable for this hint to apply
* @param reachableType the type that should be reachable for this
* hint to apply
* @return {@code this}, to facilitate method chaining * @return {@code this}, to facilitate method chaining
*/ */
public Builder onReachableType(TypeReference reachableType) { public Builder onReachableType(TypeReference reachableType) {
@ -109,14 +101,12 @@ public final class ResourceBundleHint implements ConditionalHint {
} }
/** /**
* Creates a {@link ResourceBundleHint} based on the state of this * Create a {@link ResourceBundleHint} based on the state of this builder.
* builder.
* @return a resource bundle hint * @return a resource bundle hint
*/ */
ResourceBundleHint build() { ResourceBundleHint build() {
return new ResourceBundleHint(this); return new ResourceBundleHint(this);
} }
} }
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2023 the original author or authors. * Copyright 2002-2024 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.
@ -71,7 +71,6 @@ public final class ResourcePatternHint implements ConditionalHint {
/** /**
* Return the pattern to use for identifying the resources to match. * Return the pattern to use for identifying the resources to match.
* @return the pattern
*/ */
public String getPattern() { public String getPattern() {
return this.pattern; return this.pattern;
@ -79,7 +78,6 @@ public final class ResourcePatternHint implements ConditionalHint {
/** /**
* Return the regex {@link Pattern} to use for identifying the resources to match. * Return the regex {@link Pattern} to use for identifying the resources to match.
* @return the regex pattern
*/ */
public Pattern toRegex() { public Pattern toRegex() {
String prefix = (this.pattern.startsWith("*") ? ".*" : ""); String prefix = (this.pattern.startsWith("*") ? ".*" : "");
@ -98,16 +96,9 @@ public final class ResourcePatternHint implements ConditionalHint {
} }
@Override @Override
public boolean equals(@Nullable Object o) { public boolean equals(@Nullable Object other) {
if (this == o) { return (this == other || (other instanceof ResourcePatternHint that &&
return true; this.pattern.equals(that.pattern) && Objects.equals(this.reachableType, that.reachableType)));
}
if (o == null || getClass() != o.getClass()) {
return false;
}
ResourcePatternHint that = (ResourcePatternHint) o;
return this.pattern.equals(that.pattern)
&& Objects.equals(this.reachableType, that.reachableType);
} }
@Override @Override

View File

@ -74,6 +74,7 @@ public final class TypeHint implements ConditionalHint {
return new Builder(type); return new Builder(type);
} }
/** /**
* Return the type that this hint handles. * Return the type that this hint handles.
* @return the type * @return the type
@ -154,16 +155,14 @@ public final class TypeHint implements ConditionalHint {
private final Set<MemberCategory> memberCategories = new HashSet<>(); private final Set<MemberCategory> memberCategories = new HashSet<>();
Builder(TypeReference type) { Builder(TypeReference type) {
this.type = type; this.type = type;
} }
/** /**
* Make this hint conditional on the fact that the specified type * Make this hint conditional on the fact that the specified type is in a
* is in a reachable code path from a static analysis point of view. * reachable code path from a static analysis point of view.
* @param reachableType the type that should be reachable for this * @param reachableType the type that should be reachable for this hint to apply
* hint to apply
* @return {@code this}, to facilitate method chaining * @return {@code this}, to facilitate method chaining
*/ */
public Builder onReachableType(TypeReference reachableType) { public Builder onReachableType(TypeReference reachableType) {
@ -172,10 +171,9 @@ public final class TypeHint implements ConditionalHint {
} }
/** /**
* Make this hint conditional on the fact that the specified type * Make this hint conditional on the fact that the specified type is in a
* is in a reachable code path from a static analysis point of view. * reachable code path from a static analysis point of view.
* @param reachableType the type that should be reachable for this * @param reachableType the type that should be reachable for this hint to apply
* hint to apply
* @return {@code this}, to facilitate method chaining * @return {@code this}, to facilitate method chaining
*/ */
public Builder onReachableType(Class<?> reachableType) { public Builder onReachableType(Class<?> reachableType) {
@ -212,8 +210,9 @@ public final class TypeHint implements ConditionalHint {
* constructor * constructor
* @return {@code this}, to facilitate method chaining * @return {@code this}, to facilitate method chaining
*/ */
private Builder withConstructor(List<TypeReference> parameterTypes, private Builder withConstructor(
Consumer<ExecutableHint.Builder> constructorHint) { List<TypeReference> parameterTypes, Consumer<ExecutableHint.Builder> constructorHint) {
ExecutableKey key = new ExecutableKey("<init>", parameterTypes); ExecutableKey key = new ExecutableKey("<init>", parameterTypes);
ExecutableHint.Builder builder = this.constructors.computeIfAbsent(key, ExecutableHint.Builder builder = this.constructors.computeIfAbsent(key,
k -> ExecutableHint.ofConstructor(parameterTypes)); k -> ExecutableHint.ofConstructor(parameterTypes));
@ -268,38 +267,30 @@ public final class TypeHint implements ConditionalHint {
TypeHint build() { TypeHint build() {
return new TypeHint(this); return new TypeHint(this);
} }
} }
private static final class ExecutableKey { private static final class ExecutableKey {
private final String name; private final String name;
private final List<String> parameterTypes; private final List<String> parameterTypes;
private ExecutableKey(String name, List<TypeReference> parameterTypes) { private ExecutableKey(String name, List<TypeReference> parameterTypes) {
this.name = name; this.name = name;
this.parameterTypes = parameterTypes.stream().map(TypeReference::getCanonicalName).toList(); this.parameterTypes = parameterTypes.stream().map(TypeReference::getCanonicalName).toList();
} }
@Override @Override
public boolean equals(@Nullable Object o) { public boolean equals(@Nullable Object other) {
if (this == o) { return (this == other || (other instanceof ExecutableKey that &&
return true; this.name.equals(that.name) && this.parameterTypes.equals(that.parameterTypes)));
}
if (o == null || getClass() != o.getClass()) {
return false;
}
ExecutableKey that = (ExecutableKey) o;
return this.name.equals(that.name) && this.parameterTypes.equals(that.parameterTypes);
} }
@Override @Override
public int hashCode() { public int hashCode() {
return Objects.hash(this.name, this.parameterTypes); return Objects.hash(this.name, this.parameterTypes);
} }
} }
} }

View File

@ -192,7 +192,6 @@ class DefaultServerHttpRequestBuilder implements ServerHttpRequest.Builder {
private final ServerHttpRequest originalRequest; private final ServerHttpRequest originalRequest;
public MutatedServerHttpRequest(URI uri, @Nullable String contextPath, public MutatedServerHttpRequest(URI uri, @Nullable String contextPath,
HttpMethod method, @Nullable SslInfo sslInfo, @Nullable InetSocketAddress remoteAddress, HttpMethod method, @Nullable SslInfo sslInfo, @Nullable InetSocketAddress remoteAddress,
HttpHeaders headers, Flux<DataBuffer> body, ServerHttpRequest originalRequest) { HttpHeaders headers, Flux<DataBuffer> body, ServerHttpRequest originalRequest) {
@ -232,7 +231,6 @@ class DefaultServerHttpRequestBuilder implements ServerHttpRequest.Builder {
return this.body; return this.body;
} }
@SuppressWarnings("unchecked")
@Override @Override
public <T> T getNativeRequest() { public <T> T getNativeRequest() {
return ServerHttpRequestDecorator.getNativeRequest(this.originalRequest); return ServerHttpRequestDecorator.getNativeRequest(this.originalRequest);

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2022 the original author or authors. * Copyright 2002-2024 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.
@ -119,6 +119,11 @@ public class ServerHttpRequestDecorator implements ServerHttpRequest {
return getDelegate().getBody(); return getDelegate().getBody();
} }
@Override
public String toString() {
return getClass().getSimpleName() + " [delegate=" + getDelegate() + "]";
}
/** /**
* Return the native request of the underlying server API, if possible, * Return the native request of the underlying server API, if possible,
@ -136,15 +141,8 @@ public class ServerHttpRequestDecorator implements ServerHttpRequest {
return getNativeRequest(serverHttpRequestDecorator.getDelegate()); return getNativeRequest(serverHttpRequestDecorator.getDelegate());
} }
else { else {
throw new IllegalArgumentException( throw new IllegalArgumentException("Cannot find native request in " + request.getClass().getName());
"Can't find native request in " + request.getClass().getName());
} }
} }
@Override
public String toString() {
return getClass().getSimpleName() + " [delegate=" + getDelegate() + "]";
}
} }