Skip to content

KotlinReflectionInternalError: No accessor found for property val #963

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

Closed
4 tasks done
TomerAberbach opened this issue Apr 23, 2025 · 4 comments
Closed
4 tasks done
Labels

Comments

@TomerAberbach
Copy link

Search before asking

  • I searched in the issues and found nothing similar.
  • I have confirmed that the same problem is not reproduced if I exclude the KotlinModule.
  • I searched in the issues of databind and other modules used and found nothing similar.
  • I have confirmed that the problem does not reproduce in Java and only occurs when using Kotlin and KotlinModule.

Describe the bug

I'm experiencing CI issues where I get errors like this one in my tests:

  ExternalAccountTest > roundtrip() FAILED
      kotlin.reflect.jvm.internal.KotlinReflectionInternalError: No accessor found for property val com.increase.api.models.externalaccounts.ExternalAccount.accountHolder: com.increase.api.core.JsonField<com.increase.api.models.externalaccounts.ExternalAccount.AccountHolder>
          at kotlin.reflect.jvm.internal.KPropertyImplKt.computeCallerForAccessor(KPropertyImpl.kt:289)
          at kotlin.reflect.jvm.internal.KPropertyImplKt.access$computeCallerForAccessor(KPropertyImpl.kt:1)
          at kotlin.reflect.jvm.internal.KPropertyImpl$Getter$caller$2.invoke(KPropertyImpl.kt:156)
          at kotlin.reflect.jvm.internal.KPropertyImpl$Getter$caller$2.invoke(KPropertyImpl.kt:147)
          at kotlin.reflect.jvm.internal.ReflectProperties$LazyVal.invoke(ReflectProperties.java:62)
          at kotlin.reflect.jvm.internal.ReflectProperties$Val.getValue(ReflectProperties.java:31)
          at kotlin.reflect.jvm.internal.KPropertyImpl$Getter.getCaller(KPropertyImpl.kt)
          at kotlin.reflect.jvm.ReflectJvmMapping.getJavaMethod(ReflectJvmMapping.kt:63)
          at kotlin.reflect.jvm.ReflectJvmMapping.getJavaGetter(ReflectJvmMapping.kt:48)
          at com.fasterxml.jackson.module.kotlin.KotlinAnnotationIntrospector.getRequiredMarkerFromCorrespondingAccessor(KotlinAnnotationIntrospector.kt:159)
          at com.fasterxml.jackson.module.kotlin.KotlinAnnotationIntrospector.hasRequiredMarker(KotlinAnnotationIntrospector.kt:154)
          at com.fasterxml.jackson.module.kotlin.KotlinAnnotationIntrospector.access$hasRequiredMarker(KotlinAnnotationIntrospector.kt:26)
          at com.fasterxml.jackson.module.kotlin.KotlinAnnotationIntrospector$hasRequiredMarker$hasRequired$1.invoke(KotlinAnnotationIntrospector.kt:43)
          at com.fasterxml.jackson.module.kotlin.KotlinAnnotationIntrospector$hasRequiredMarker$hasRequired$1.invoke(KotlinAnnotationIntrospector.kt:36)
          at com.fasterxml.jackson.module.kotlin.ReflectionCache.javaMemberIsRequired(ReflectionCache.kt:88)
          at com.fasterxml.jackson.module.kotlin.KotlinAnnotationIntrospector.hasRequiredMarker(KotlinAnnotationIntrospector.kt:36)
          at com.fasterxml.jackson.databind.introspect.AnnotationIntrospectorPair.hasRequiredMarker(AnnotationIntrospectorPair.java:319)
          at com.fasterxml.jackson.databind.introspect.AnnotationIntrospectorPair.hasRequiredMarker(AnnotationIntrospectorPair.java:319)
          at com.fasterxml.jackson.databind.introspect.POJOPropertyBuilder.getMetadata(POJOPropertyBuilder.java:230)
          at com.fasterxml.jackson.databind.introspect.POJOPropertiesCollector._anyIndexed(POJOPropertiesCollector.java:1238)
          at com.fasterxml.jackson.databind.introspect.POJOPropertiesCollector._sortProperties(POJOPropertiesCollector.java:1140)
          at com.fasterxml.jackson.databind.introspect.POJOPropertiesCollector.collectAll(POJOPropertiesCollector.java:470)
          at com.fasterxml.jackson.databind.introspect.POJOPropertiesCollector.getJsonValueAccessor(POJOPropertiesCollector.java:270)
          at com.fasterxml.jackson.databind.introspect.BasicBeanDescription.findJsonValueAccessor(BasicBeanDescription.java:258)
          at com.fasterxml.jackson.databind.ser.BasicSerializerFactory.findSerializerByAnnotations(BasicSerializerFactory.java:391)
          at com.fasterxml.jackson.databind.ser.BeanSerializerFactory._createSerializer2(BeanSerializerFactory.java:224)
          at com.fasterxml.jackson.databind.ser.BeanSerializerFactory.createSerializer(BeanSerializerFactory.java:173)
          at com.fasterxml.jackson.databind.SerializerProvider._createUntypedSerializer(SerializerProvider.java:1495)
          at com.fasterxml.jackson.databind.SerializerProvider._createAndCacheUntypedSerializer(SerializerProvider.java:1443)
          at com.fasterxml.jackson.databind.SerializerProvider.findValueSerializer(SerializerProvider.java:544)
          at com.fasterxml.jackson.databind.SerializerProvider.findTypedValueSerializer(SerializerProvider.java:822)
          at com.fasterxml.jackson.databind.ser.DefaultSerializerProvider.serializeValue(DefaultSerializerProvider.java:308)
          at com.fasterxml.jackson.databind.ObjectMapper._writeValueAndClose(ObjectMapper.java:4568)
          at com.fasterxml.jackson.databind.ObjectMapper.writeValueAsString(ObjectMapper.java:3821)
          at com.increase.api.models.externalaccounts.ExternalAccountTest.roundtrip(ExternalAccountTest.kt:66)

To Reproduce

Unfortunately, this doesn't seem to reproduce for me locally. I'm really not sure why, and I couldn't figure it out. I'm hoping maybe y'all have some ideas based on the stack trace above.

The stack trace corresponds to this test, for what it's worth. Although, cloning this repo and running ./scripts/test locally doesn't seem to result in any issues.

I did notice that this Jackson library's code has a ReflectionCache so I'm wondering maybe there's some weird race condition with this cache? Not sure.

Expected behavior

I expect no stack trace, consistently.

Versions

Kotlin: 1.9.20
Jackson-module-kotlin: 2.13.4
Jackson-databind: 2.13.4

Additional context

Appreciate any insights you can provide because I'm pretty lost here!

@TomerAberbach
Copy link
Author

Okay, so I was able to figure out that this was happening due to mismatching Kotlin vs Java toolchains

I had:

java {
    toolchain {
        languageVersion.set(JavaLanguageVersion.of(17))	
    }
}

But also had:

kotlin {
    jvmToolchain {
        languageVersion.set(JavaLanguageVersion.of(21))
    }
}

Swapping the former to this, fixed it:

java {
    toolchain {
        languageVersion.set(JavaLanguageVersion.of(21))	
    }
}

I'm not sure why it was happening only on CI though. I'll leave this issue open in case you want to do some more investigation

@k163377
Copy link
Contributor

k163377 commented Apr 28, 2025

It is closed because it does not seem to be a kotlin-module problem.

@k163377 k163377 closed this as completed Apr 28, 2025
@TomerAberbach
Copy link
Author

Okay, so actually, it seems it was just flaky. Even with my "fix" above, it still happens.

@k163377 do you think this could plausibly be a bug with kotlin-module? Because the stack trace is from this library? Is this reflection error an expected thing that should be caught by this lib?

@k163377
Copy link
Contributor

k163377 commented May 1, 2025

First, I did not do a complete analysis of the submitted content because it is not a minimum reproduction and the Jackson version is too old.
However, from the message No accessor found for property, this appears to be due to something like.

  • Corruption of Kotlin metadata or output binaries
  • Version mismatch between Kotlin and jackson-module-kotlin
  • Bug in kotlin-reflect

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

No branches or pull requests

2 participants