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

Fix issue where java datafetcher methods were incorrectly called as Kotlin function #1694

Merged
merged 2 commits into from
Nov 5, 2023

Conversation

paulbakker
Copy link
Collaborator

Pull Request type

  • [x ] Bugfix
  • Feature
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • Other (please describe):

Changes in this PR

Java datafetcher methods with an argument were incorrectly called as being kotlin functions. While this mostly works, it causes an incorrect wrapping of InvocationException if an exception occurs.
The code was prepared for calling Java functions using regular Java Reflection, but the assumption was that kotlinFunction != null would be false. This is not true (for reasons I don't understand, that's Kotlin internals).

The correct check also verifies if the class has Kotlin metadata, which is the correct way to verify if we're dealing with Kotlin code.

@paulbakker paulbakker requested a review from kilink November 5, 2023 17:06
@srinivasankavitha srinivasankavitha merged commit b84bb1a into master Nov 5, 2023
4 checks passed
@@ -65,7 +65,7 @@ class DataFetcherInvoker internal constructor(
return ReflectionUtils.invokeMethod(bridgedMethod, dgsComponent)
}

if (kotlinFunction != null) {
if (dgsComponent.javaClass.getDeclaredAnnotation(Metadata::class.java) != null && kotlinFunction != null) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it'd be better to do this in the constructor to avoid having to check it every time. We can also use KotlinDetector from Spring. e.g.:

private val kotlinFunction: KFunction<*>? = if (KotlinDetector.isKotlinType(method.declaringClass)) bridgedMethod.kotlinFunction else null

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed in a separate PR: #1697

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants