-
Notifications
You must be signed in to change notification settings - Fork 40.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Configuration property binding does not deal with bridge methods #33105
Comments
Thanks very much for raising the issue @vkuzel. I think that the problem might be being caused by synthetic bridge methods that are added by the compiler. I've attempted to fix this, but it's unfortunately quite hard to write a test that consistently works. I'd appreciate it If you could try the latest SNAPSHOT release and let me know if it actually solved your issue for real. |
Hey @philwebb I tested this in my environment and it works as expected. The non-bridge methods are filtered out, so the binding mechanism does not have issues with method resolution. Thank you! |
Thanks very much for taking the time to try a snapshot, @vkuzel. Much appreciated. |
Summary
If a bean class contains multiple getter/setter methods with a same name but different types, the binding mechanism does not sort these methods properly which may lead to a non-deterministic/erroneous behaviour.
Affects v2.7.5 (current main).
Details
Let's have following bean classes:
When compiled, the
Child
class does have two getter methods. One from theParent
class with theParentProperty
return type, another from it's own implementation with theChildPropertyReturnType
.The binding mechanism in the
JavaBeanBinder.Bean.addProperties()
method, reads all declared methods via reflection and then tries to sort those methods by its name. Reason of sorting is non-determinism of theClass.getDeclaredMethods()
reflection method. This issue was previously noted in #24068https://github.com/spring-projects/spring-boot/blob/v2.7.5/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/properties/bind/JavaBeanBinder.java#L130-L143
The problems is: Sorting is solely based on method name which does not (fully) remove the aforementioned non-determinism.
Additional details
abstract var property: T
are slightly more common.txt
extension tojava
)public ParentProperty getProperty()
on theChild
class as abstract. The following code returns array of false values:JavaBeanBinder.Bean.isCandidate()
method returns true for bothgetProperty()
methods in theChild
class.The text was updated successfully, but these errors were encountered: