Skip to content

Commit 5c9f364

Browse files
committed
Polishing
(cherry picked from commit ec1f5ca)
1 parent 55f9581 commit 5c9f364

File tree

4 files changed

+26
-25
lines changed

4 files changed

+26
-25
lines changed

Diff for: spring-context/src/main/java/org/springframework/context/annotation/ConfigurationClassEnhancer.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2022 the original author or authors.
2+
* Copyright 2002-2024 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -225,7 +225,6 @@ public void end_class() {
225225
};
226226
return new TransformingClassGenerator(cg, transformer);
227227
}
228-
229228
}
230229

231230

@@ -334,6 +333,7 @@ public Object intercept(Object enhancedConfigInstance, Method beanMethod, Object
334333
return resolveBeanReference(beanMethod, beanMethodArgs, beanFactory, beanName);
335334
}
336335

336+
@Nullable
337337
private Object resolveBeanReference(Method beanMethod, Object[] beanMethodArgs,
338338
ConfigurableBeanFactory beanFactory, String beanName) {
339339

Diff for: spring-context/src/main/java/org/springframework/context/annotation/ConfigurationClassPostProcessor.java

+13-12
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2023 the original author or authors.
2+
* Copyright 2002-2024 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -386,11 +386,11 @@ else if (ConfigurationClassUtils.checkConfigurationClassCandidate(beanDef, this.
386386
});
387387

388388
// Detect any custom bean name generation strategy supplied through the enclosing application context
389-
SingletonBeanRegistry sbr = null;
390-
if (registry instanceof SingletonBeanRegistry _sbr) {
391-
sbr = _sbr;
389+
SingletonBeanRegistry singletonRegistry = null;
390+
if (registry instanceof SingletonBeanRegistry sbr) {
391+
singletonRegistry = sbr;
392392
if (!this.localBeanNameGeneratorSet) {
393-
BeanNameGenerator generator = (BeanNameGenerator) sbr.getSingleton(
393+
BeanNameGenerator generator = (BeanNameGenerator) singletonRegistry.getSingleton(
394394
AnnotationConfigUtils.CONFIGURATION_BEAN_NAME_GENERATOR);
395395
if (generator != null) {
396396
this.componentScanBeanNameGenerator = generator;
@@ -451,8 +451,8 @@ else if (ConfigurationClassUtils.checkConfigurationClassCandidate(beanDef, this.
451451
while (!candidates.isEmpty());
452452

453453
// Register the ImportRegistry as a bean in order to support ImportAware @Configuration classes
454-
if (sbr != null && !sbr.containsSingleton(IMPORT_REGISTRY_BEAN_NAME)) {
455-
sbr.registerSingleton(IMPORT_REGISTRY_BEAN_NAME, parser.getImportRegistry());
454+
if (singletonRegistry != null && !singletonRegistry.containsSingleton(IMPORT_REGISTRY_BEAN_NAME)) {
455+
singletonRegistry.registerSingleton(IMPORT_REGISTRY_BEAN_NAME, parser.getImportRegistry());
456456
}
457457

458458
// Store the PropertySourceDescriptors to contribute them Ahead-of-time if necessary
@@ -550,6 +550,7 @@ public ImportAwareBeanPostProcessor(BeanFactory beanFactory) {
550550
}
551551

552552
@Override
553+
@Nullable
553554
public PropertyValues postProcessProperties(@Nullable PropertyValues pvs, Object bean, String beanName) {
554555
// Inject the BeanFactory before AutowiredAnnotationBeanPostProcessor's
555556
// postProcessProperties method attempts to autowire other configuration beans.
@@ -645,9 +646,9 @@ private Map<String, String> buildImportAwareMappings() {
645646
}
646647
return mappings;
647648
}
648-
649649
}
650650

651+
651652
private static class PropertySourcesAotContribution implements BeanFactoryInitializationAotContribution {
652653

653654
private static final String ENVIRONMENT_VARIABLE = "environment";
@@ -743,22 +744,22 @@ private CodeBlock handleNull(@Nullable Object value, Supplier<CodeBlock> nonNull
743744
return nonNull.get();
744745
}
745746
}
746-
747747
}
748748

749+
749750
private static class ConfigurationClassProxyBeanRegistrationCodeFragments extends BeanRegistrationCodeFragmentsDecorator {
750751

751752
private final Class<?> proxyClass;
752753

753-
public ConfigurationClassProxyBeanRegistrationCodeFragments(BeanRegistrationCodeFragments codeFragments,
754-
Class<?> proxyClass) {
754+
public ConfigurationClassProxyBeanRegistrationCodeFragments(BeanRegistrationCodeFragments codeFragments, Class<?> proxyClass) {
755755
super(codeFragments);
756756
this.proxyClass = proxyClass;
757757
}
758758

759759
@Override
760760
public CodeBlock generateSetBeanDefinitionPropertiesCode(GenerationContext generationContext,
761761
BeanRegistrationCode beanRegistrationCode, RootBeanDefinition beanDefinition, Predicate<String> attributeFilter) {
762+
762763
CodeBlock.Builder code = CodeBlock.builder();
763764
code.add(super.generateSetBeanDefinitionPropertiesCode(generationContext,
764765
beanRegistrationCode, beanDefinition, attributeFilter));
@@ -771,6 +772,7 @@ public CodeBlock generateSetBeanDefinitionPropertiesCode(GenerationContext gener
771772
public CodeBlock generateInstanceSupplierCode(GenerationContext generationContext,
772773
BeanRegistrationCode beanRegistrationCode, Executable constructorOrFactoryMethod,
773774
boolean allowDirectSupplierShortcut) {
775+
774776
Executable executableToUse = proxyExecutable(generationContext.getRuntimeHints(), constructorOrFactoryMethod);
775777
return super.generateInstanceSupplierCode(generationContext, beanRegistrationCode,
776778
executableToUse, allowDirectSupplierShortcut);
@@ -788,7 +790,6 @@ private Executable proxyExecutable(RuntimeHints runtimeHints, Executable userExe
788790
}
789791
return userExecutable;
790792
}
791-
792793
}
793794

794795
}

Diff for: spring-context/src/test/java/org/springframework/context/annotation/ConfigurationClassPostProcessorAotContributionTests.java

+10-10
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2023 the original author or authors.
2+
* Copyright 2002-2024 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -99,8 +99,8 @@ void applyToWhenHasImportAwareConfigurationRegistersBeanPostProcessorWithMapEntr
9999
initializer.accept(freshBeanFactory);
100100
freshContext.refresh();
101101
assertThat(freshBeanFactory.getBeanPostProcessors()).filteredOn(ImportAwareAotBeanPostProcessor.class::isInstance)
102-
.singleElement().satisfies(postProcessor -> assertPostProcessorEntry(postProcessor, ImportAwareConfiguration.class,
103-
ImportConfiguration.class));
102+
.singleElement().satisfies(postProcessor ->
103+
assertPostProcessorEntry(postProcessor, ImportAwareConfiguration.class, ImportConfiguration.class));
104104
freshContext.close();
105105
});
106106
}
@@ -117,8 +117,8 @@ void applyToWhenHasImportAwareConfigurationRegistersBeanPostProcessorAfterApplic
117117
freshContext.refresh();
118118
TestAwareCallbackBean bean = freshContext.getBean(TestAwareCallbackBean.class);
119119
assertThat(bean.instances).hasSize(2);
120-
assertThat(bean.instances.get(0)).isEqualTo(freshContext);
121-
assertThat(bean.instances.get(1)).isInstanceOfSatisfying(AnnotationMetadata.class, metadata ->
120+
assertThat(bean.instances).element(0).isEqualTo(freshContext);
121+
assertThat(bean.instances).element(1).isInstanceOfSatisfying(AnnotationMetadata.class, metadata ->
122122
assertThat(metadata.getClassName()).isEqualTo(TestAwareCallbackConfiguration.class.getName()));
123123
freshContext.close();
124124
});
@@ -236,13 +236,14 @@ public int getOrder() {
236236
}
237237

238238
@Override
239-
public void afterPropertiesSet() throws Exception {
239+
public void afterPropertiesSet() {
240240
Assert.notNull(this.metadata, "Metadata was not injected");
241241
}
242242

243243
}
244244
}
245245

246+
246247
@Nested
247248
class PropertySourceTests {
248249

@@ -362,9 +363,9 @@ static class PropertySourceWithDetailsConfiguration {
362363
static class PropertySourceWithCustomFactoryConfiguration {
363364

364365
}
365-
366366
}
367367

368+
368369
@Nested
369370
class ConfigurationClassProxyTests {
370371

@@ -384,15 +385,14 @@ void processAheadOfTimeFullConfigurationClass() {
384385
getRegisteredBean(CglibConfiguration.class))).isNotNull();
385386
}
386387

387-
388388
private RegisteredBean getRegisteredBean(Class<?> bean) {
389389
this.beanFactory.registerBeanDefinition("test", new RootBeanDefinition(bean));
390390
this.processor.postProcessBeanFactory(this.beanFactory);
391391
return RegisteredBean.of(this.beanFactory, "test");
392392
}
393-
394393
}
395394

395+
396396
@Nullable
397397
private BeanFactoryInitializationAotContribution getContribution(Class<?>... types) {
398398
DefaultListableBeanFactory beanFactory = new DefaultListableBeanFactory();
@@ -410,8 +410,8 @@ private void assertPostProcessorEntry(BeanPostProcessor postProcessor, Class<?>
410410
.containsExactly(entry(key.getName(), value.getName()));
411411
}
412412

413-
static class CustomPropertySourcesFactory extends DefaultPropertySourceFactory {
414413

414+
static class CustomPropertySourcesFactory extends DefaultPropertySourceFactory {
415415
}
416416

417417
}

Diff for: spring-core/src/main/java/org/springframework/cglib/core/ReflectUtils.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ private ReflectUtils() {
7575
Throwable throwable = null;
7676
try {
7777
classLoaderDefineClass = ClassLoader.class.getDeclaredMethod("defineClass",
78-
String.class, byte[].class, Integer.TYPE, Integer.TYPE, ProtectionDomain.class);
78+
String.class, byte[].class, Integer.TYPE, Integer.TYPE, ProtectionDomain.class);
7979
}
8080
catch (Throwable t) {
8181
classLoaderDefineClass = null;

0 commit comments

Comments
 (0)