Skip to content

Commit 622d083

Browse files
committed
Polishing
1 parent 56dbe06 commit 622d083

File tree

2 files changed

+22
-16
lines changed

2 files changed

+22
-16
lines changed

spring-beans/src/main/java/org/springframework/beans/factory/support/ConstructorResolver.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@
6767

6868
/**
6969
* Delegate for resolving constructors and factory methods.
70+
*
7071
* <p>Performs constructor resolution through argument matching.
7172
*
7273
* @author Juergen Hoeller
@@ -85,7 +86,7 @@ class ConstructorResolver {
8586
private static final Object[] EMPTY_ARGS = new Object[0];
8687

8788
/**
88-
* Marker for autowired arguments in a cached argument array, to be later replaced
89+
* Marker for autowired arguments in a cached argument array, to be replaced
8990
* by a {@linkplain #resolveAutowiredArgument resolved autowired argument}.
9091
*/
9192
private static final Object autowiredArgumentMarker = new Object();
@@ -149,7 +150,7 @@ public BeanWrapper autowireConstructor(String beanName, RootBeanDefinition mbd,
149150
}
150151
}
151152
if (argsToResolve != null) {
152-
argsToUse = resolvePreparedArguments(beanName, mbd, bw, constructorToUse, argsToResolve, true);
153+
argsToUse = resolvePreparedArguments(beanName, mbd, bw, constructorToUse, argsToResolve);
153154
}
154155
}
155156

@@ -445,7 +446,7 @@ public BeanWrapper instantiateUsingFactoryMethod(
445446
}
446447
}
447448
if (argsToResolve != null) {
448-
argsToUse = resolvePreparedArguments(beanName, mbd, bw, factoryMethodToUse, argsToResolve, true);
449+
argsToUse = resolvePreparedArguments(beanName, mbd, bw, factoryMethodToUse, argsToResolve);
449450
}
450451
}
451452

@@ -817,7 +818,7 @@ private ArgumentsHolder createArgumentArray(
817818
* Resolve the prepared arguments stored in the given bean definition.
818819
*/
819820
private Object[] resolvePreparedArguments(String beanName, RootBeanDefinition mbd, BeanWrapper bw,
820-
Executable executable, Object[] argsToResolve, boolean fallback) {
821+
Executable executable, Object[] argsToResolve) {
821822

822823
TypeConverter customConverter = this.beanFactory.getCustomTypeConverter();
823824
TypeConverter converter = (customConverter != null ? customConverter : bw);
@@ -830,7 +831,7 @@ private Object[] resolvePreparedArguments(String beanName, RootBeanDefinition mb
830831
Object argValue = argsToResolve[argIndex];
831832
MethodParameter methodParam = MethodParameter.forExecutable(executable, argIndex);
832833
if (argValue == autowiredArgumentMarker) {
833-
argValue = resolveAutowiredArgument(methodParam, beanName, null, converter, fallback);
834+
argValue = resolveAutowiredArgument(methodParam, beanName, null, converter, true);
834835
}
835836
else if (argValue instanceof BeanMetadataElement) {
836837
argValue = valueResolver.resolveValueIfNecessary("constructor argument", argValue);

spring-beans/src/test/java/org/springframework/beans/factory/BeanFactoryUtilsTests.java

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,8 @@ public class BeanFactoryUtilsTests {
6363

6464

6565
@BeforeEach
66-
public void setUp() {
66+
public void setup() {
6767
// Interesting hierarchical factory to test counts.
68-
// Slow to read so we cache it.
6968

7069
DefaultListableBeanFactory grandParent = new DefaultListableBeanFactory();
7170
new XmlBeanDefinitionReader(grandParent).loadBeanDefinitions(ROOT_CONTEXT);
@@ -93,22 +92,22 @@ public void testHierarchicalCountBeansWithNonHierarchicalFactory() {
9392
* Check that override doesn't count as two separate beans.
9493
*/
9594
@Test
96-
public void testHierarchicalCountBeansWithOverride() throws Exception {
95+
public void testHierarchicalCountBeansWithOverride() {
9796
// Leaf count
9897
assertThat(this.listableBeanFactory.getBeanDefinitionCount() == 1).isTrue();
9998
// Count minus duplicate
10099
assertThat(BeanFactoryUtils.countBeansIncludingAncestors(this.listableBeanFactory) == 8).as("Should count 8 beans, not " + BeanFactoryUtils.countBeansIncludingAncestors(this.listableBeanFactory)).isTrue();
101100
}
102101

103102
@Test
104-
public void testHierarchicalNamesWithNoMatch() throws Exception {
103+
public void testHierarchicalNamesWithNoMatch() {
105104
List<String> names = Arrays.asList(
106105
BeanFactoryUtils.beanNamesForTypeIncludingAncestors(this.listableBeanFactory, NoOp.class));
107106
assertThat(names.size()).isEqualTo(0);
108107
}
109108

110109
@Test
111-
public void testHierarchicalNamesWithMatchOnlyInRoot() throws Exception {
110+
public void testHierarchicalNamesWithMatchOnlyInRoot() {
112111
List<String> names = Arrays.asList(
113112
BeanFactoryUtils.beanNamesForTypeIncludingAncestors(this.listableBeanFactory, IndexedTestBean.class));
114113
assertThat(names.size()).isEqualTo(1);
@@ -118,7 +117,7 @@ public void testHierarchicalNamesWithMatchOnlyInRoot() throws Exception {
118117
}
119118

120119
@Test
121-
public void testGetBeanNamesForTypeWithOverride() throws Exception {
120+
public void testGetBeanNamesForTypeWithOverride() {
122121
List<String> names = Arrays.asList(
123122
BeanFactoryUtils.beanNamesForTypeIncludingAncestors(this.listableBeanFactory, ITestBean.class));
124123
// includes 2 TestBeans from FactoryBeans (DummyFactory definitions)
@@ -236,7 +235,7 @@ public void testFindsBeansOfTypeWithDefaultFactory() {
236235
}
237236

238237
@Test
239-
public void testHierarchicalResolutionWithOverride() throws Exception {
238+
public void testHierarchicalResolutionWithOverride() {
240239
Object test3 = this.listableBeanFactory.getBean("test3");
241240
Object test = this.listableBeanFactory.getBean("test");
242241

@@ -276,14 +275,14 @@ public void testHierarchicalResolutionWithOverride() throws Exception {
276275
}
277276

278277
@Test
279-
public void testHierarchicalNamesForAnnotationWithNoMatch() throws Exception {
278+
public void testHierarchicalNamesForAnnotationWithNoMatch() {
280279
List<String> names = Arrays.asList(
281280
BeanFactoryUtils.beanNamesForAnnotationIncludingAncestors(this.listableBeanFactory, Override.class));
282281
assertThat(names.size()).isEqualTo(0);
283282
}
284283

285284
@Test
286-
public void testHierarchicalNamesForAnnotationWithMatchOnlyInRoot() throws Exception {
285+
public void testHierarchicalNamesForAnnotationWithMatchOnlyInRoot() {
287286
List<String> names = Arrays.asList(
288287
BeanFactoryUtils.beanNamesForAnnotationIncludingAncestors(this.listableBeanFactory, TestAnnotation.class));
289288
assertThat(names.size()).isEqualTo(1);
@@ -293,7 +292,7 @@ public void testHierarchicalNamesForAnnotationWithMatchOnlyInRoot() throws Excep
293292
}
294293

295294
@Test
296-
public void testGetBeanNamesForAnnotationWithOverride() throws Exception {
295+
public void testGetBeanNamesForAnnotationWithOverride() {
297296
AnnotatedBean annotatedBean = new AnnotatedBean();
298297
this.listableBeanFactory.registerSingleton("anotherAnnotatedBean", annotatedBean);
299298
List<String> names = Arrays.asList(
@@ -433,6 +432,7 @@ public void isSingletonAndIsPrototypeWithStaticFactory() {
433432
String basePackage() default "";
434433
}
435434

435+
436436
@Retention(RetentionPolicy.RUNTIME)
437437
@ControllerAdvice
438438
@interface RestControllerAdvice {
@@ -444,18 +444,23 @@ public void isSingletonAndIsPrototypeWithStaticFactory() {
444444
String basePackage() default "";
445445
}
446446

447+
447448
@ControllerAdvice("com.example")
448449
static class ControllerAdviceClass {
449450
}
450451

452+
451453
@RestControllerAdvice("com.example")
452454
static class RestControllerAdviceClass {
453455
}
454456

457+
455458
static class TestBeanSmartFactoryBean implements SmartFactoryBean<TestBean> {
456459

457460
private final TestBean testBean = new TestBean("enigma", 42);
461+
458462
private final boolean singleton;
463+
459464
private final boolean prototype;
460465

461466
TestBeanSmartFactoryBean(boolean singleton, boolean prototype) {
@@ -478,7 +483,7 @@ public Class<TestBean> getObjectType() {
478483
return TestBean.class;
479484
}
480485

481-
public TestBean getObject() throws Exception {
486+
public TestBean getObject() {
482487
// We don't really care if the actual instance is a singleton or prototype
483488
// for the tests that use this factory.
484489
return this.testBean;

0 commit comments

Comments
 (0)