Skip to content

Resolver#getJvmCheckedException(KSPropertyAccessor) throws IllegalArgumentException #2548

@bcorso

Description

@bcorso

I'm getting an IllegalArgumentException when calling Resolver#getJvmCheckedException(KSPropertyAccessor) on a property.

In particular it looks like it happens when there's an inherited function that has the same name as the synthetic getter.

Note: this repro is for Bazel builds (not sure about Gradle).

// BUILD
kt_jvm_library(
    name = "app",
    srcs = [
        "App.java",
        "FooProvider1.kt",
    ],
    plugins = [":my_ksp_plugin"],
    deps = [
        ":lib",
    ],
)

kt_jvm_library(
    name = "lib",
    srcs = [
        "Foo.kt",
        "FooProvider2.kt",
    ],
)

Where the classes are defined as follows:

// App.java
interface App extends FooProvider1, FooProvider2 {}

// FooProvider1.kt
interface FooProvider1 {
  val foo: Foo
}

// FooProvider2.kt
interface FooProvider2 {
  fun getFoo(): Foo
}

// Foo.kt
interface Foo
val appClassName = resolver.getKSNameFromString("repros.repro11.App")
val app: KSClassDeclaration = resolver.getClassDeclarationByName(appClassName)!!
val fooProperty = app.getAllProperties().filter { it.simpleName.asString() == "foo" }.single()

// This call throws IllegalArgumentException
resolver.getJvmCheckedException(fooProperty.getter!!)

Result

java.lang.IllegalArgumentException
  at ksp2_impl.jar_1//ksp.org.jetbrains.org.objectweb.asm.ClassReader.<init>(ClassReader.java:253)
  at ksp2_impl.jar_1//ksp.org.jetbrains.org.objectweb.asm.ClassReader.<init>(ClassReader.java:170)
  at ksp2_impl.jar_1//ksp.org.jetbrains.org.objectweb.asm.ClassReader.<init>(ClassReader.java:156)
  at ksp2_impl.jar_1//com.google.devtools.ksp.impl.symbol.util.BinaryUtilsKt.extractThrowsFromClassFile(BinaryUtils.kt:105)
  at ksp2_impl.jar_1//com.google.devtools.ksp.impl.ResolverAAImpl.getJvmCheckedException(ResolverAAImpl.kt:400)
  at PluginSatelliteClassLoaderUnscoped_4//repros.repro11.MyProcessor.process(MyProcessor.kt:26)
  at ksp2_impl.jar_1//com.google.devtools.ksp.impl.KotlinSymbolProcessing$execute$1$1.invoke(KotlinSymbolProcessing.kt:562)
  at ksp2_impl.jar_1//com.google.devtools.ksp.impl.KotlinSymbolProcessing$execute$1$1.invoke(KotlinSymbolProcessing.kt:560)
  at ksp2_impl.jar_1//ksp.com.google.devtools.ksp.common.IncrementalContextBase.closeFilesOnException(IncrementalContextBase.kt:400)
  at ksp2_impl.jar_1//com.google.devtools.ksp.impl.KotlinSymbolProcessing.execute(KotlinSymbolProcessing.kt:560)

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions