Litote / kmongo

[deprecated] KMongo - a Kotlin toolkit for Mongo
https://litote.org/kmongo/
Apache License 2.0
781 stars 74 forks source link

IllegalAccessError: tried to access method org.bson.internal.OverridableUuidRepresentationCodecRegistry #361

Closed Nopock closed 2 years ago

Nopock commented 2 years ago

Whenever I run my application I get this error:

java.lang.IllegalAccessError: tried to access method org.bson.internal.OverridableUuidRepresentationCodecRegistry.(Lorg/bson/codecs/configuration/CodecProvider;Lorg/bson/UuidRepresentation;)V from class org.litote.kmongo.KMongo at org.litote.kmongo.KMongo.createRegistry(KMongo.kt:87) ~[?:?] at org.litote.kmongo.KMongo.createClient(KMongo.kt:78) ~[?:?] at org.hyrical.influx.storage.Storage.load(Storage.kt:30) ~[?:?]

dependencies {
    implementation 'org.litote.kmongo:kmongo-serialization:4.6.1'
    implementation "org.jetbrains.kotlinx:kotlinx-serialization-json:1.3.3"
    implementation 'org.mongodb:bson:4.7.1'
}

and I run shadowJar

Here is my implementation (It errors when I call this)

    lateinit var client: MongoClientSettings

    lateinit var mongoClient: MongoClient
    lateinit var database: MongoDatabase

    fun load() {
        client = MongoClientSettings.builder()
            .applyConnectionString(ConnectionString("my mongoDb URL"))
            .uuidRepresentation(UuidRepresentation.STANDARD)
            .build()

        mongoClient = KMongo.createClient(client)

        database = mongoClient.getDatabase("Influx")
    }

Specifically on the line where I initialize mongoClient.

ohemilyy commented 2 years ago

This is caused by the protocol in the ihcf event causing an abstract class to throw an java exception handler

zigzago commented 2 years ago

First idea: try to use org.litote.kmongo:kmongo-serialization:4.7.0.

Because org.litote.kmongo:kmongo-serialization:4.6.1 is compiled with org.mongodb:bson:4.6.0 (and not 4.7.1)

HTH

Nopock commented 2 years ago

First idea: try to use org.litote.kmongo:kmongo-serialization:4.7.0.

Because org.litote.kmongo:kmongo-serialization:4.6.1 is compiled with org.mongodb:bson:4.6.0 (and not 4.7.1)

HTH

Sorry for the late reply.

Still seems to throw the exact same error!

zigzago commented 2 years ago

Check if you have other version of mongo jar in your dependencies (from third party dependencies). Usually this is the origin of this stacktrace

HTH