Ignore static JavaBean getter methods#37081
Open
arnabnandy7 wants to merge 1 commit into
Open
Conversation
Closes spring-projectsgh-37068 Signed-off-by: Arnab Nandy <arnab_nandy7@yahoo.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Static
get...andis...methods are currently discovered as JavaBeans properties by Spring's basic property introspection.This change excludes static getter methods, aligning Spring's behavior with the standard JDK
Introspector.Closes #37068
Root cause
Spring Framework 6.0 replaced the previous
Introspector-based property discovery with the reflection-basedPropertyDescriptorUtils.determineBasicProperties()implementation.The basic property discovery logic validates accessor names, parameter counts, and return types, but did not exclude static getter methods. Consequently, methods such as
getInstance(),getBean(), orisActive()could be exposed as properties despite not operating on a bean instance.Changes
get...methods from basic property discovery.is...methods from basic property discovery.Static setters are intentionally unaffected since their support is an existing compatibility requirement covered by
BeanWrapperTests.cornerSpr10115.Replace the verification section with this more detailed version:
Before-and-after verification
Before the fix
To verify that the regression test detects the original behavior, the new test was applied without the production change and run with:
Outcome
The test failed for Spring's
BasicPropertiesResolver.The resolver incorrectly returned property descriptors for the static getter methods:
getId()produced theidproperty.isActive()produced theactiveproperty.The assertion expected only the standard
classproperty:Conceptually, the failing result was:
The same test passed for the standard JDK
Introspector, demonstrating that the regression was specific to Spring's basic property discovery.After the fix
After adding the static-method checks to the
get...andis...getter conditions, the regression test was rerun with:Outcome
Both property resolvers now return only the
classproperty for the test class:BasicPropertiesResolverIntrospectorThis confirms that static
get...andis...methods are no longer exposed as JavaBeans properties.Static setter compatibility
Spring has existing support for static setter methods, covered by
BeanWrapperTests.cornerSpr10115. The compatibility test was run together with the regression suite:Outcome
This verifies that the fix excludes only static getter methods and does not alter the established static-setter behavior.
Full module test suite
Finally, the complete
spring-beanstest suite was run:Outcome