Skip to content
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

Calling MethodParameter.isOptional() for Kotlin Continuation parameter fails with IndexOutOfBoundsException #23991

Closed
mp911de opened this issue Nov 14, 2019 · 2 comments
Assignees
Labels
type: bug A general bug
Milestone

Comments

@mp911de
Copy link
Member

mp911de commented Nov 14, 2019

Affects: 5.2.1.RELEASE

Calling MethodParameter.isOptional() for a kotlin.coroutines.Continuation parameter of a suspend fun fails when introspecting a Coroutines method.

java.lang.IndexOutOfBoundsException: Index: 1, Size: 1

	at java.util.ArrayList.rangeCheck(ArrayList.java:657)
	at java.util.ArrayList.get(ArrayList.java:433)
	at org.springframework.core.MethodParameter$KotlinDelegate.isOptional(MethodParameter.java:899)
	at org.springframework.core.MethodParameter.isOptional(MethodParameter.java:408)

The backing collection of KParameters does not contain the parameter and therefore optionality checks fail.

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label Nov 14, 2019
@sdeleuze sdeleuze self-assigned this Nov 14, 2019
@sdeleuze
Copy link
Contributor

Could you share a little bit more about the context where this code path is reached? I am asking that because in current Coroutines support this kind of code path is not reached because we use upfront Kotlin reflection to identify the parameters that the user see, not the parameters at bytecode level that does not really make sense from a programming model perspective.

@mp911de
Copy link
Member Author

mp911de commented Nov 14, 2019

Sure, we're introspecting in Spring Data MethodParameters to determine whether they are nullable or not (optional vs. required).

Here's some context of how it is used:

interface CoCrudRepository<T, ID> {
	suspend fun save(entity: T): T
}

Method method = CoCrudRepository.class.getDeclaredMethod(…);

for (int i = 0; i < method.getParameterCount(); i++) {

	MethodParameter parameter = new MethodParameter(method, i);
	parameter.isOptional();
}

@sdeleuze sdeleuze added this to the 5.2.2 milestone Nov 14, 2019
@sdeleuze sdeleuze added type: bug A general bug and removed status: waiting-for-triage An issue we've not yet triaged or decided on labels Nov 14, 2019
sdeleuze added a commit to sdeleuze/spring-framework that referenced this issue Nov 14, 2019
This commit adds support for Continuation parameter that is now
considered as an optional parameter since it is never provided by
the user.

It also simplifies and optimizes the implementation.

Closes spring-projectsgh-23991
sdeleuze added a commit to sdeleuze/spring-framework that referenced this issue Nov 14, 2019
This commit adds support for Continuation parameter that is now
considered as an optional parameter since it is never provided by
the user.

It also simplifies and optimizes the implementation.

Closes spring-projectsgh-23991
sdeleuze added a commit to sdeleuze/spring-framework that referenced this issue Nov 14, 2019
This commit adds support for Continuation parameter that is now
considered as an optional parameter since it is never provided by
the user.

It also simplifies and optimizes the implementation.

Closes spring-projectsgh-23991
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug A general bug
Projects
None yet
Development

No branches or pull requests

3 participants