Skip to content

Commit 120d512

Browse files
committed
Polishing (backported from main)
1 parent 3ddf183 commit 120d512

File tree

3 files changed

+9
-22
lines changed

3 files changed

+9
-22
lines changed

spring-beans/src/main/java/org/springframework/beans/factory/annotation/QualifierAnnotationAutowireCandidateResolver.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2020 the original author or authors.
2+
* Copyright 2002-2023 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.
@@ -25,6 +25,7 @@
2525

2626
import org.springframework.beans.SimpleTypeConverter;
2727
import org.springframework.beans.TypeConverter;
28+
import org.springframework.beans.factory.BeanFactory;
2829
import org.springframework.beans.factory.NoSuchBeanDefinitionException;
2930
import org.springframework.beans.factory.config.BeanDefinitionHolder;
3031
import org.springframework.beans.factory.config.DependencyDescriptor;
@@ -240,10 +241,11 @@ protected boolean checkQualifier(
240241
}
241242
}
242243
if (targetAnnotation == null) {
244+
BeanFactory beanFactory = getBeanFactory();
243245
// Look for matching annotation on the target class
244-
if (getBeanFactory() != null) {
246+
if (beanFactory != null) {
245247
try {
246-
Class<?> beanType = getBeanFactory().getType(bdHolder.getBeanName());
248+
Class<?> beanType = beanFactory.getType(bdHolder.getBeanName());
247249
if (beanType != null) {
248250
targetAnnotation = AnnotationUtils.getAnnotation(ClassUtils.getUserClass(beanType), type);
249251
}

spring-beans/src/main/java/org/springframework/beans/factory/xml/XmlBeanDefinitionReader.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2020 the original author or authors.
2+
* Copyright 2002-2023 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.
@@ -547,7 +547,8 @@ public NamespaceHandlerResolver getNamespaceHandlerResolver() {
547547
* @see DefaultNamespaceHandlerResolver#DefaultNamespaceHandlerResolver(ClassLoader)
548548
*/
549549
protected NamespaceHandlerResolver createDefaultNamespaceHandlerResolver() {
550-
ClassLoader cl = (getResourceLoader() != null ? getResourceLoader().getClassLoader() : getBeanClassLoader());
550+
ResourceLoader resourceLoader = getResourceLoader();
551+
ClassLoader cl = (resourceLoader != null ? resourceLoader.getClassLoader() : getBeanClassLoader());
551552
return new DefaultNamespaceHandlerResolver(cl);
552553
}
553554

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

Lines changed: 1 addition & 17 deletions
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-2023 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.
@@ -436,7 +436,6 @@ void nonStaticPrototypeFactoryMethodFoundByNonEagerTypeMatching() {
436436

437437
@Test
438438
void empty() {
439-
ListableBeanFactory lbf = new DefaultListableBeanFactory();
440439
assertThat(lbf.getBeanDefinitionNames() != null).as("No beans defined --> array != null").isTrue();
441440
assertThat(lbf.getBeanDefinitionNames().length == 0).as("No beans defined after no arg constructor").isTrue();
442441
assertThat(lbf.getBeanDefinitionCount() == 0).as("No beans defined after no arg constructor").isTrue();
@@ -778,21 +777,6 @@ void getTypeWorksAfterParentChildMerging() {
778777
assertThat(factory.getType("child")).isEqualTo(DerivedTestBean.class);
779778
}
780779

781-
@Test
782-
void nameAlreadyBound() {
783-
Properties p = new Properties();
784-
p.setProperty("kerry.(class)", TestBean.class.getName());
785-
p.setProperty("kerry.age", "35");
786-
registerBeanDefinitions(p);
787-
try {
788-
registerBeanDefinitions(p);
789-
}
790-
catch (BeanDefinitionStoreException ex) {
791-
assertThat(ex.getBeanName()).isEqualTo("kerry");
792-
// expected
793-
}
794-
}
795-
796780
private void singleTestBean(ListableBeanFactory lbf) {
797781
assertThat(lbf.getBeanDefinitionCount() == 1).as("1 beans defined").isTrue();
798782
String[] names = lbf.getBeanDefinitionNames();

0 commit comments

Comments
 (0)