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

java.lang.IllegalStateException: unhandled value type on Multiplatform/JS target #1503

Open
mikedawson opened this issue Aug 22, 2023 · 1 comment · May be fixed by #1508
Open

java.lang.IllegalStateException: unhandled value type on Multiplatform/JS target #1503

mikedawson opened this issue Aug 22, 2023 · 1 comment · May be fixed by #1508

Comments

@mikedawson
Copy link

I have an annotation processor that uses Kotlin multiplatform for Android, JVM, and JS targets. Everything was working fine with Kotlin 1.8.10 KSP 1.0.9 . Now using Kotlin 1.9 KSP 1.0.13 results has an exception as follows:

e: [ksp] java.lang.IllegalStateException: unhandled value type, please file a bug at https://github.com/google/ksp/issues/new
        at com.google.devtools.ksp.UtilsKt.createInvocationHandler$lambda$8(utils.kt:381)
        at jdk.proxy12/jdk.proxy12.$Proxy229.indices(Unknown Source)
        at com.ustadmobile.lib.annotationprocessor.core.CodeBlockExtKt.addCreateTableCode(CodeBlockExt.kt:74)

To reproduce:

  1. Checkout the project from https://github.com/UstadMobile/door/
  2. Checkout the kotlin1.9 branch or commit 9dc3e5487f6b280cd48f163c3e601a35f3b73251
  3. Run the Gradle task gradlew door-testdb:jsJar

It is throwing an exception when running the getAnnotation function. The exception itself is coming from here in utils.kt:

// Workaround for java annotation value array type
                        // https://github.com/google/ksp/issues/1329
                        method.returnType.isArray -> {
                            if (result !is Array<*>) {
                                val value = { result.asArray(method, clazz) }
                                cache.getOrPut(Pair(method.returnType, value), value)
                            } else {
                                throw IllegalStateException("unhandled value type, $ExceptionMessage")
                            }
                        }

Would appreciate to know if there any fix / workaround: this is a blocker to prevent me from being able to update to Kotlin 1.9.

@mikedawson
Copy link
Author

The Exception is coming from the proxy which is returned by KSAnnotated.getAnnotation(class). The workaround I am using for now is to use KSAnnotation itself and "manually" instantiate the annotation class.

fun KSAnnotation.toMyAnnotation(): MyAnnotation {
   if(annotationType.resolve().declaration.qualifiedName?.asString() != "mypackage.MyAnnotation") 
     throw IllegalArgumentException("not a myannotation!")

   return MyAnnotation(
      name = arguments.firstOrNull { it.name?.asString() == "name" }?.value as? String
   )
}

KSValueArgument.value is not really typed: it's Any. Different parameter types (e.g. Enums, String arrays, Class arrays, etc) have different types. You can use the debugger to inspect and figure it out.

mikedawson added a commit to UstadMobile/door that referenced this issue Aug 23, 2023
Upgrading KSP broke compilation on JS. Got java.lang.IllegalStateException: unhandled value type when using getAnnotation .

Now use KSAnnotation itself with "manual" conversion to the annotation class instead of using the proxy provided by KSP.
@qdsfdhvh qdsfdhvh linked a pull request Aug 25, 2023 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant