Skip to content

Commit 5b4511f

Browse files
committed
Merge branch '6.2.x'
2 parents 907c1db + dbd47ff commit 5b4511f

File tree

8 files changed

+29
-20
lines changed

8 files changed

+29
-20
lines changed

Diff for: spring-aop/src/main/java/org/springframework/aop/framework/autoproxy/BeanNameAutoProxyCreator.java

+3-3
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-2025 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.
@@ -112,10 +112,10 @@ private boolean isSupportedBeanName(Class<?> beanClass, String beanName) {
112112
boolean isFactoryBean = FactoryBean.class.isAssignableFrom(beanClass);
113113
for (String mappedName : this.beanNames) {
114114
if (isFactoryBean) {
115-
if (!mappedName.startsWith(BeanFactory.FACTORY_BEAN_PREFIX)) {
115+
if (mappedName.isEmpty() || mappedName.charAt(0) != BeanFactory.FACTORY_BEAN_PREFIX_CHAR) {
116116
continue;
117117
}
118-
mappedName = mappedName.substring(BeanFactory.FACTORY_BEAN_PREFIX.length());
118+
mappedName = mappedName.substring(1); // length of '&'
119119
}
120120
if (isMatch(beanName, mappedName)) {
121121
return true;

Diff for: spring-beans/src/main/java/org/springframework/beans/factory/BeanFactory.java

+8-1
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-2025 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.
@@ -125,9 +125,16 @@ public interface BeanFactory {
125125
* beans <i>created</i> by the FactoryBean. For example, if the bean named
126126
* {@code myJndiObject} is a FactoryBean, getting {@code &myJndiObject}
127127
* will return the factory, not the instance returned by the factory.
128+
* @see #FACTORY_BEAN_PREFIX_CHAR
128129
*/
129130
String FACTORY_BEAN_PREFIX = "&";
130131

132+
/**
133+
* Character variant of {@link #FACTORY_BEAN_PREFIX}.
134+
* @since 6.2.6
135+
*/
136+
char FACTORY_BEAN_PREFIX_CHAR = '&';
137+
131138

132139
/**
133140
* Return an instance, which may be shared or independent, of the specified bean.

Diff for: spring-beans/src/main/java/org/springframework/beans/factory/BeanFactoryUtils.java

+4-4
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ public abstract class BeanFactoryUtils {
7373
* @see BeanFactory#FACTORY_BEAN_PREFIX
7474
*/
7575
public static boolean isFactoryDereference(@Nullable String name) {
76-
return (name != null && name.startsWith(BeanFactory.FACTORY_BEAN_PREFIX));
76+
return (name != null && !name.isEmpty() && name.charAt(0) == BeanFactory.FACTORY_BEAN_PREFIX_CHAR);
7777
}
7878

7979
/**
@@ -85,14 +85,14 @@ public static boolean isFactoryDereference(@Nullable String name) {
8585
*/
8686
public static String transformedBeanName(String name) {
8787
Assert.notNull(name, "'name' must not be null");
88-
if (!name.startsWith(BeanFactory.FACTORY_BEAN_PREFIX)) {
88+
if (name.isEmpty() || name.charAt(0) != BeanFactory.FACTORY_BEAN_PREFIX_CHAR) {
8989
return name;
9090
}
9191
return transformedBeanNameCache.computeIfAbsent(name, beanName -> {
9292
do {
93-
beanName = beanName.substring(BeanFactory.FACTORY_BEAN_PREFIX.length());
93+
beanName = beanName.substring(1); // length of '&'
9494
}
95-
while (beanName.startsWith(BeanFactory.FACTORY_BEAN_PREFIX));
95+
while (beanName.charAt(0) == BeanFactory.FACTORY_BEAN_PREFIX_CHAR);
9696
return beanName;
9797
});
9898
}

Diff for: spring-beans/src/main/java/org/springframework/beans/factory/support/AbstractBeanFactory.java

+5-5
Original file line numberDiff line numberDiff line change
@@ -762,16 +762,16 @@ else if (BeanFactoryUtils.isFactoryDereference(name)) {
762762
public String[] getAliases(String name) {
763763
String beanName = transformedBeanName(name);
764764
List<String> aliases = new ArrayList<>();
765-
boolean factoryPrefix = name.startsWith(FACTORY_BEAN_PREFIX);
765+
boolean hasFactoryPrefix = (!name.isEmpty() && name.charAt(0) == BeanFactory.FACTORY_BEAN_PREFIX_CHAR);
766766
String fullBeanName = beanName;
767-
if (factoryPrefix) {
767+
if (hasFactoryPrefix) {
768768
fullBeanName = FACTORY_BEAN_PREFIX + beanName;
769769
}
770770
if (!fullBeanName.equals(name)) {
771771
aliases.add(fullBeanName);
772772
}
773773
String[] retrievedAliases = super.getAliases(beanName);
774-
String prefix = (factoryPrefix ? FACTORY_BEAN_PREFIX : "");
774+
String prefix = (hasFactoryPrefix ? FACTORY_BEAN_PREFIX : "");
775775
for (String retrievedAlias : retrievedAliases) {
776776
String alias = prefix + retrievedAlias;
777777
if (!alias.equals(name)) {
@@ -1137,7 +1137,7 @@ public void copyConfigurationFrom(ConfigurableBeanFactory otherFactory) {
11371137
public BeanDefinition getMergedBeanDefinition(String name) throws BeansException {
11381138
String beanName = transformedBeanName(name);
11391139
// Efficiently check whether bean definition exists in this factory.
1140-
if (!containsBeanDefinition(beanName) && getParentBeanFactory() instanceof ConfigurableBeanFactory parent) {
1140+
if (getParentBeanFactory() instanceof ConfigurableBeanFactory parent && !containsBeanDefinition(beanName)) {
11411141
return parent.getMergedBeanDefinition(beanName);
11421142
}
11431143
// Resolve merged bean definition locally.
@@ -1276,7 +1276,7 @@ protected String transformedBeanName(String name) {
12761276
*/
12771277
protected String originalBeanName(String name) {
12781278
String beanName = transformedBeanName(name);
1279-
if (name.startsWith(FACTORY_BEAN_PREFIX)) {
1279+
if (!name.isEmpty() && name.charAt(0) == BeanFactory.FACTORY_BEAN_PREFIX_CHAR) {
12801280
beanName = FACTORY_BEAN_PREFIX + beanName;
12811281
}
12821282
return beanName;

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

+3-3
Original file line numberDiff line numberDiff line change
@@ -362,9 +362,9 @@ private static class BeanMethodInterceptor implements MethodInterceptor, Conditi
362362
// proxy that intercepts calls to getObject() and returns any cached bean instance.
363363
// This ensures that the semantics of calling a FactoryBean from within @Bean methods
364364
// is the same as that of referring to a FactoryBean within XML. See SPR-6602.
365-
if (factoryContainsBean(beanFactory, BeanFactory.FACTORY_BEAN_PREFIX + beanName) &&
366-
factoryContainsBean(beanFactory, beanName)) {
367-
Object factoryBean = beanFactory.getBean(BeanFactory.FACTORY_BEAN_PREFIX + beanName);
365+
String factoryBeanName = BeanFactory.FACTORY_BEAN_PREFIX + beanName;
366+
if (factoryContainsBean(beanFactory, factoryBeanName) && factoryContainsBean(beanFactory, beanName)) {
367+
Object factoryBean = beanFactory.getBean(factoryBeanName);
368368
if (factoryBean instanceof ScopedProxyFactoryBean) {
369369
// Scoped proxy factory beans are a special case and should not be further proxied
370370
}

Diff for: spring-context/src/main/java/org/springframework/jmx/export/MBeanExporter.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2024 the original author or authors.
2+
* Copyright 2002-2025 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.
@@ -926,8 +926,8 @@ private void autodetect(Map<String, Object> beans, AutodetectCallback callback)
926926
*/
927927
private boolean isExcluded(String beanName) {
928928
return (this.excludedBeans.contains(beanName) ||
929-
(beanName.startsWith(BeanFactory.FACTORY_BEAN_PREFIX) &&
930-
this.excludedBeans.contains(beanName.substring(BeanFactory.FACTORY_BEAN_PREFIX.length()))));
929+
(!beanName.isEmpty() && (beanName.charAt(0) == BeanFactory.FACTORY_BEAN_PREFIX_CHAR) &&
930+
this.excludedBeans.contains(beanName.substring(1)))); // length of '&'
931931
}
932932

933933
/**

Diff for: spring-core/src/main/java/org/springframework/core/annotation/AnnotationsScanner.java

+1
Original file line numberDiff line numberDiff line change
@@ -350,6 +350,7 @@ private AnnotationsScanner() {
350350

351351
private static boolean isOverride(Method rootMethod, Method candidateMethod) {
352352
return (!Modifier.isPrivate(candidateMethod.getModifiers()) &&
353+
candidateMethod.getParameterCount() == rootMethod.getParameterCount() &&
353354
candidateMethod.getName().equals(rootMethod.getName()) &&
354355
hasSameParameterTypes(rootMethod, candidateMethod));
355356
}

Diff for: spring-core/src/main/java/org/springframework/util/ClassUtils.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -614,10 +614,11 @@ public static boolean isAssignable(Class<?> lhsType, Class<?> rhsType) {
614614
Class<?> resolvedPrimitive = primitiveWrapperTypeMap.get(rhsType);
615615
return (lhsType == resolvedPrimitive);
616616
}
617-
else {
617+
else if (rhsType.isPrimitive()) {
618618
Class<?> resolvedWrapper = primitiveTypeToWrapperMap.get(rhsType);
619619
return (resolvedWrapper != null && lhsType.isAssignableFrom(resolvedWrapper));
620620
}
621+
return false;
621622
}
622623

623624
/**

0 commit comments

Comments
 (0)