Merge branch '6.1.x'

# Conflicts:
#	spring-context-support/src/main/java/org/springframework/cache/jcache/interceptor/AbstractFallbackJCacheOperationSource.java
#	spring-context/src/main/java/org/springframework/cache/interceptor/AbstractFallbackCacheOperationSource.java
#	spring-tx/src/main/java/org/springframework/transaction/interceptor/AbstractFallbackTransactionAttributeSource.java
This commit is contained in:
Juergen Hoeller 2024-03-04 22:50:22 +01:00
commit dc6c96de0a
13 changed files with 71 additions and 40 deletions

View File

@ -17,16 +17,19 @@
package org.springframework.aop.support; package org.springframework.aop.support;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.util.List;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.springframework.aop.ClassFilter; import org.springframework.aop.ClassFilter;
import org.springframework.aop.MethodMatcher; import org.springframework.aop.MethodMatcher;
import org.springframework.aop.Pointcut; import org.springframework.aop.Pointcut;
import org.springframework.aop.framework.ProxyFactory;
import org.springframework.aop.interceptor.ExposeInvocationInterceptor; import org.springframework.aop.interceptor.ExposeInvocationInterceptor;
import org.springframework.aop.target.EmptyTargetSource; import org.springframework.aop.target.EmptyTargetSource;
import org.springframework.aop.testfixture.interceptor.NopInterceptor; import org.springframework.aop.testfixture.interceptor.NopInterceptor;
import org.springframework.beans.testfixture.beans.TestBean; import org.springframework.beans.testfixture.beans.TestBean;
import org.springframework.core.ResolvableType;
import org.springframework.core.testfixture.io.SerializationTestUtils; import org.springframework.core.testfixture.io.SerializationTestUtils;
import org.springframework.lang.Nullable; import org.springframework.lang.Nullable;
import org.springframework.util.ReflectionUtils; import org.springframework.util.ReflectionUtils;
@ -37,6 +40,7 @@ import static org.assertj.core.api.Assertions.assertThat;
* @author Rod Johnson * @author Rod Johnson
* @author Chris Beams * @author Chris Beams
* @author Sebastien Deleuze * @author Sebastien Deleuze
* @author Juergen Hoeller
*/ */
class AopUtilsTests { class AopUtilsTests {
@ -99,4 +103,36 @@ class AopUtilsTests {
assertThat(result).isEqualTo(name); assertThat(result).isEqualTo(name);
} }
@Test // gh-32365
void mostSpecificMethodBetweenJdkProxyAndTarget() throws Exception {
Class<?> proxyClass = new ProxyFactory(new WithInterface()).getProxyClass(getClass().getClassLoader());
Method specificMethod = AopUtils.getMostSpecificMethod(proxyClass.getMethod("handle", List.class), WithInterface.class);
assertThat(ResolvableType.forMethodParameter(specificMethod, 0).getGeneric().toClass()).isEqualTo(String.class);
}
@Test // gh-32365
void mostSpecificMethodBetweenCglibProxyAndTarget() throws Exception {
Class<?> proxyClass = new ProxyFactory(new WithoutInterface()).getProxyClass(getClass().getClassLoader());
Method specificMethod = AopUtils.getMostSpecificMethod(proxyClass.getMethod("handle", List.class), WithoutInterface.class);
assertThat(ResolvableType.forMethodParameter(specificMethod, 0).getGeneric().toClass()).isEqualTo(String.class);
}
interface ProxyInterface {
void handle(List<String> list);
}
static class WithInterface implements ProxyInterface {
public void handle(List<String> list) {
}
}
static class WithoutInterface {
public void handle(List<String> list) {
}
}
} }

View File

@ -224,10 +224,8 @@ public abstract class AnnotationJCacheOperationSource extends AbstractFallbackJC
for (Class<?> parameterType : parameterTypes) { for (Class<?> parameterType : parameterTypes) {
parameters.add(parameterType.getName()); parameters.add(parameterType.getName());
} }
return method.getDeclaringClass().getName() + '.' + method.getName() +
return method.getDeclaringClass().getName() '(' + StringUtils.collectionToCommaDelimitedString(parameters) + ')';
+ '.' + method.getName()
+ '(' + StringUtils.collectionToCommaDelimitedString(parameters) + ')';
} }
private int countNonNull(Object... instances) { private int countNonNull(Object... instances) {

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.
@ -98,8 +98,8 @@ public class AsyncAnnotationBeanPostProcessor extends AbstractBeanFactoryAwareAd
* applying the corresponding default if a supplier is not resolvable. * applying the corresponding default if a supplier is not resolvable.
* @since 5.1 * @since 5.1
*/ */
public void configure( public void configure(@Nullable Supplier<Executor> executor,
@Nullable Supplier<Executor> executor, @Nullable Supplier<AsyncUncaughtExceptionHandler> exceptionHandler) { @Nullable Supplier<AsyncUncaughtExceptionHandler> exceptionHandler) {
this.executor = executor; this.executor = executor;
this.exceptionHandler = exceptionHandler; this.exceptionHandler = exceptionHandler;

View File

@ -38,7 +38,6 @@ import static org.assertj.core.api.Assertions.assertThat;
*/ */
class DataBinderConstructTests { class DataBinderConstructTests {
@Test @Test
void dataClassBinding() { void dataClassBinding() {
MapValueResolver valueResolver = new MapValueResolver(Map.of("param1", "value1", "param2", "true")); MapValueResolver valueResolver = new MapValueResolver(Map.of("param1", "value1", "param2", "true"));
@ -78,7 +77,7 @@ class DataBinderConstructTests {
assertThat(bindingResult.getFieldValue("param3")).isNull(); assertThat(bindingResult.getFieldValue("param3")).isNull();
} }
@Test // gh-31821 @Test // gh-31821
void dataClassBindingWithNestedOptionalParameterWithMissingParameter() { void dataClassBindingWithNestedOptionalParameterWithMissingParameter() {
MapValueResolver valueResolver = new MapValueResolver(Map.of("param1", "value1")); MapValueResolver valueResolver = new MapValueResolver(Map.of("param1", "value1"));
DataBinder binder = initDataBinder(NestedDataClass.class); DataBinder binder = initDataBinder(NestedDataClass.class);

View File

@ -2055,7 +2055,7 @@ class DataBinderTests {
.withMessageContaining("DataBinder is already initialized - call setAutoGrowCollectionLimit before other configuration methods"); .withMessageContaining("DataBinder is already initialized - call setAutoGrowCollectionLimit before other configuration methods");
} }
@Test // SPR-15009 @Test // SPR-15009
void setCustomMessageCodesResolverBeforeInitializeBindingResultForBeanPropertyAccess() { void setCustomMessageCodesResolverBeforeInitializeBindingResultForBeanPropertyAccess() {
TestBean testBean = new TestBean(); TestBean testBean = new TestBean();
DataBinder binder = new DataBinder(testBean, "testBean"); DataBinder binder = new DataBinder(testBean, "testBean");
@ -2072,7 +2072,7 @@ class DataBinderTests {
assertThat(((BeanWrapper) binder.getInternalBindingResult().getPropertyAccessor()).getAutoGrowCollectionLimit()).isEqualTo(512); assertThat(((BeanWrapper) binder.getInternalBindingResult().getPropertyAccessor()).getAutoGrowCollectionLimit()).isEqualTo(512);
} }
@Test // SPR-15009 @Test // SPR-15009
void setCustomMessageCodesResolverBeforeInitializeBindingResultForDirectFieldAccess() { void setCustomMessageCodesResolverBeforeInitializeBindingResultForDirectFieldAccess() {
TestBean testBean = new TestBean(); TestBean testBean = new TestBean();
DataBinder binder = new DataBinder(testBean, "testBean"); DataBinder binder = new DataBinder(testBean, "testBean");
@ -2126,7 +2126,7 @@ class DataBinderTests {
.withMessageContaining("DataBinder is already initialized with MessageCodesResolver"); .withMessageContaining("DataBinder is already initialized with MessageCodesResolver");
} }
@Test // gh-24347 @Test // gh-24347
void overrideBindingResultType() { void overrideBindingResultType() {
TestBean testBean = new TestBean(); TestBean testBean = new TestBean();
DataBinder binder = new DataBinder(testBean, "testBean"); DataBinder binder = new DataBinder(testBean, "testBean");

View File

@ -83,8 +83,7 @@ class MethodValidationProxyTests {
context.close(); context.close();
} }
@Test // gh-29782 @Test // gh-29782
@SuppressWarnings("unchecked")
public void testMethodValidationPostProcessorForInterfaceOnlyProxy() { public void testMethodValidationPostProcessorForInterfaceOnlyProxy() {
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(); AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
context.register(MethodValidationPostProcessor.class); context.register(MethodValidationPostProcessor.class);

View File

@ -17,6 +17,7 @@
package org.springframework.core; package org.springframework.core;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.lang.reflect.Proxy;
import java.lang.reflect.Type; import java.lang.reflect.Type;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
@ -86,7 +87,10 @@ public final class BridgeMethodResolver {
* @see org.springframework.util.ClassUtils#getMostSpecificMethod * @see org.springframework.util.ClassUtils#getMostSpecificMethod
*/ */
public static Method getMostSpecificMethod(Method bridgeMethod, @Nullable Class<?> targetClass) { public static Method getMostSpecificMethod(Method bridgeMethod, @Nullable Class<?> targetClass) {
if (targetClass != null && !bridgeMethod.getDeclaringClass().isAssignableFrom(targetClass)) { if (targetClass != null &&
!ClassUtils.getUserClass(bridgeMethod.getDeclaringClass()).isAssignableFrom(targetClass) &&
!Proxy.isProxyClass(bridgeMethod.getDeclaringClass())) {
// From a different class hierarchy, and not a JDK or CGLIB proxy either -> return as-is.
return bridgeMethod; return bridgeMethod;
} }

View File

@ -710,7 +710,7 @@ public class ResolvableType implements Serializable {
* @param nestingLevel the required nesting level, indexed from 1 for the * @param nestingLevel the required nesting level, indexed from 1 for the
* current type, 2 for the first nested generic, 3 for the second and so on * current type, 2 for the first nested generic, 3 for the second and so on
* @param typeIndexesPerLevel a map containing the generic index for a given * @param typeIndexesPerLevel a map containing the generic index for a given
* nesting level (may be {@code null}) * nesting level (can be {@code null})
* @return a {@code ResolvableType} for the nested level, or {@link #NONE} * @return a {@code ResolvableType} for the nested level, or {@link #NONE}
*/ */
public ResolvableType getNested(int nestingLevel, @Nullable Map<Integer, Integer> typeIndexesPerLevel) { public ResolvableType getNested(int nestingLevel, @Nullable Map<Integer, Integer> typeIndexesPerLevel) {
@ -742,7 +742,7 @@ public class ResolvableType implements Serializable {
* generic is returned. * generic is returned.
* <p>If no generic is available at the specified indexes {@link #NONE} is returned. * <p>If no generic is available at the specified indexes {@link #NONE} is returned.
* @param indexes the indexes that refer to the generic parameter * @param indexes the indexes that refer to the generic parameter
* (may be omitted to return the first generic) * (can be omitted to return the first generic)
* @return a {@code ResolvableType} for the specified generic, or {@link #NONE} * @return a {@code ResolvableType} for the specified generic, or {@link #NONE}
* @see #hasGenerics() * @see #hasGenerics()
* @see #getGenerics() * @see #getGenerics()
@ -845,7 +845,7 @@ public class ResolvableType implements Serializable {
* Convenience method that will {@link #getGeneric(int...) get} and * Convenience method that will {@link #getGeneric(int...) get} and
* {@link #resolve() resolve} a specific generic parameter. * {@link #resolve() resolve} a specific generic parameter.
* @param indexes the indexes that refer to the generic parameter * @param indexes the indexes that refer to the generic parameter
* (may be omitted to return the first generic) * (can be omitted to return the first generic)
* @return a resolved {@link Class} or {@code null} * @return a resolved {@link Class} or {@code null}
* @see #getGeneric(int...) * @see #getGeneric(int...)
* @see #resolve() * @see #resolve()

View File

@ -31,7 +31,6 @@ import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException; import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
import static org.assertj.core.api.Assertions.assertThatIllegalStateException; import static org.assertj.core.api.Assertions.assertThatIllegalStateException;
/** /**
* Integration tests for {@link MockMvcWebConnection}. * Integration tests for {@link MockMvcWebConnection}.
* *
@ -64,14 +63,15 @@ public class MockMvcWebConnectionTests {
public void contextPathEmpty() { public void contextPathEmpty() {
this.webClient.setWebConnection(new MockMvcWebConnection(this.mockMvc, this.webClient, "")); this.webClient.setWebConnection(new MockMvcWebConnection(this.mockMvc, this.webClient, ""));
// Empty context path (root context) should not match to a URL with a context path // Empty context path (root context) should not match to a URL with a context path
assertThatExceptionOfType(FailingHttpStatusCodeException.class).isThrownBy(() -> assertThatExceptionOfType(FailingHttpStatusCodeException.class)
this.webClient.getPage("http://localhost/context/a")) .isThrownBy(() -> this.webClient.getPage("http://localhost/context/a"))
.satisfies(ex -> assertThat(ex.getStatusCode()).isEqualTo(404)); .satisfies(ex -> assertThat(ex.getStatusCode()).isEqualTo(404));
this.webClient.setWebConnection(new MockMvcWebConnection(this.mockMvc, this.webClient)); this.webClient.setWebConnection(new MockMvcWebConnection(this.mockMvc, this.webClient));
// No context is the same providing an empty context path // No context is the same providing an empty context path
assertThatExceptionOfType(FailingHttpStatusCodeException.class).isThrownBy(() -> assertThatExceptionOfType(FailingHttpStatusCodeException.class)
this.webClient.getPage("http://localhost/context/a")) .isThrownBy(() -> this.webClient.getPage("http://localhost/context/a"))
.satisfies(ex -> assertThat(ex.getStatusCode()).isEqualTo(404)); .satisfies(ex -> assertThat(ex.getStatusCode()).isEqualTo(404));
} }
@Test @Test
@ -84,8 +84,9 @@ public class MockMvcWebConnectionTests {
@Test @Test
public void infiniteForward() { public void infiniteForward() {
this.webClient.setWebConnection(new MockMvcWebConnection(this.mockMvc, this.webClient, "")); this.webClient.setWebConnection(new MockMvcWebConnection(this.mockMvc, this.webClient, ""));
assertThatIllegalStateException().isThrownBy(() -> this.webClient.getPage("http://localhost/infiniteForward")) assertThatIllegalStateException()
.withMessage("Forwarded 100 times in a row, potential infinite forward loop"); .isThrownBy(() -> this.webClient.getPage("http://localhost/infiniteForward"))
.withMessage("Forwarded 100 times in a row, potential infinite forward loop");
} }
@Test @Test

View File

@ -32,7 +32,6 @@ import org.springframework.mock.web.MockHttpServletResponse;
import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException; import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
/** /**
* Tests for {@link MockWebResponseBuilder}. * Tests for {@link MockWebResponseBuilder}.
* *
@ -55,8 +54,6 @@ public class MockWebResponseBuilderTests {
} }
// --- constructor
@Test @Test
public void constructorWithNullWebRequest() { public void constructorWithNullWebRequest() {
assertThatIllegalArgumentException().isThrownBy(() -> assertThatIllegalArgumentException().isThrownBy(() ->
@ -66,12 +63,10 @@ public class MockWebResponseBuilderTests {
@Test @Test
public void constructorWithNullResponse() { public void constructorWithNullResponse() {
assertThatIllegalArgumentException().isThrownBy(() -> assertThatIllegalArgumentException().isThrownBy(() ->
new MockWebResponseBuilder(0L, new WebRequest(new URL("http://company.example:80/test/this/here")), null)); new MockWebResponseBuilder(0L,
new WebRequest(new URL("http://company.example:80/test/this/here")), null));
} }
// --- build
@Test @Test
public void buildContent() throws Exception { public void buildContent() throws Exception {
this.response.getWriter().write("expected content"); this.response.getWriter().write("expected content");
@ -124,8 +119,7 @@ public class MockWebResponseBuilderTests {
.endsWith("; Secure; HttpOnly"); .endsWith("; Secure; HttpOnly");
} }
// SPR-14169 @Test // SPR-14169
@Test
public void buildResponseHeadersNullDomainDefaulted() throws Exception { public void buildResponseHeadersNullDomainDefaulted() throws Exception {
Cookie cookie = new Cookie("cookieA", "valueA"); Cookie cookie = new Cookie("cookieA", "valueA");
this.response.addCookie(cookie); this.response.addCookie(cookie);

View File

@ -50,6 +50,7 @@ class MockMvcHtmlUnitDriverBuilderTests {
private HtmlUnitDriver driver; private HtmlUnitDriver driver;
MockMvcHtmlUnitDriverBuilderTests(WebApplicationContext wac) { MockMvcHtmlUnitDriverBuilderTests(WebApplicationContext wac) {
this.mockMvc = MockMvcBuilders.webAppContextSetup(wac).build(); this.mockMvc = MockMvcBuilders.webAppContextSetup(wac).build();
} }

View File

@ -48,6 +48,7 @@ class WebConnectionHtmlUnitDriverTests {
@Mock @Mock
private WebConnection connection; private WebConnection connection;
@BeforeEach @BeforeEach
void setup() throws Exception { void setup() throws Exception {
given(this.connection.getResponse(any(WebRequest.class))).willThrow(new IOException("")); given(this.connection.getResponse(any(WebRequest.class))).willThrow(new IOException(""));

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.
@ -218,7 +218,6 @@ public abstract class AbstractHttpMessageConverter<T> implements HttpMessageConv
public OutputStream getBody() { public OutputStream getBody() {
return outputStream; return outputStream;
} }
@Override @Override
public HttpHeaders getHeaders() { public HttpHeaders getHeaders() {
return headers; return headers;
@ -304,8 +303,7 @@ public abstract class AbstractHttpMessageConverter<T> implements HttpMessageConv
* Indicates whether this message converter can * Indicates whether this message converter can
* {@linkplain #write(Object, MediaType, HttpOutputMessage) write} the * {@linkplain #write(Object, MediaType, HttpOutputMessage) write} the
* given object multiple times. * given object multiple times.
* * <p>The default implementation returns {@code false}.
* <p>Default implementation returns {@code false}.
* @param t the object t * @param t the object t
* @return {@code true} if {@code t} can be written repeatedly; * @return {@code true} if {@code t} can be written repeatedly;
* {@code false} otherwise * {@code false} otherwise