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

ClassCastException when using reloading with kotlinx.dnq #1225

Open
gzoritchak opened this issue Jul 7, 2019 · 3 comments
Open

ClassCastException when using reloading with kotlinx.dnq #1225

gzoritchak opened this issue Jul 7, 2019 · 3 comments
Labels

Comments

@gzoritchak
Copy link

Ktor 1.2.2, Netty
with OAuth, CallLogging, StatusPages, Sessions, ContentNegotiation

I use the Xodus database with Kotlinx.dnq.

Without reloading, it works fine. But trying to add reloading fails during startup, while Xodus.dnq is trying to access to the companion object of an entity.

Caused by: java.lang.ClassCastException: kotlin.reflect.jvm.internal.KClassImpl cannot be cast to kotlin.reflect.jvm.internal.KClassImpl
	at kotlin.reflect.full.KClasses.getCompanionObject(KClasses.kt:52)
	at kotlinx.dnq.util.ReflectionUtilKt.getEnclosingEntityClass(ReflectionUtil.kt:47)
	at kotlinx.dnq.util.ReflectionUtilKt.getParent(ReflectionUtil.kt:60)
	at kotlinx.dnq.XdModel.registerNode(XdModel.kt:87)
	at kotlinx.dnq.XdModel.registerNodes(XdModel.kt:120)
@gzoritchak gzoritchak added the bug label Jul 7, 2019
@cy6erGn0m cy6erGn0m self-assigned this Jul 7, 2019
@kam1sh
Copy link

kam1sh commented Jun 30, 2020

Similar issue: Java 1.8 Ktor 1.3.2 with the next gradle dependencies:

$ cat gradle.properties 
javaVersion=1.8
systemProp.kotlinVersion=1.3.72
serializationVersion=0.20.0
kotlin.code.style=official
kotlin.incremental=true
org.gradle.caching=true

# Dependencies

## backend
ktorVersion=1.3.2
hikariVersion=3.2.0
commonsCodecVersion=1.10
jdbcNamedParametersVersion=1.1
logbackVersion=1.2.3
coroutinesVersion=1.3.7
junitVersion=5.6.2
jacksonVersion=2.10.1
koinVersion=2.1.6
hibernateVersion=5.4.15.Final

$ cat build.gradle.kts
<...>
                implementation(kotlin("stdlib-jdk8"))
                implementation(kotlin("reflect"))
                //////////
                // KTOR //
                //////////
                implementation("io.ktor:ktor-server-netty:$ktorVersion")
                implementation("io.ktor:ktor-auth:$ktorVersion")
                implementation("io.ktor:ktor-pebble:$ktorVersion")
                implementation("io.ktor:ktor-client-cio:$ktorVersion")
                implementation("io.ktor:ktor-locations:$ktorVersion")

                /////////////
                // LOGGING //
                /////////////
                implementation("org.slf4j:slf4j-api:1.7.30")
                implementation("ch.qos.logback:logback-classic:$logbackVersion")

                //////////////
                // DATABASE //
                //////////////
                implementation("mysql:mysql-connector-java:8.0.20")
                implementation("org.hibernate:hibernate-core:$hibernateVersion")
                implementation("org.hibernate:hibernate-entitymanager:$hibernateVersion")
                implementation("org.hibernate:hibernate-hikaricp:$hibernateVersion")
                implementation("com.zaxxer:HikariCP:$hikariVersion")
                implementation("org.flywaydb:flyway-core:6.2.0")

                /////////////
                // JACKSON //
                /////////////
                implementation("com.fasterxml.jackson.dataformat:jackson-dataformat-yaml:$jacksonVersion")
                implementation("com.fasterxml.jackson.core:jackson-databind:$jacksonVersion")
                implementation("com.fasterxml.jackson.module:jackson-module-kotlin:$jacksonVersion")
                implementation("com.fasterxml.jackson.datatype:jackson-datatype-jsr310:$jacksonVersion")

                ////////
                // DI //
                ////////
                implementation("org.koin:koin-core:$koinVersion")
                implementation("org.koin:koin-ktor:$koinVersion")
                implementation("org.koin:koin-logger-slf4j:$koinVersion")
                //////////
                // MISC //
                //////////
                implementation("com.github.ajalt:clikt:2.3.0")
                implementation("commons-codec:commons-codec:$commonsCodecVersion")
                implementation("com.axiomalaska:jdbc-named-parameters:$jdbcNamedParametersVersion")
                implementation("com.github.andrewoma.kwery:core:$kweryVersion")
                implementation("de.mkammerer:argon2-jvm:2.7")
<...>

Exception occurs while launching application:

Exception in thread "main" java.lang.reflect.InvocationTargetException
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:498)
        at kotlin.reflect.jvm.internal.calls.CallerImpl$Method.callMethod(CallerImpl.kt:97)
        at kotlin.reflect.jvm.internal.calls.CallerImpl$Method$Static.call(CallerImpl.kt:106)
        at kotlin.reflect.jvm.internal.KCallableImpl.call(KCallableImpl.kt:106)
        at kotlin.reflect.jvm.internal.KCallableImpl.callDefaultMethod$kotlin_reflection(KCallableImpl.kt:152)
        at kotlin.reflect.jvm.internal.KCallableImpl.callBy(KCallableImpl.kt:110)
        at io.ktor.server.engine.ApplicationEngineEnvironmentReloading.callFunctionWithInjection(ApplicationEngineEnvironmentReloading.kt:384)
        at io.ktor.server.engine.ApplicationEngineEnvironmentReloading.executeModuleFunction(ApplicationEngineEnvironmentReloading.kt:330)
        at io.ktor.server.engine.ApplicationEngineEnvironmentReloading.access$executeModuleFunction(ApplicationEngineEnvironmentReloading.kt:33)
        at io.ktor.server.engine.ApplicationEngineEnvironmentReloading$instantiateAndConfigureApplication$1$$special$$inlined$forEach$lambda$1.invoke(ApplicationEngineEnvironmentReloading.kt:275)
        at io.ktor.server.engine.ApplicationEngineEnvironmentReloading$instantiateAndConfigureApplication$1$$special$$inlined$forEach$lambda$1.invoke(ApplicationEngineEnvironmentReloading.kt:33)
        at io.ktor.server.engine.ApplicationEngineEnvironmentReloading.avoidingDoubleStartupFor(ApplicationEngineEnvironmentReloading.kt:310)
        at io.ktor.server.engine.ApplicationEngineEnvironmentReloading.access$avoidingDoubleStartupFor(ApplicationEngineEnvironmentReloading.kt:33)
        at io.ktor.server.engine.ApplicationEngineEnvironmentReloading$instantiateAndConfigureApplication$1.invoke(ApplicationEngineEnvironmentReloading.kt:274)
        at io.ktor.server.engine.ApplicationEngineEnvironmentReloading$instantiateAndConfigureApplication$1.invoke(ApplicationEngineEnvironmentReloading.kt:33)
        at io.ktor.server.engine.ApplicationEngineEnvironmentReloading.avoidingDoubleStartup(ApplicationEngineEnvironmentReloading.kt:290)
        at io.ktor.server.engine.ApplicationEngineEnvironmentReloading.instantiateAndConfigureApplication(ApplicationEngineEnvironmentReloading.kt:272)
        at io.ktor.server.engine.ApplicationEngineEnvironmentReloading.createApplication(ApplicationEngineEnvironmentReloading.kt:125)
        at io.ktor.server.engine.ApplicationEngineEnvironmentReloading.start(ApplicationEngineEnvironmentReloading.kt:245)
        at io.ktor.server.netty.NettyApplicationEngine.start(NettyApplicationEngine.kt:126)
        at org.cec.platform.commands.Serve.run(Serve.kt:22)
        at com.github.ajalt.clikt.parsers.Parser.parse(Parser.kt:139)
        at com.github.ajalt.clikt.parsers.Parser.parse(Parser.kt:14)
        at com.github.ajalt.clikt.core.CliktCommand.parse(CliktCommand.kt:215)
        at com.github.ajalt.clikt.core.CliktCommand.parse$default(CliktCommand.kt:212)
        at com.github.ajalt.clikt.core.CliktCommand.main(CliktCommand.kt:230)
        at com.github.ajalt.clikt.core.CliktCommand.main(CliktCommand.kt:253)
        at org.cec.platform.AppKt.main(App.kt:223)
Caused by: java.lang.ClassCastException: org.cec.platform.App cannot be cast to org.cec.platform.App
        at org.cec.platform.AppKt.main(App.kt:118)
        ... 31 more

It's not critical, but it would be nice if someone will fix that =)

@oleg-larshin
Copy link

Please check the following ticket on YouTrack for follow-ups to this issue. GitHub issues will be closed in the coming weeks.

@Stexxe
Copy link
Contributor

Stexxe commented Jul 23, 2021

Could you please share a code snippet to reproduce this problem if it's still relevant?

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

5 participants