lundi 3 juin 2019

IllegalCallableAccessException in kotlin-reflect

I use simple-xml in the Android app. Parsed member properties are debugged using Kotlin-reflect. Properties can be displayed correctly if @field: Element is used, but if @field: ElementList is used, An IllegalCallableAccessException occurs and debugging can not be displayed.

Please tell me what to do.

Error: Class kotlin.reflect.jvm.internal.FunctionCaller$FieldSetter I changed the version of gradle and tried invalidate Caches / Restart, but it does not improve.

gradle-wrapper.properties:gradle-5.1.1-all
build:gradle:3.4.1
kotlin version:1.3.21
simple-xml:2.7.1

sample.xml

<Test>
    <Res id="aaa">
        <Event/>
        <Type>Japan</Type>
    </Res>
    <Res id="bbb">
        <Event>manually</Event>
        <Type>Italy</Type>
    </Res>
    <Res id="ccc">
        <Event>manually</Event>
        <Type>America</Type>
    </Res>
</Test>

Test.kt

@Root(name = "Test", strict = false)
class Test{
    @field:ElementList(name = "Res", inline = true) var Res: ArrayList<Res>? = null
}

Res.kt

@Root(name = "Res", strict = false)
class Res {
    @field:Element(name = "Event", required = false) var Event:String? = null
    @field:Element(name = "Type", required = false) var Type:String? = null
}

MainActivity.kt

override fun onCreate(savedInstanceState: Bundle?) {
    ...some code ...
    ParseDebug.debug(Test::class, t)
}

ParseDebug.kt

class ParseDebug{
    companion object {
        fun <T : Any> debug(type: KClass<T>?, obj: T) {
            type?.memberProperties?.forEach { member ->
                member.get(obj)?.let { data ->
                    if (data is String || data is Int) {
                        // String or Integer
                        Log.d(type.simpleName, "${member.name}: $data")
                    } else {
                        debug(data.javaClass.kotlin, data)
                    }
                }
            }
        }
    }
}

It is an acquired error

 java.lang.RuntimeException: Unable to start activity ComponentInfo{com.test.project/com.test.project.MainActivity}: kotlin.reflect.full.IllegalCallableAccessException: java.lang.IllegalAccessException: Class java.lang.Class<kotlin.reflect.jvm.internal.calls.CallerImpl$FieldGetter> cannot access transient  field java.lang.Object[] java.util.ArrayList.elementData of class java.lang.Class<java.util.ArrayList>
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3086)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3229)
        at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:78)
        at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108)
        at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1926)
        at android.os.Handler.dispatchMessage(Handler.java:106)
        at android.os.Looper.loop(Looper.java:214)
        at android.app.ActivityThread.main(ActivityThread.java:6981)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1445)





Aucun commentaire:

Enregistrer un commentaire