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");
* 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
* parameter or a field. Exposed by {@link UnsatisfiedDependencyException}.
* Also available as an argument for factory methods, reacting to the
* requesting injection point for building a customized bean instance.
* parameter or a field.
*
* <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
* @since 4.3

View File

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

View File

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

View File

@ -518,8 +518,8 @@ public class DefaultListableBeanFactory extends AbstractAutowireCapableBeanFacto
return namedBean.getBeanInstance();
}
BeanFactory parent = getParentBeanFactory();
if (parent instanceof DefaultListableBeanFactory dlfb) {
return dlfb.resolveBean(requiredType, args, nonUniqueAsNull);
if (parent instanceof DefaultListableBeanFactory dlbf) {
return dlbf.resolveBean(requiredType, args, nonUniqueAsNull);
}
else if (parent != null) {
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");
* you may not use this file except in compliance with the License.
@ -45,11 +45,13 @@ public final class AccessControl {
private final Visibility visibility;
AccessControl(Class<?> target, Visibility visibility) {
this.target = target;
this.visibility = visibility;
}
/**
* Create an {@link AccessControl} for the given member. This considers the
* 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
*/
public static AccessControl forResolvableType(ResolvableType resolvableType) {
return new AccessControl(resolvableType.toClass(),
Visibility.forResolvableType(resolvableType));
return new AccessControl(resolvableType.toClass(), Visibility.forResolvableType(resolvableType));
}
/**
@ -87,8 +88,8 @@ public final class AccessControl {
* @return the lowest {@link AccessControl} from the candidates
*/
public static AccessControl lowest(AccessControl... candidates) {
int index = Visibility.lowestIndex(Arrays.stream(candidates)
.map(AccessControl::getVisibility).toArray(Visibility[]::new));
int index = Visibility.lowestIndex(
Arrays.stream(candidates).map(AccessControl::getVisibility).toArray(Visibility[]::new));
return candidates[index];
}
@ -125,6 +126,7 @@ public final class AccessControl {
return this.target.getPackageName().equals(type.packageName());
}
/**
* Access visibility types as determined by the <a href=
* "https://docs.oracle.com/javase/tutorial/java/javaOO/accesscontrol.html">modifiers</a>
@ -270,6 +272,6 @@ public final class AccessControl {
}
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");
* you may not use this file except in compliance with the License.
@ -28,21 +28,22 @@ import org.springframework.lang.Nullable;
* @author Brian Clozel
* @since 6.0
*/
public class JavaSerializationHint implements ConditionalHint {
public final class JavaSerializationHint implements ConditionalHint {
private final TypeReference type;
@Nullable
private final TypeReference reachableType;
JavaSerializationHint(Builder builder) {
this.type = builder.type;
this.reachableType = builder.reachableType;
}
/**
* Return the {@link TypeReference type} that needs to be serialized using
* Java serialization at runtime.
* Return the {@link TypeReference type} that needs to be serialized using Java serialization at runtime.
* @return a {@link Serializable} type
*/
public TypeReference getType() {
@ -56,16 +57,9 @@ public class JavaSerializationHint implements ConditionalHint {
}
@Override
public boolean equals(@Nullable Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
JavaSerializationHint that = (JavaSerializationHint) o;
return this.type.equals(that.type)
&& Objects.equals(this.reachableType, that.reachableType);
public boolean equals(@Nullable Object other) {
return (this == other || (other instanceof JavaSerializationHint that &&
this.type.equals(that.type) && Objects.equals(this.reachableType, that.reachableType)));
}
@Override
@ -84,16 +78,13 @@ public class JavaSerializationHint implements ConditionalHint {
@Nullable
private TypeReference reachableType;
Builder(TypeReference type) {
this.type = type;
}
/**
* Make this hint conditional on the fact that the specified type
* can be resolved.
* @param reachableType the type that should be reachable for this
* hint to apply
* Make this hint conditional on the fact that the specified type can be resolved.
* @param reachableType the type that should be reachable for this hint to apply
* @return {@code this}, to facilitate method chaining
*/
public Builder onReachableType(TypeReference reachableType) {
@ -108,6 +99,6 @@ public class JavaSerializationHint implements ConditionalHint {
JavaSerializationHint build() {
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");
* 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 the interfaces to be proxied.
* @return the interfaces that the proxy should implement
@ -77,16 +78,10 @@ public final class JdkProxyHint implements ConditionalHint {
}
@Override
public boolean equals(@Nullable Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
JdkProxyHint that = (JdkProxyHint) o;
return this.proxiedInterfaces.equals(that.proxiedInterfaces)
&& Objects.equals(this.reachableType, that.reachableType);
public boolean equals(@Nullable Object other) {
return (this == other || (other instanceof JdkProxyHint that &&
this.proxiedInterfaces.equals(that.proxiedInterfaces) &&
Objects.equals(this.reachableType, that.reachableType)));
}
@Override
@ -105,7 +100,6 @@ public final class JdkProxyHint implements ConditionalHint {
@Nullable
private TypeReference reachableType;
Builder() {
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
* can be resolved.
* @param reachableType the type that should be reachable for this
* hint to apply
* Make this hint conditional on the fact that the specified type can be resolved.
* @param reachableType the type that should be reachable for this hint to apply
* @return {@code this}, to facilitate method chaining
*/
public Builder onReachableType(TypeReference reachableType) {
@ -160,7 +152,6 @@ public final class JdkProxyHint implements ConditionalHint {
}
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");
* 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;
}
/**
* Return the {@code baseName} of the resource bundle.
* @return the base name
*/
public String getBaseName() {
return this.baseName;
@ -56,16 +56,9 @@ public final class ResourceBundleHint implements ConditionalHint {
}
@Override
public boolean equals(@Nullable Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
ResourceBundleHint that = (ResourceBundleHint) o;
return this.baseName.equals(that.baseName)
&& Objects.equals(this.reachableType, that.reachableType);
public boolean equals(@Nullable Object other) {
return (this == other || (other instanceof ResourceBundleHint that &&
this.baseName.equals(that.baseName) && Objects.equals(this.reachableType, that.reachableType)));
}
@Override
@ -73,6 +66,7 @@ public final class ResourceBundleHint implements ConditionalHint {
return Objects.hash(this.baseName, this.reachableType);
}
/**
* 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
* can be resolved.
* @param reachableType the type that should be reachable for this
* hint to apply
* Make this hint conditional on the fact that the specified type can be resolved.
* @param reachableType the type that should be reachable for this hint to apply
* @return {@code this}, to facilitate method chaining
*/
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
* builder.
* Create a {@link ResourceBundleHint} based on the state of this builder.
* @return a resource bundle hint
*/
ResourceBundleHint build() {
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");
* 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
*/
public String getPattern() {
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 pattern
*/
public Pattern toRegex() {
String prefix = (this.pattern.startsWith("*") ? ".*" : "");
@ -98,16 +96,9 @@ public final class ResourcePatternHint implements ConditionalHint {
}
@Override
public boolean equals(@Nullable Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
ResourcePatternHint that = (ResourcePatternHint) o;
return this.pattern.equals(that.pattern)
&& Objects.equals(this.reachableType, that.reachableType);
public boolean equals(@Nullable Object other) {
return (this == other || (other instanceof ResourcePatternHint that &&
this.pattern.equals(that.pattern) && Objects.equals(this.reachableType, that.reachableType)));
}
@Override

View File

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

View File

@ -192,7 +192,6 @@ class DefaultServerHttpRequestBuilder implements ServerHttpRequest.Builder {
private final ServerHttpRequest originalRequest;
public MutatedServerHttpRequest(URI uri, @Nullable String contextPath,
HttpMethod method, @Nullable SslInfo sslInfo, @Nullable InetSocketAddress remoteAddress,
HttpHeaders headers, Flux<DataBuffer> body, ServerHttpRequest originalRequest) {
@ -232,7 +231,6 @@ class DefaultServerHttpRequestBuilder implements ServerHttpRequest.Builder {
return this.body;
}
@SuppressWarnings("unchecked")
@Override
public <T> T getNativeRequest() {
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");
* you may not use this file except in compliance with the License.
@ -119,6 +119,11 @@ public class ServerHttpRequestDecorator implements ServerHttpRequest {
return getDelegate().getBody();
}
@Override
public String toString() {
return getClass().getSimpleName() + " [delegate=" + getDelegate() + "]";
}
/**
* Return the native request of the underlying server API, if possible,
@ -136,15 +141,8 @@ public class ServerHttpRequestDecorator implements ServerHttpRequest {
return getNativeRequest(serverHttpRequestDecorator.getDelegate());
}
else {
throw new IllegalArgumentException(
"Can't find native request in " + request.getClass().getName());
throw new IllegalArgumentException("Cannot find native request in " + request.getClass().getName());
}
}
@Override
public String toString() {
return getClass().getSimpleName() + " [delegate=" + getDelegate() + "]";
}
}