Skip to content

Commit

Permalink
Merge branch '6.1.x'
Browse files Browse the repository at this point in the history
# Conflicts:
#	spring-jms/src/main/java/org/springframework/jms/listener/DefaultMessageListenerContainer.java
  • Loading branch information
jhoeller committed Feb 26, 2024
2 parents 5c58983 + 479879c commit 4d206f7
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 19 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2023 the original author or authors.
* Copyright 2002-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -21,6 +21,7 @@

import org.apache.commons.logging.LogFactory;

import org.springframework.core.MethodParameter;
import org.springframework.core.ResolvableType;
import org.springframework.core.convert.TypeDescriptor;
import org.springframework.lang.Nullable;
Expand Down Expand Up @@ -283,16 +284,25 @@ public void setValue(@Nullable Object value) throws Exception {

@Override
public boolean setValueFallbackIfPossible(@Nullable Object value) {
Method writeMethod = this.pd.getWriteMethodFallback(value != null ? value.getClass() : null);
if (writeMethod != null) {
ReflectionUtils.makeAccessible(writeMethod);
try {
try {
Method writeMethod = this.pd.getWriteMethodFallback(value != null ? value.getClass() : null);
if (writeMethod == null) {
writeMethod = this.pd.getUniqueWriteMethodFallback();
if (writeMethod != null) {
// Conversion necessary as we would otherwise have received the method
// from the type-matching getWriteMethodFallback call above already
value = convertForProperty(this.pd.getName(), null, value,
new TypeDescriptor(new MethodParameter(writeMethod, 0)));
}
}
if (writeMethod != null) {
ReflectionUtils.makeAccessible(writeMethod);
writeMethod.invoke(getWrappedInstance(), value);
return true;
}
catch (Exception ex) {
LogFactory.getLog(BeanPropertyHandler.class).debug("Write method fallback failed", ex);
}
}
catch (Exception ex) {
LogFactory.getLog(BeanPropertyHandler.class).debug("Write method fallback failed", ex);
}
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,14 @@ public Method getWriteMethodFallback(@Nullable Class<?> valueType) {
return null;
}

@Nullable
public Method getUniqueWriteMethodFallback() {
if (this.ambiguousWriteMethods != null && this.ambiguousWriteMethods.size() == 1) {
return this.ambiguousWriteMethods.iterator().next();
}
return null;
}

public boolean hasUniqueWriteMethod() {
return (this.writeMethod != null && this.ambiguousWriteMethods == null);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1325,6 +1325,11 @@ void withOverloadedSetters() {
rbd.getPropertyValues().add("value", Duration.ofSeconds(1000));
lbf.registerBeanDefinition("overloaded", rbd);
assertThat(lbf.getBean(SetterOverload.class).getObject()).isEqualTo("1000s");

rbd = new RootBeanDefinition(SetterOverload.class);
rbd.getPropertyValues().add("value", "1000");
lbf.registerBeanDefinition("overloaded", rbd);
assertThat(lbf.getBean(SetterOverload.class).getObject()).isEqualTo("1000i");
}

@Test
Expand Down Expand Up @@ -3382,13 +3387,13 @@ public String getObject() {
return this.value;
}

public void setValue(int length) {
this.value = length + "i";
}

public void setValue(Duration duration) {
this.value = duration.getSeconds() + "s";
}

public void setValue(int length) {
this.value = length + "i";
}
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2547,23 +2547,21 @@ void mixedOptionalArgMethodInjection(){
assertThat(mixedOptionalInjectionBean.nullableBean).isNull();
}

private <E extends UnsatisfiedDependencyException> Consumer<E> methodParameterDeclaredOn(
Class<?> expected) {

private <E extends UnsatisfiedDependencyException> Consumer<E> methodParameterDeclaredOn(Class<?> expected) {
return declaredOn(
injectionPoint -> injectionPoint.getMethodParameter().getDeclaringClass(),
expected);
}

private <E extends UnsatisfiedDependencyException> Consumer<E> fieldDeclaredOn(
Class<?> expected) {
private <E extends UnsatisfiedDependencyException> Consumer<E> fieldDeclaredOn(Class<?> expected) {
return declaredOn(
injectionPoint -> injectionPoint.getField().getDeclaringClass(),
expected);
}

private <E extends UnsatisfiedDependencyException> Consumer<E> declaredOn(
Function<InjectionPoint, Class<?>> declaringClassExtractor,
Class<?> expected) {
Function<InjectionPoint, Class<?>> declaringClassExtractor, Class<?> expected) {
return ex -> {
InjectionPoint injectionPoint = ex.getInjectionPoint();
Class<?> declaringClass = declaringClassExtractor.apply(injectionPoint);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -992,7 +992,7 @@ private boolean shouldRescheduleInvoker(int idleTaskExecutionCount) {
}

/**
* Used to determine whether this listener container currently has more
* Called to determine whether this listener container currently has more
* than one idle instance among its scheduled invokers.
*/
private int getIdleInvokerCount() {
Expand Down

0 comments on commit 4d206f7

Please sign in to comment.