Skip to content

Commit 4d206f7

Browse files
committed
Merge branch '6.1.x'
# Conflicts: # spring-jms/src/main/java/org/springframework/jms/listener/DefaultMessageListenerContainer.java
2 parents 5c58983 + 479879c commit 4d206f7

File tree

5 files changed

+40
-19
lines changed

5 files changed

+40
-19
lines changed

spring-beans/src/main/java/org/springframework/beans/BeanWrapperImpl.java

Lines changed: 18 additions & 8 deletions
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.
@@ -21,6 +21,7 @@
2121

2222
import org.apache.commons.logging.LogFactory;
2323

24+
import org.springframework.core.MethodParameter;
2425
import org.springframework.core.ResolvableType;
2526
import org.springframework.core.convert.TypeDescriptor;
2627
import org.springframework.lang.Nullable;
@@ -283,16 +284,25 @@ public void setValue(@Nullable Object value) throws Exception {
283284

284285
@Override
285286
public boolean setValueFallbackIfPossible(@Nullable Object value) {
286-
Method writeMethod = this.pd.getWriteMethodFallback(value != null ? value.getClass() : null);
287-
if (writeMethod != null) {
288-
ReflectionUtils.makeAccessible(writeMethod);
289-
try {
287+
try {
288+
Method writeMethod = this.pd.getWriteMethodFallback(value != null ? value.getClass() : null);
289+
if (writeMethod == null) {
290+
writeMethod = this.pd.getUniqueWriteMethodFallback();
291+
if (writeMethod != null) {
292+
// Conversion necessary as we would otherwise have received the method
293+
// from the type-matching getWriteMethodFallback call above already
294+
value = convertForProperty(this.pd.getName(), null, value,
295+
new TypeDescriptor(new MethodParameter(writeMethod, 0)));
296+
}
297+
}
298+
if (writeMethod != null) {
299+
ReflectionUtils.makeAccessible(writeMethod);
290300
writeMethod.invoke(getWrappedInstance(), value);
291301
return true;
292302
}
293-
catch (Exception ex) {
294-
LogFactory.getLog(BeanPropertyHandler.class).debug("Write method fallback failed", ex);
295-
}
303+
}
304+
catch (Exception ex) {
305+
LogFactory.getLog(BeanPropertyHandler.class).debug("Write method fallback failed", ex);
296306
}
297307
return false;
298308
}

spring-beans/src/main/java/org/springframework/beans/GenericTypeAwarePropertyDescriptor.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,14 @@ public Method getWriteMethodFallback(@Nullable Class<?> valueType) {
171171
return null;
172172
}
173173

174+
@Nullable
175+
public Method getUniqueWriteMethodFallback() {
176+
if (this.ambiguousWriteMethods != null && this.ambiguousWriteMethods.size() == 1) {
177+
return this.ambiguousWriteMethods.iterator().next();
178+
}
179+
return null;
180+
}
181+
174182
public boolean hasUniqueWriteMethod() {
175183
return (this.writeMethod != null && this.ambiguousWriteMethods == null);
176184
}

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

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1325,6 +1325,11 @@ void withOverloadedSetters() {
13251325
rbd.getPropertyValues().add("value", Duration.ofSeconds(1000));
13261326
lbf.registerBeanDefinition("overloaded", rbd);
13271327
assertThat(lbf.getBean(SetterOverload.class).getObject()).isEqualTo("1000s");
1328+
1329+
rbd = new RootBeanDefinition(SetterOverload.class);
1330+
rbd.getPropertyValues().add("value", "1000");
1331+
lbf.registerBeanDefinition("overloaded", rbd);
1332+
assertThat(lbf.getBean(SetterOverload.class).getObject()).isEqualTo("1000i");
13281333
}
13291334

13301335
@Test
@@ -3382,13 +3387,13 @@ public String getObject() {
33823387
return this.value;
33833388
}
33843389

3385-
public void setValue(int length) {
3386-
this.value = length + "i";
3387-
}
3388-
33893390
public void setValue(Duration duration) {
33903391
this.value = duration.getSeconds() + "s";
33913392
}
3393+
3394+
public void setValue(int length) {
3395+
this.value = length + "i";
3396+
}
33923397
}
33933398

33943399

spring-beans/src/test/java/org/springframework/beans/factory/annotation/AutowiredAnnotationBeanPostProcessorTests.java

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2547,23 +2547,21 @@ void mixedOptionalArgMethodInjection(){
25472547
assertThat(mixedOptionalInjectionBean.nullableBean).isNull();
25482548
}
25492549

2550-
private <E extends UnsatisfiedDependencyException> Consumer<E> methodParameterDeclaredOn(
2551-
Class<?> expected) {
2550+
2551+
private <E extends UnsatisfiedDependencyException> Consumer<E> methodParameterDeclaredOn(Class<?> expected) {
25522552
return declaredOn(
25532553
injectionPoint -> injectionPoint.getMethodParameter().getDeclaringClass(),
25542554
expected);
25552555
}
25562556

2557-
private <E extends UnsatisfiedDependencyException> Consumer<E> fieldDeclaredOn(
2558-
Class<?> expected) {
2557+
private <E extends UnsatisfiedDependencyException> Consumer<E> fieldDeclaredOn(Class<?> expected) {
25592558
return declaredOn(
25602559
injectionPoint -> injectionPoint.getField().getDeclaringClass(),
25612560
expected);
25622561
}
25632562

25642563
private <E extends UnsatisfiedDependencyException> Consumer<E> declaredOn(
2565-
Function<InjectionPoint, Class<?>> declaringClassExtractor,
2566-
Class<?> expected) {
2564+
Function<InjectionPoint, Class<?>> declaringClassExtractor, Class<?> expected) {
25672565
return ex -> {
25682566
InjectionPoint injectionPoint = ex.getInjectionPoint();
25692567
Class<?> declaringClass = declaringClassExtractor.apply(injectionPoint);

spring-jms/src/main/java/org/springframework/jms/listener/DefaultMessageListenerContainer.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -992,7 +992,7 @@ private boolean shouldRescheduleInvoker(int idleTaskExecutionCount) {
992992
}
993993

994994
/**
995-
* Used to determine whether this listener container currently has more
995+
* Called to determine whether this listener container currently has more
996996
* than one idle instance among its scheduled invokers.
997997
*/
998998
private int getIdleInvokerCount() {

0 commit comments

Comments
 (0)