Sergio B.
Sergio B.

Reputation: 1000

Kotlin reflection fails to return function after update to version 1.6.10

I have the following kotlin property declared in a class of my Android app:

private val updateRef: KFunction<*> by lazy {
    dao::class.functions.find {it.name.equals("update", true)}!!
}

Where dao is a reference to a Room DAO interface. Since I've updated kotlin to version 1.6.10 it doesn't work anymore, the following wierd exception is thrown every time I try to execute the code above. The same exception is thrown when I evaluate the expression using Android Studio's EVALUATE tool:

"Incorrect resolution sequence for Java method public open suspend fun count(): kotlin.Int defined in it.kfi.lorikeetmobile.db.dao.TablePriorityDao_Impl[JavaMethodDescriptor@d45ec9a]".

Where count() is a suspend method declared in the DAO interface. But I get this for every DAO class I have in my project and for different methods, so I think the method has nothing to do with the real problem here... I cannot figure out what is happening.

Before the update I had no problems at all. Please help.

Upvotes: 1

Views: 716

Answers (1)

Sergio B.
Sergio B.

Reputation: 1000

In the end I discovered that the last version of kotlin-reflect (v. 1.6.10 in my case) doesn't keep backward compatibility for Kotlin classes that extend Java super-classes. Using Kotlin reflection to access member properties or functions of a Java super-class extended by a Kotlin class will fail as described in my question. It works fine if also the super-class is a Kotlin class. That is for me a bug that should be addressed.

Upvotes: 0

Related Questions