Browse Source

Polishing

Closes gh-31522
pull/31530/head
Johnny Lim 1 year ago committed by Sam Brannen
parent
commit
2b750926c3
  1. 4
      framework-docs/modules/ROOT/pages/integration/observability.adoc
  2. 2
      framework-docs/modules/ROOT/pages/languages/kotlin/spring-projects-in.adoc
  3. 10
      spring-beans/src/test/java/org/springframework/beans/factory/aot/BeanDefinitionPropertiesCodeGeneratorTests.java
  4. 2
      spring-context/src/main/java/org/springframework/context/annotation/ConfigurationClassPostProcessor.java
  5. 2
      spring-context/src/main/java/org/springframework/validation/beanvalidation/MethodValidationInterceptor.java
  6. 2
      spring-context/src/test/java/org/springframework/format/datetime/standard/InstantFormatterTests.java
  7. 2
      spring-context/src/test/java/org/springframework/format/support/FormattingConversionServiceRuntimeHintsTests.java
  8. 4
      spring-context/src/test/java/org/springframework/validation/beanvalidation/MethodValidationProxyReactorTests.java
  9. 4
      spring-core/src/jmh/java/org/springframework/core/env/CompositePropertySourceBenchmark.java
  10. 4
      spring-core/src/main/java/org/springframework/core/io/buffer/OutputStreamPublisher.java
  11. 2
      spring-core/src/main/java/org/springframework/core/task/support/ContextPropagatingTaskDecorator.java
  12. 2
      spring-core/src/main/java/org/springframework/util/function/SingletonSupplier.java
  13. 8
      spring-core/src/test/java/org/springframework/core/task/support/ContextPropagatingTaskDecoratorTests.java
  14. 2
      spring-orm/src/main/java/org/springframework/orm/jpa/persistenceunit/DefaultPersistenceUnitManager.java
  15. 2
      spring-web/src/main/java/org/springframework/web/filter/reactive/ServerHttpObservationFilter.java
  16. 2
      spring-web/src/main/java/org/springframework/web/server/adapter/HttpWebHandlerAdapter.java
  17. 2
      spring-web/src/test/java/org/springframework/http/client/reactive/ReactorClientHttpConnectorTests.java
  18. 2
      spring-webflux/src/main/java/org/springframework/web/reactive/DispatchExceptionHandler.java
  19. 2
      spring-webflux/src/main/kotlin/org/springframework/web/reactive/function/server/CoRouterFunctionDsl.kt
  20. 2
      spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/RequestMappingHandlerAdapter.java

4
framework-docs/modules/ROOT/pages/integration/observability.adoc

@ -358,14 +358,14 @@ By default, event publication and processing is done synchronously and on the sa
This means that during the execution of that task, the ThreadLocals and logging context will be the same as the event publisher. This means that during the execution of that task, the ThreadLocals and logging context will be the same as the event publisher.
If the application configures globally a custom `ApplicationEventMulticaster` with a strategy that schedules event processing on different threads, this is no longer true. If the application configures globally a custom `ApplicationEventMulticaster` with a strategy that schedules event processing on different threads, this is no longer true.
All `@EventListener` methods will be processed on a different thread, outstide of the main event publication thread. All `@EventListener` methods will be processed on a different thread, outside of the main event publication thread.
In these cases, the https://micrometer.io/docs/contextPropagation[Micrometer Context Propagation library] can help propagating such values and better correlate the processing of the events. In these cases, the https://micrometer.io/docs/contextPropagation[Micrometer Context Propagation library] can help propagating such values and better correlate the processing of the events.
The application can configure the chosen `TaskExecutor` to use a `ContextPropagatingTaskDecorator` that decorates tasks and propagates context. The application can configure the chosen `TaskExecutor` to use a `ContextPropagatingTaskDecorator` that decorates tasks and propagates context.
For this to work, the `io.micrometer:context-propagation` library must be present on the classpath: For this to work, the `io.micrometer:context-propagation` library must be present on the classpath:
include-code::./ApplicationEventsConfiguration[] include-code::./ApplicationEventsConfiguration[]
Similarly, if that asynchronous choice is made locally for each `@EventListener` annotated method, by adding an `@Async` method to it, Similarly, if that asynchronous choice is made locally for each `@EventListener` annotated method, by adding an `@Async` to it,
you can choose a `TaskExecutor` that propagates context by referring to it by its qualifier. you can choose a `TaskExecutor` that propagates context by referring to it by its qualifier.
Given the following `TaskExecutor` bean definition, configured with the dedicated task decorator: Given the following `TaskExecutor` bean definition, configured with the dedicated task decorator:

2
framework-docs/modules/ROOT/pages/languages/kotlin/spring-projects-in.adoc

@ -248,7 +248,7 @@ For example, declaring `List<Foo>` in Kotlin is conceptually equivalent to `java
`kotlin.collections.List` is declared as `kotlin.collections.List` is declared as
https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.collections/-list/[`interface List<out E> : kotlin.collections.Collection<E>`]. https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.collections/-list/[`interface List<out E> : kotlin.collections.Collection<E>`].
This needs to be taken in account by using the `out` Kotlin keyword on generic types when using Java classes, This needs to be taken into account by using the `out` Kotlin keyword on generic types when using Java classes,
for example when writing a `org.springframework.core.convert.converter.Converter` from a Kotlin type to a Java type. for example when writing a `org.springframework.core.convert.converter.Converter` from a Kotlin type to a Java type.
[source,kotlin,indent=0] [source,kotlin,indent=0]

10
spring-beans/src/test/java/org/springframework/beans/factory/aot/BeanDefinitionPropertiesCodeGeneratorTests.java

@ -287,7 +287,7 @@ class BeanDefinitionPropertiesCodeGeneratorTests {
assertThat(actual.getPropertyValues().get("spring")).isEqualTo("framework"); assertThat(actual.getPropertyValues().get("spring")).isEqualTo("framework");
}); });
assertHasMethodInvokeHints(PropertyValuesBean.class, "setTest", "setSpring"); assertHasMethodInvokeHints(PropertyValuesBean.class, "setTest", "setSpring");
assertHasDecalredFieldsHint(PropertyValuesBean.class); assertHasDeclaredFieldsHint(PropertyValuesBean.class);
} }
@Test @Test
@ -300,8 +300,8 @@ class BeanDefinitionPropertiesCodeGeneratorTests {
assertThat(actual.getPropertyValues().get("spring")).isEqualTo("framework"); assertThat(actual.getPropertyValues().get("spring")).isEqualTo("framework");
}); });
assertHasMethodInvokeHints(PropertyValuesBean.class, "setTest", "setSpring"); assertHasMethodInvokeHints(PropertyValuesBean.class, "setTest", "setSpring");
assertHasDecalredFieldsHint(ExtendedPropertyValuesBean.class); assertHasDeclaredFieldsHint(ExtendedPropertyValuesBean.class);
assertHasDecalredFieldsHint(PropertyValuesBean.class); assertHasDeclaredFieldsHint(PropertyValuesBean.class);
} }
@Test @Test
@ -362,7 +362,7 @@ class BeanDefinitionPropertiesCodeGeneratorTests {
assertThat(actual.getPropertyValues().get("name")).isEqualTo("World"); assertThat(actual.getPropertyValues().get("name")).isEqualTo("World");
}); });
assertHasMethodInvokeHints(PropertyValuesFactoryBean.class, "setPrefix", "setName" ); assertHasMethodInvokeHints(PropertyValuesFactoryBean.class, "setPrefix", "setName" );
assertHasDecalredFieldsHint(PropertyValuesFactoryBean.class); assertHasDeclaredFieldsHint(PropertyValuesFactoryBean.class);
} }
@Test @Test
@ -516,7 +516,7 @@ class BeanDefinitionPropertiesCodeGeneratorTests {
.test(this.generationContext.getRuntimeHints())); .test(this.generationContext.getRuntimeHints()));
} }
private void assertHasDecalredFieldsHint(Class<?> beanType) { private void assertHasDeclaredFieldsHint(Class<?> beanType) {
assertThat(RuntimeHintsPredicates.reflection() assertThat(RuntimeHintsPredicates.reflection()
.onType(beanType).withMemberCategory(MemberCategory.DECLARED_FIELDS)) .onType(beanType).withMemberCategory(MemberCategory.DECLARED_FIELDS))
.accepts(this.generationContext.getRuntimeHints()); .accepts(this.generationContext.getRuntimeHints());

2
spring-context/src/main/java/org/springframework/context/annotation/ConfigurationClassPostProcessor.java

@ -511,7 +511,7 @@ public class ConfigurationClassPostProcessor implements BeanDefinitionRegistryPo
logger.warn("Cannot enhance @Configuration bean definition '" + beanName + logger.warn("Cannot enhance @Configuration bean definition '" + beanName +
"' since its singleton instance has been created too early. The typical cause " + "' since its singleton instance has been created too early. The typical cause " +
"is a non-static @Bean method with a BeanDefinitionRegistryPostProcessor " + "is a non-static @Bean method with a BeanDefinitionRegistryPostProcessor " +
"return type: Consider declaring such methods as 'static' and/or mark the " + "return type: Consider declaring such methods as 'static' and/or marking the " +
"containing configuration class as 'proxyBeanMethods=false'."); "containing configuration class as 'proxyBeanMethods=false'.");
} }
configBeanDefs.put(beanName, abd); configBeanDefs.put(beanName, abd);

2
spring-context/src/main/java/org/springframework/validation/beanvalidation/MethodValidationInterceptor.java

@ -240,7 +240,7 @@ public class MethodValidationInterceptor implements MethodInterceptor {
ReactiveAdapterRegistry.getSharedInstance(); ReactiveAdapterRegistry.getSharedInstance();
public static Object[] insertAsyncValidation( static Object[] insertAsyncValidation(
Supplier<SpringValidatorAdapter> validatorAdapterSupplier, boolean adaptViolations, Supplier<SpringValidatorAdapter> validatorAdapterSupplier, boolean adaptViolations,
Object target, Method method, Object[] arguments) { Object target, Method method, Object[] arguments) {

2
spring-context/src/test/java/org/springframework/format/datetime/standard/InstantFormatterTests.java

@ -82,7 +82,7 @@ class InstantFormatterTests {
@ParameterizedTest @ParameterizedTest
@ArgumentsSource(RandomEpochMillisProvider.class) @ArgumentsSource(RandomEpochMillisProvider.class)
void should_parse_into_an_Instant_from_epoch_mili(Instant input) throws ParseException { void should_parse_into_an_Instant_from_epoch_milli(Instant input) throws ParseException {
Instant expected = input; Instant expected = input;
Instant actual = instantFormatter.parse(Long.toString(input.toEpochMilli()), null); Instant actual = instantFormatter.parse(Long.toString(input.toEpochMilli()), null);

2
spring-context/src/test/java/org/springframework/format/support/FormattingConversionServiceRuntimeHintsTests.java

@ -44,7 +44,7 @@ class FormattingConversionServiceRuntimeHintsTests {
} }
@Test @Test
void montearyAmountHasHints() { void monetaryAmountHasHints() {
assertThat(RuntimeHintsPredicates.reflection().onType(javax.money.MonetaryAmount.class)).accepts(this.hints); assertThat(RuntimeHintsPredicates.reflection().onType(javax.money.MonetaryAmount.class)).accepts(this.hints);
} }

4
spring-context/src/test/java/org/springframework/validation/beanvalidation/MethodValidationProxyReactorTests.java

@ -36,9 +36,11 @@ import org.springframework.validation.method.ParameterErrors;
import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThat;
/** /**
* Tests for method validation proxy with reactor.
* *
* @author Rossen Stoyanchev
*/ */
public class MethodValidationProxyReactorTests { class MethodValidationProxyReactorTests {
@Test @Test
void validMonoArgument() { void validMonoArgument() {

4
spring-core/src/jmh/java/org/springframework/core/env/CompositePropertySourceBenchmark.java vendored

@ -62,7 +62,7 @@ public class CompositePropertySourceBenchmark {
CompositePropertySource composite; CompositePropertySource composite;
@Param({ "2", "5", "10" }) @Param({ "2", "5", "10" })
int numberOfPropertySource; int numberOfPropertySources;
@Param({ "10", "100", "1000" }) @Param({ "10", "100", "1000" })
int numberOfPropertyNamesPerSource; int numberOfPropertyNamesPerSource;
@ -70,7 +70,7 @@ public class CompositePropertySourceBenchmark {
@Setup(Level.Trial) @Setup(Level.Trial)
public void setUp() { public void setUp() {
this.composite = new CompositePropertySource("benchmark"); this.composite = new CompositePropertySource("benchmark");
for (int i = 0; i < this.numberOfPropertySource; i++) { for (int i = 0; i < this.numberOfPropertySources; i++) {
Map<String, Object> map = new HashMap<>(this.numberOfPropertyNamesPerSource); Map<String, Object> map = new HashMap<>(this.numberOfPropertyNamesPerSource);
for (int j = 0; j < this.numberOfPropertyNamesPerSource; j++) { for (int j = 0; j < this.numberOfPropertyNamesPerSource; j++) {
map.put(ID_GENERATOR.generateId().toString(), VALUE); map.put(ID_GENERATOR.generateId().toString(), VALUE);

4
spring-core/src/main/java/org/springframework/core/io/buffer/OutputStreamPublisher.java

@ -54,7 +54,7 @@ final class OutputStreamPublisher implements Publisher<DataBuffer> {
private final int chunkSize; private final int chunkSize;
public OutputStreamPublisher(Consumer<OutputStream> outputStreamConsumer, DataBufferFactory bufferFactory, OutputStreamPublisher(Consumer<OutputStream> outputStreamConsumer, DataBufferFactory bufferFactory,
Executor executor, int chunkSize) { Executor executor, int chunkSize) {
this.outputStreamConsumer = outputStreamConsumer; this.outputStreamConsumer = outputStreamConsumer;
@ -99,7 +99,7 @@ final class OutputStreamPublisher implements Publisher<DataBuffer> {
private long produced; private long produced;
public OutputStreamSubscription(Subscriber<? super DataBuffer> actual, OutputStreamSubscription(Subscriber<? super DataBuffer> actual,
Consumer<OutputStream> outputStreamConsumer, DataBufferFactory bufferFactory, int chunkSize) { Consumer<OutputStream> outputStreamConsumer, DataBufferFactory bufferFactory, int chunkSize) {
this.actual = actual; this.actual = actual;

2
spring-core/src/main/java/org/springframework/core/task/support/ContextPropagatingTaskDecorator.java

@ -22,7 +22,7 @@ import io.micrometer.context.ContextSnapshotFactory;
import org.springframework.core.task.TaskDecorator; import org.springframework.core.task.TaskDecorator;
/** /**
* {@link TaskDecorator} that {@link ContextSnapshot#wrap(Runnable) wrap the execution} of * {@link TaskDecorator} that {@link ContextSnapshot#wrap(Runnable) wraps the execution} of
* tasks, assisting with context propagation. * tasks, assisting with context propagation.
* <p>This operation is only useful when the task execution is scheduled on a different * <p>This operation is only useful when the task execution is scheduled on a different
* thread than the original call stack; this depends on the choice of * thread than the original call stack; this depends on the choice of

2
spring-core/src/main/java/org/springframework/util/function/SingletonSupplier.java

@ -49,7 +49,7 @@ public class SingletonSupplier<T> implements Supplier<T> {
private volatile T singletonInstance; private volatile T singletonInstance;
/** /**
* Guards access to write operations on the response. * Guards access to write operations on the {@code singletonInstance} field.
*/ */
private final Lock writeLock = new ReentrantLock(); private final Lock writeLock = new ReentrantLock();

8
spring-core/src/test/java/org/springframework/core/task/support/ContextPropagatingTaskDecoratorTests.java

@ -52,15 +52,15 @@ class ContextPropagatingTaskDecoratorTests {
private static final ThreadLocal<String> holder = new ThreadLocal<>(); private static final ThreadLocal<String> holder = new ThreadLocal<>();
public static void setValue(String value) { static void setValue(String value) {
holder.set(value); holder.set(value);
} }
public static String getValue() { static String getValue() {
return holder.get(); return holder.get();
} }
public static void reset() { static void reset() {
holder.remove(); holder.remove();
} }
@ -68,7 +68,7 @@ class ContextPropagatingTaskDecoratorTests {
static class TestThreadLocalAccessor implements ThreadLocalAccessor<String> { static class TestThreadLocalAccessor implements ThreadLocalAccessor<String> {
public static final String KEY = "test.threadlocal"; static final String KEY = "test.threadlocal";
@Override @Override
public Object key() { public Object key() {

2
spring-orm/src/main/java/org/springframework/orm/jpa/persistenceunit/DefaultPersistenceUnitManager.java

@ -716,7 +716,7 @@ public class DefaultPersistenceUnitManager
*/ */
private static class BeanValidationDelegate { private static class BeanValidationDelegate {
public static boolean isValidationProviderPresent() { static boolean isValidationProviderPresent() {
try { try {
Validation.byDefaultProvider().configure(); Validation.byDefaultProvider().configure();
return true; return true;

2
spring-web/src/main/java/org/springframework/web/filter/reactive/ServerHttpObservationFilter.java

@ -115,7 +115,7 @@ public class ServerHttpObservationFilter implements WebFilter {
private final AtomicBoolean observationRecorded = new AtomicBoolean(); private final AtomicBoolean observationRecorded = new AtomicBoolean();
public ObservationSignalListener(ServerRequestObservationContext observationContext) { ObservationSignalListener(ServerRequestObservationContext observationContext) {
this.observationContext = observationContext; this.observationContext = observationContext;
this.observation = ServerHttpObservationDocumentation.HTTP_REACTIVE_SERVER_REQUESTS.observation(observationConvention, this.observation = ServerHttpObservationDocumentation.HTTP_REACTIVE_SERVER_REQUESTS.observation(observationConvention,
DEFAULT_OBSERVATION_CONVENTION, () -> observationContext, observationRegistry); DEFAULT_OBSERVATION_CONVENTION, () -> observationContext, observationRegistry);

2
spring-web/src/main/java/org/springframework/web/server/adapter/HttpWebHandlerAdapter.java

@ -367,7 +367,7 @@ public class HttpWebHandlerAdapter extends WebHandlerDecorator implements HttpHa
private final AtomicBoolean observationRecorded = new AtomicBoolean(); private final AtomicBoolean observationRecorded = new AtomicBoolean();
public ObservationSignalListener(ServerRequestObservationContext observationContext) { ObservationSignalListener(ServerRequestObservationContext observationContext) {
this.observationContext = observationContext; this.observationContext = observationContext;
this.observation = ServerHttpObservationDocumentation.HTTP_REACTIVE_SERVER_REQUESTS.observation(observationConvention, this.observation = ServerHttpObservationDocumentation.HTTP_REACTIVE_SERVER_REQUESTS.observation(observationConvention,
DEFAULT_OBSERVATION_CONVENTION, () -> observationContext, observationRegistry); DEFAULT_OBSERVATION_CONVENTION, () -> observationContext, observationRegistry);

2
spring-web/src/test/java/org/springframework/http/client/reactive/ReactorClientHttpConnectorTests.java

@ -28,7 +28,7 @@ import static org.assertj.core.api.Assertions.assertThat;
/** /**
* @author Sebastien Deleuze * @author Sebastien Deleuze
*/ */
public class ReactorClientHttpConnectorTests { class ReactorClientHttpConnectorTests {
@Test @Test
void restartWithDefaultConstructor() { void restartWithDefaultConstructor() {

2
spring-webflux/src/main/java/org/springframework/web/reactive/DispatchExceptionHandler.java

@ -30,7 +30,7 @@ import org.springframework.web.server.ServerWebExchange;
* from asynchronous return values, and to response rendering. * from asynchronous return values, and to response rendering.
* <li>Implemented by a {@link HandlerAdapter} in order to handle exceptions that * <li>Implemented by a {@link HandlerAdapter} in order to handle exceptions that
* occur before a request is mapped to a handler, or for unhandled errors from a * occur before a request is mapped to a handler, or for unhandled errors from a
* handler.. * handler.
* </ul> * </ul>
* *
* @author Rossen Stoyanchev * @author Rossen Stoyanchev

2
spring-webflux/src/main/kotlin/org/springframework/web/reactive/function/server/CoRouterFunctionDsl.kt

@ -628,7 +628,7 @@ class CoRouterFunctionDsl internal constructor (private val init: (CoRouterFunct
*/ */
fun context(provider: suspend (ServerRequest) -> CoroutineContext) { fun context(provider: suspend (ServerRequest) -> CoroutineContext) {
if (this.contextProvider != null) { if (this.contextProvider != null) {
throw IllegalStateException("The Coroutine context provider should be defined not more than once") throw IllegalStateException("The Coroutine context provider should not be defined more than once")
} }
this.contextProvider = provider this.contextProvider = provider
} }

2
spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/RequestMappingHandlerAdapter.java

@ -1049,7 +1049,7 @@ public class RequestMappingHandlerAdapter extends AbstractHandlerMethodAdapter
private static boolean taskExecutorWarning = true; private static boolean taskExecutorWarning = true;
public MvcSimpleAsyncTaskExecutor() { MvcSimpleAsyncTaskExecutor() {
super("MvcAsync"); super("MvcAsync");
} }

Loading…
Cancel
Save