From bba66429fbf77b242aa02c63baec489488ce6263 Mon Sep 17 00:00:00 2001 From: Juergen Hoeller Date: Tue, 11 Oct 2022 15:35:25 +0200 Subject: [PATCH] Polishing --- .../context/support/GenericApplicationContext.java | 10 ++++++---- .../core/task/SimpleAsyncTaskExecutorTests.java | 10 +++++----- .../java/org/springframework/http/RequestEntity.java | 5 ++--- 3 files changed, 13 insertions(+), 12 deletions(-) diff --git a/spring-context/src/main/java/org/springframework/context/support/GenericApplicationContext.java b/spring-context/src/main/java/org/springframework/context/support/GenericApplicationContext.java index 69da2d6bfc6..8f8f5f64ab7 100644 --- a/spring-context/src/main/java/org/springframework/context/support/GenericApplicationContext.java +++ b/spring-context/src/main/java/org/springframework/context/support/GenericApplicationContext.java @@ -111,12 +111,12 @@ import org.springframework.util.ClassUtils; */ public class GenericApplicationContext extends AbstractApplicationContext implements BeanDefinitionRegistry { - private static final Consumer asCglibProxy = hint -> + private static final Consumer asClassBasedProxy = hint -> hint.withMembers(MemberCategory.INVOKE_DECLARED_CONSTRUCTORS, MemberCategory.INVOKE_DECLARED_METHODS, MemberCategory.DECLARED_FIELDS); - private static final Consumer asCglibProxyTarget = hint -> + private static final Consumer asProxiedUserClass = hint -> hint.withMembers(MemberCategory.INTROSPECT_DECLARED_CONSTRUCTORS, MemberCategory.INVOKE_DECLARED_METHODS); @@ -445,14 +445,16 @@ public class GenericApplicationContext extends AbstractApplicationContext implem for (SmartInstantiationAwareBeanPostProcessor bpp : bpps) { beanType = bpp.determineBeanType(beanType, beanName); if (Proxy.isProxyClass(beanType)) { + // A JDK proxy class needs an explicit hint runtimeHints.proxies().registerJdkProxy(beanType.getInterfaces()); } else { + // Potentially a CGLIB-generated subclass with reflection hints Class userClass = ClassUtils.getUserClass(beanType); if (userClass != beanType) { runtimeHints.reflection() - .registerType(beanType, asCglibProxy) - .registerType(userClass, asCglibProxyTarget); + .registerType(beanType, asClassBasedProxy) + .registerType(userClass, asProxiedUserClass); } } } diff --git a/spring-core/src/test/java/org/springframework/core/task/SimpleAsyncTaskExecutorTests.java b/spring-core/src/test/java/org/springframework/core/task/SimpleAsyncTaskExecutorTests.java index 175002cbfbe..70376abc931 100644 --- a/spring-core/src/test/java/org/springframework/core/task/SimpleAsyncTaskExecutorTests.java +++ b/spring-core/src/test/java/org/springframework/core/task/SimpleAsyncTaskExecutorTests.java @@ -32,7 +32,7 @@ import static org.assertj.core.api.Assertions.assertThatIllegalStateException; class SimpleAsyncTaskExecutorTests { @Test - void cannotExecuteWhenConcurrencyIsSwitchedOff() throws Exception { + void cannotExecuteWhenConcurrencyIsSwitchedOff() { SimpleAsyncTaskExecutor executor = new SimpleAsyncTaskExecutor(); executor.setConcurrencyLimit(ConcurrencyThrottleSupport.NO_CONCURRENCY); assertThat(executor.isThrottleActive()).isTrue(); @@ -41,13 +41,13 @@ class SimpleAsyncTaskExecutorTests { } @Test - void throttleIsNotActiveByDefault() throws Exception { + void throttleIsNotActiveByDefault() { SimpleAsyncTaskExecutor executor = new SimpleAsyncTaskExecutor(); assertThat(executor.isThrottleActive()).as("Concurrency throttle must not default to being active (on)").isFalse(); } @Test - void threadNameGetsSetCorrectly() throws Exception { + void threadNameGetsSetCorrectly() { final String customPrefix = "chankPop#"; final Object monitor = new Object(); SimpleAsyncTaskExecutor executor = new SimpleAsyncTaskExecutor(customPrefix); @@ -57,7 +57,7 @@ class SimpleAsyncTaskExecutorTests { } @Test - void threadFactoryOverridesDefaults() throws Exception { + void threadFactoryOverridesDefaults() { final Object monitor = new Object(); SimpleAsyncTaskExecutor executor = new SimpleAsyncTaskExecutor(runnable -> new Thread(runnable, "test")); ThreadNameHarvester task = new ThreadNameHarvester(monitor); @@ -66,7 +66,7 @@ class SimpleAsyncTaskExecutorTests { } @Test - void throwsExceptionWhenSuppliedWithNullRunnable() throws Exception { + void throwsExceptionWhenSuppliedWithNullRunnable() { assertThatIllegalArgumentException().isThrownBy(() -> new SimpleAsyncTaskExecutor().execute(null)); } diff --git a/spring-web/src/main/java/org/springframework/http/RequestEntity.java b/spring-web/src/main/java/org/springframework/http/RequestEntity.java index b5bd28da5c3..364a1373bfa 100644 --- a/spring-web/src/main/java/org/springframework/http/RequestEntity.java +++ b/spring-web/src/main/java/org/springframework/http/RequestEntity.java @@ -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. @@ -28,7 +28,6 @@ import java.util.function.Consumer; import org.springframework.lang.Nullable; import org.springframework.util.MultiValueMap; import org.springframework.util.ObjectUtils; -import org.springframework.web.util.UriTemplateHandler; /** * Extension of {@link HttpEntity} that also exposes the HTTP method and the @@ -167,7 +166,7 @@ public class RequestEntity extends HttpEntity { * on how to expand template and encode the URI. In such cases, the * {@code URI} is prepared by the * {@link org.springframework.web.client.RestTemplate} with the help of the - * {@link UriTemplateHandler} it is configured with. + * {@link org.springframework.web.util.UriTemplateHandler} it is configured with. */ public URI getUrl() { if (this.url == null) {