Reject write methods not starting with "set" in Property - #37139
Open
junhyeong9812 wants to merge 1 commit into
Open
Reject write methods not starting with "set" in Property#37139junhyeong9812 wants to merge 1 commit into
junhyeong9812 wants to merge 1 commit into
Conversation
Property.resolveName() located the "set" prefix of a write method with String.indexOf, which matches the token anywhere in the method name. A write method that merely contains "set" (for example offsetX or upset) was silently accepted and resolved to a meaningless property name derived from whatever follows the token, while only names with no "set" token at all were rejected. Match the prefix only at the start of the method name via startsWith, so that write methods that are not setters consistently throw the existing IllegalArgumentException. Extracted from the change originally bundled into spring-projectsgh-36911. Signed-off-by: junhyeong9812 <pickjog@gmail.com>
sbrannen
approved these changes
Aug 16, 2026
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.
Overview
org.springframework.core.convert.Property#resolveName()derives a propertyname from a write
Methodwhen no explicit name is given. It located thesetprefix withString#indexOf, which matches the token anywhere inthe method name.
Problem
A write method whose name merely contains
setis silently accepted andresolves to a meaningless property name derived from whatever follows the
token:
setName(String)nameoffsetX(String)xupset(String)""(empty)updateName(String)IllegalArgumentExceptionsettoken at allAn empty or wrong name then misleads
Property#getField()and any consumer ofProperty#getName(). Only names with nosettoken at all were rejected.Fix
Match the
setprefix only at the start of the method name viastartsWith.Write methods that are not setters now consistently throw the existing
IllegalArgumentException("Not a setter method")instead of silentlyproducing a wrong name.
This was originally bundled into gh-36911 and has been extracted into this
dedicated PR as requested there, since it is a behavior change: write methods
that embed
setmid-name were previously accepted and now throw.Note on impact
A remaining known gap, unchanged by this PR: a write method whose name starts
with
setfollowed by a lowercase letter (for examplesettle(String))resolves to the stripped remainder (
tle) before and after this change, sinceprefix matching alone cannot tell it apart from a setter.
New exceptions surface at
Propertyconstruction time for write methodsthat are not setters (previously
offsetX/upsetshapes constructedsuccessfully with a wrong name). Framework-internal call sites are largely
unaffected: spring-beans passes an explicit property name, and SpEL searches
for
set-prefixed methods — with one exotic exception: SpEL's Kotlin supportcan surface a
@JvmName-renamed setter, whose name previously either alreadythrew (no
settoken anywhere) or resolved to a coincidental name (setmid-name) and now consistently throws. gh-37123 passes verified property
names explicitly at those SpEL call sites, which takes them off this code
path entirely.
Tests
PropertyTestscovers the intactsetNamehappy path, the previouslyrejected
updateNameshape, and the two newly rejected shapes (offsetX,upset), asserting the exception message as well.Note: gh-36911 also adds a
PropertyTestsclass on its branch; whichever PRlands second will be rebased to merge the two test classes.