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
Milestone

Comments

@mp911de
Copy link
Member

@mp911de 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.

@sdeleuze

This comment has been minimized.

Copy link
Contributor

@sdeleuze sdeleuze commented Nov 14, 2019

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

This comment has been minimized.

Copy link
Member Author

@mp911de 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 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
@sdeleuze sdeleuze closed this in 029e61f Nov 14, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
3 participants
You can’t perform that action at this time.