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

Annotation method return type resolved as property for java sources. #1004

Closed
bcorso opened this issue May 25, 2022 · 1 comment · Fixed by #1005
Closed

Annotation method return type resolved as property for java sources. #1004

bcorso opened this issue May 25, 2022 · 1 comment · Fixed by #1005

Comments

@bcorso
Copy link

bcorso commented May 25, 2022

When processing Java source for an annotation like:

@interface MyAnnotation {
    boolean booleanParam();
}

I'm hitting a ClassCastException when trying to get the return type of the booleanParam() method.

Caused by: java.lang.ClassCastException: class org.jetbrains.kotlin.load.java.descriptors.JavaPropertyDescriptor cannot be cast to class org.jetbrains.kotlin.descriptors.FunctionDescriptor (org.jetbrains.kotlin.load.java.descriptors.JavaPropertyDescriptor and org.jetbrains.kotlin.descriptors.FunctionDescriptor are in unnamed module of loader 'app')
    at com.google.devtools.ksp.processing.impl.ResolverImpl.resolveFunctionDeclaration(ResolverImpl.kt:640)
    at com.google.devtools.ksp.symbol.impl.java.KSFunctionDeclarationJavaImpl.findOverridee(KSFunctionDeclarationJavaImpl.kt:55)
    at androidx.room.compiler.processing.ksp.KSFunctionExtKt.getOriginatingReference(KSFunctionExt.kt:57)
    at androidx.room.compiler.processing.ksp.KSFunctionExtKt.returnKspType(KSFunctionExt.kt:35)
    at androidx.room.compiler.processing.ksp.KspMethodElement$KspNormalMethodElement$returnType$2.invoke(KspMethodElement.kt:165)
    at androidx.room.compiler.processing.ksp.KspMethodElement$KspNormalMethodElement$returnType$2.invoke(KspMethodElement.kt:164)
    at kotlin.SynchronizedLazyImpl.getValue(LazyJVM.kt:74)
    at androidx.room.compiler.processing.ksp.KspMethodElement$KspNormalMethodElement.getReturnType(KspMethodElement.kt:164)
    at androidx.room.compiler.processing.XAnnotationValueTest$tmp$1.invoke(XAnnotationValueTest.kt:762)
    at androidx.room.compiler.processing.XAnnotationValueTest$tmp$1.invoke(XAnnotationValueTest.kt:724)

Also note that it's only when processing the annotation as a source -- it works as expected when the using the precompiled class

@neetopia
Copy link
Collaborator

This is returned by compiler, probably need to handle it as is. Since resolveFunctionDeclaration is not part of public KSP API, it's probably better to just handle this case at call site of this function, internally.

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.

2 participants