Skip to content

Fix reserveMethodNames to reserve each supplied name - #36912

Merged
bclozel merged 1 commit into
spring-projects:7.0.xfrom
junhyeong9812:fix/generatedclass-reserve-method-names
Sep 4, 2026
Merged

bclozel merged 1 commit into
spring-projects:7.0.xfrom
junhyeong9812:fix/generatedclass-reserve-method-names

Conversation

@junhyeong9812

Copy link
Copy Markdown
Contributor

Overview

GeneratedClass.reserveMethodNames(String...) reserves a set of method names so that
generated methods will not collide with them.

Problem

Inside the per-name loop, the whole varargs array was passed to MethodName.of(...) instead
of the current element:

for (String reservedMethodName : reservedMethodNames) {
    String generatedName = generateSequencedMethodName(MethodName.of(reservedMethodNames)); // whole array
    Assert.state(generatedName.equals(reservedMethodName), ...);
}

MethodName.of(String...) joins all parts into a single camel-case name, so
reserveMethodNames("apply", "test") produced "applyTest", and the per-element check
Assert.state("applyTest".equals("apply")) failed with IllegalStateException. Single-name
calls worked only by accident (a one-element array round-trips to the same name). The only
in-tree caller reserves a single name, so the multi-name path was never exercised.

Fix

Pass the loop variable so that each supplied name is reserved individually. A regression test
in GeneratedClassTests reserves two names.

Note on intent

This fix assumes reserveMethodNames is meant to reserve each supplied name individually.
The per-element assertion Assert.state(generatedName.equals(reservedMethodName)) and the
javadoc ("a set of reserved method names") both indicate this. If the intent was instead to
reserve a single combined name, the loop and the per-element assertion would be inconsistent
and a different fix would be appropriate — happy to adjust if I have misread the intent.

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label Jun 13, 2026
@bclozel bclozel added the in: core Issues in core modules (aop, beans, core, context, expression) label Sep 4, 2026
@bclozel
bclozel changed the base branch from main to 7.0.x September 4, 2026 15:13
GeneratedClass.reserveMethodNames(String...) passed the entire varargs
array to MethodName.of() inside the per-name loop instead of the current
element. Since MethodName.of(String...) joins all parts into a single
camel-case name, reserving two or more names (for example "apply" and
"test") produced "applyTest", and the per-element check
Assert.state(generatedName.equals(reservedMethodName)) failed with an
IllegalStateException. Single-name calls worked only by accident.

Reserve each supplied name individually by passing the loop variable.

Signed-off-by: junhyeong9812 <pickjog@gmail.com>
@bclozel bclozel self-assigned this Sep 4, 2026
@bclozel bclozel added type: bug A general bug and removed status: waiting-for-triage An issue we've not yet triaged or decided on labels Sep 4, 2026
@bclozel bclozel added this to the 7.0.10 milestone Sep 4, 2026
@bclozel
bclozel force-pushed the fix/generatedclass-reserve-method-names branch from ea33c7d to 2b5229f Compare September 4, 2026 15:15
@bclozel
bclozel merged commit 2b5229f into spring-projects:7.0.x Sep 4, 2026
2 checks passed
@bclozel

bclozel commented Sep 4, 2026

Copy link
Copy Markdown
Member

You were right on the intent @junhyeong9812 , this is now fixed for the next maintenance release thanks to you!

@junhyeong9812

Copy link
Copy Markdown
Contributor Author

Thanks for confirming the intent and merging this!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

in: core Issues in core modules (aop, beans, core, context, expression) type: bug A general bug

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants