Browse Source

Polishing

pull/31496/head
Juergen Hoeller 2 years ago
parent
commit
2ce75dc415
  1. 4
      spring-context-support/src/main/java/org/springframework/cache/jcache/interceptor/BeanFactoryJCacheOperationSourceAdvisor.java
  2. 4
      spring-context/src/main/java/org/springframework/cache/interceptor/CacheOperationSourcePointcut.java
  3. 16
      spring-context/src/main/java/org/springframework/context/annotation/PropertySourceRegistry.java
  4. 20
      spring-context/src/test/java/org/springframework/context/annotation/PropertySourceAnnotationTests.java
  5. 2
      spring-jdbc/src/main/java/org/springframework/jdbc/core/BeanPropertyRowMapper.java
  6. 3
      spring-messaging/src/main/java/org/springframework/messaging/handler/annotation/support/PayloadMethodArgumentResolver.java
  7. 4
      spring-tx/src/main/java/org/springframework/transaction/interceptor/TransactionAttributeSourcePointcut.java

4
spring-context-support/src/main/java/org/springframework/cache/jcache/interceptor/BeanFactoryJCacheOperationSourceAdvisor.java vendored

@ -82,8 +82,8 @@ public class BeanFactoryJCacheOperationSourceAdvisor extends AbstractBeanFactory
@Override @Override
public boolean equals(@Nullable Object other) { public boolean equals(@Nullable Object other) {
return (this == other || (other instanceof JCacheOperationSourcePointcut otherPc && return (this == other || (other instanceof JCacheOperationSourcePointcut that &&
ObjectUtils.nullSafeEquals(this.cacheOperationSource, otherPc.cacheOperationSource))); ObjectUtils.nullSafeEquals(this.cacheOperationSource, that.cacheOperationSource)));
} }
@Override @Override

4
spring-context/src/main/java/org/springframework/cache/interceptor/CacheOperationSourcePointcut.java vendored

@ -58,8 +58,8 @@ class CacheOperationSourcePointcut extends StaticMethodMatcherPointcut implement
@Override @Override
public boolean equals(@Nullable Object other) { public boolean equals(@Nullable Object other) {
return (this == other || (other instanceof CacheOperationSourcePointcut otherPc && return (this == other || (other instanceof CacheOperationSourcePointcut that &&
ObjectUtils.nullSafeEquals(this.cacheOperationSource, otherPc.cacheOperationSource))); ObjectUtils.nullSafeEquals(this.cacheOperationSource, that.cacheOperationSource)));
} }
@Override @Override

16
spring-context/src/main/java/org/springframework/context/annotation/PropertySourceRegistry.java

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2022 the original author or authors. * Copyright 2002-2023 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.
@ -42,14 +42,12 @@ class PropertySourceRegistry {
private final List<PropertySourceDescriptor> descriptors; private final List<PropertySourceDescriptor> descriptors;
public PropertySourceRegistry(PropertySourceProcessor propertySourceProcessor) { public PropertySourceRegistry(PropertySourceProcessor propertySourceProcessor) {
this.propertySourceProcessor = propertySourceProcessor; this.propertySourceProcessor = propertySourceProcessor;
this.descriptors = new ArrayList<>(); this.descriptors = new ArrayList<>();
} }
public List<PropertySourceDescriptor> getDescriptors() {
return Collections.unmodifiableList(this.descriptors);
}
/** /**
* Process the given <code>@PropertySource</code> annotation metadata. * Process the given <code>@PropertySource</code> annotation metadata.
@ -70,12 +68,16 @@ class PropertySourceRegistry {
boolean ignoreResourceNotFound = propertySource.getBoolean("ignoreResourceNotFound"); boolean ignoreResourceNotFound = propertySource.getBoolean("ignoreResourceNotFound");
Class<? extends PropertySourceFactory> factoryClass = propertySource.getClass("factory"); Class<? extends PropertySourceFactory> factoryClass = propertySource.getClass("factory");
Class<? extends PropertySourceFactory> factorClassToUse = Class<? extends PropertySourceFactory> factoryClassToUse =
(factoryClass != PropertySourceFactory.class ? factoryClass : null); (factoryClass != PropertySourceFactory.class ? factoryClass : null);
PropertySourceDescriptor descriptor = new PropertySourceDescriptor(Arrays.asList(locations), ignoreResourceNotFound, name, PropertySourceDescriptor descriptor = new PropertySourceDescriptor(Arrays.asList(locations),
factorClassToUse, encoding); ignoreResourceNotFound, name, factoryClassToUse, encoding);
this.propertySourceProcessor.processPropertySource(descriptor); this.propertySourceProcessor.processPropertySource(descriptor);
this.descriptors.add(descriptor); this.descriptors.add(descriptor);
} }
public List<PropertySourceDescriptor> getDescriptors() {
return Collections.unmodifiableList(this.descriptors);
}
} }

20
spring-context/src/test/java/org/springframework/context/annotation/PropertySourceAnnotationTests.java

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2021 the original author or authors. * Copyright 2002-2023 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.
@ -23,7 +23,6 @@ import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy; import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target; import java.lang.annotation.Target;
import java.util.Collections; import java.util.Collections;
import java.util.Iterator;
import java.util.Properties; import java.util.Properties;
import jakarta.inject.Inject; import jakarta.inject.Inject;
@ -56,21 +55,13 @@ class PropertySourceAnnotationTests {
@Test @Test
void withExplicitName() { void withExplicitName() {
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(); AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(ConfigWithExplicitName.class);
ctx.register(ConfigWithExplicitName.class);
ctx.refresh();
assertThat(ctx.getEnvironment().getPropertySources().contains("p1")).as("property source p1 was not added").isTrue(); assertThat(ctx.getEnvironment().getPropertySources().contains("p1")).as("property source p1 was not added").isTrue();
assertThat(ctx.getBean(TestBean.class).getName()).isEqualTo("p1TestBean"); assertThat(ctx.getBean(TestBean.class).getName()).isEqualTo("p1TestBean");
// assert that the property source was added last to the set of sources // assert that the property source was added last to the set of sources
String name;
MutablePropertySources sources = ctx.getEnvironment().getPropertySources(); MutablePropertySources sources = ctx.getEnvironment().getPropertySources();
Iterator<org.springframework.core.env.PropertySource<?>> iterator = sources.iterator(); String name = sources.stream().toList().get(sources.size() - 1).getName();
do {
name = iterator.next().getName();
}
while (iterator.hasNext());
assertThat(name).isEqualTo("p1"); assertThat(name).isEqualTo("p1");
ctx.close(); ctx.close();
} }
@ -78,7 +69,9 @@ class PropertySourceAnnotationTests {
@Test @Test
void withImplicitName() { void withImplicitName() {
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(ConfigWithImplicitName.class); AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(ConfigWithImplicitName.class);
assertThat(ctx.getEnvironment().getPropertySources().contains("class path resource [org/springframework/context/annotation/p1.properties]")).as("property source p1 was not added").isTrue(); String name = "class path resource [org/springframework/context/annotation/p1.properties]";
assertThat(ctx.getEnvironment().getPropertySources().contains(name))
.as("property source p1 was not added").isTrue();
assertThat(ctx.getBean(TestBean.class).getName()).isEqualTo("p1TestBean"); assertThat(ctx.getBean(TestBean.class).getName()).isEqualTo("p1TestBean");
ctx.close(); ctx.close();
} }
@ -540,7 +533,6 @@ class PropertySourceAnnotationTests {
}) })
@Configuration @Configuration
static class ConfigWithSameSourceImportedInDifferentOrder { static class ConfigWithSameSourceImportedInDifferentOrder {
} }

2
spring-jdbc/src/main/java/org/springframework/jdbc/core/BeanPropertyRowMapper.java

@ -343,7 +343,7 @@ public class BeanPropertyRowMapper<T> implements RowMapper<T> {
bw.setPropertyValue(pd.getName(), value); bw.setPropertyValue(pd.getName(), value);
} }
catch (TypeMismatchException ex) { catch (TypeMismatchException ex) {
if (value == null && this.primitivesDefaultedForNullValue) { if (value == null && isPrimitivesDefaultedForNullValue()) {
if (logger.isDebugEnabled()) { if (logger.isDebugEnabled()) {
String propertyType = ClassUtils.getQualifiedName(pd.getPropertyType()); String propertyType = ClassUtils.getQualifiedName(pd.getPropertyType());
logger.debug(""" logger.debug("""

3
spring-messaging/src/main/java/org/springframework/messaging/handler/annotation/support/PayloadMethodArgumentResolver.java

@ -197,8 +197,7 @@ public class PayloadMethodArgumentResolver implements HandlerMethodArgumentResol
/** /**
* Validate the payload if applicable. * Validate the payload if applicable.
* <p>The default implementation checks for {@code @jakarta.validation.Valid}, * <p>The default implementation checks for {@code @jakarta.validation.Valid},
* Spring's {@link Validated}, * Spring's {@link Validated}, and custom annotations whose name starts with "Valid".
* and custom annotations whose name starts with "Valid".
* @param message the currently processed message * @param message the currently processed message
* @param parameter the method parameter * @param parameter the method parameter
* @param target the target payload object * @param target the target payload object

4
spring-tx/src/main/java/org/springframework/transaction/interceptor/TransactionAttributeSourcePointcut.java

@ -57,8 +57,8 @@ class TransactionAttributeSourcePointcut extends StaticMethodMatcherPointcut imp
@Override @Override
public boolean equals(@Nullable Object other) { public boolean equals(@Nullable Object other) {
return (this == other || (other instanceof TransactionAttributeSourcePointcut otherPc && return (this == other || (other instanceof TransactionAttributeSourcePointcut that &&
ObjectUtils.nullSafeEquals(this.transactionAttributeSource, otherPc.transactionAttributeSource))); ObjectUtils.nullSafeEquals(this.transactionAttributeSource, that.transactionAttributeSource)));
} }
@Override @Override

Loading…
Cancel
Save