Skip to content

Fix reserveMethodNames to reserve each supplied name#36912

Open
junhyeong9812 wants to merge 1 commit into
spring-projects:mainfrom
junhyeong9812:fix/generatedclass-reserve-method-names
Open

Fix reserveMethodNames to reserve each supplied name#36912
junhyeong9812 wants to merge 1 commit into
spring-projects:mainfrom
junhyeong9812:fix/generatedclass-reserve-method-names

Conversation

@junhyeong9812

Copy link
Copy Markdown

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.

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>
@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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

status: waiting-for-triage An issue we've not yet triaged or decided on

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants