JetBrains / Exposed

Kotlin SQL Framework
http://jetbrains.github.io/Exposed/
Apache License 2.0
8.32k stars 693 forks source link

ClassCastException when attempting to register table #352

Closed hafarooki closed 6 years ago

hafarooki commented 6 years ago
Caused by: java.lang.ClassCastException: kotlin.jvm.internal.ClassReference cannot be cast to kotlin.reflect.jvm.internal.KClassImpl
        at kotlin.reflect.full.KClasses.getPrimaryConstructor(KClasses.kt:40) ~[?:?]
        at org.jetbrains.exposed.sql.Table.clone(Table.kt:205) ~[?:?]
        at org.jetbrains.exposed.sql.Table.cloneWithAutoInc(Table.kt:344) ~[?:?]
        at org.jetbrains.exposed.sql.Table.autoIncrement(Table.kt:348) ~[?:?]
        at org.jetbrains.exposed.sql.Table.autoIncrement$default(Table.kt:348) ~[?:?]
        at org.jetbrains.exposed.dao.IntIdTable.<init>(IntEntity.kt:6) ~[?:?]
        at org.jetbrains.exposed.dao.IntIdTable.<init>(IntEntity.kt:5) ~[?:?]
        at net.starlegacy.nations.database.table.Settlements.<init>(Tables.kt:50) ~[?:?]
        at net.starlegacy.nations.database.table.Settlements.<clinit>(Tables.kt:50) ~[?:?]
        ... 26 more

Erroring table:

object Settlements : IntIdTable("${Config.Db.PREFIX}_settlements") {
    val name = varchar("name", 50).uniqueIndex()
    val territoryId = varchar("territory_id", 100).uniqueIndex()
    val leader = reference("leader", NationPlayers).uniqueIndex()
    val balance = integer("balance")
}
Tapac commented 6 years ago

@Miclebrick , the comment from a Kotlin team:

Are you doing something non-trivial like serializing and deserializing KClass objects maybe? kotlin.jvm.internal.ClassReference only comes up if you’re using the ::class syntax in a module without kotlin-reflect.jar in the classpath

Another reason might be an unexpected implementation of the class loader used where the ::class literal is present. (Upon the first access to ::class, we use Class.forName in kotlin-stdlib to locate the reflection implementation, and fallback to ClassReferences if not found.)

hafarooki commented 6 years ago

The issue seemed to have been another version of Kotlin on the classpath (an issue because it's a Minecraft server plugin where any plugin can have its own version shaded in)