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

K2 KAPT (aka KAPT4) doesn't like inline/reified. #4373

Open
tinder-johnbuhanan2 opened this issue Jul 30, 2024 · 6 comments
Open

K2 KAPT (aka KAPT4) doesn't like inline/reified. #4373

tinder-johnbuhanan2 opened this issue Jul 30, 2024 · 6 comments

Comments

@tinder-johnbuhanan2
Copy link

Kotlin 2.0.20-Beta2
Dagger 2.51.1

Apparently having an inline/reified inside one of the injecting classes breaks things.
image

image

I attached a small reproducing project:
Example.zip

@kuanyingchou
Copy link
Collaborator

Thanks for the report. The error seems to be from xprocessing, a library Dagger uses. Here's the stacktrace I got from the repro. This could happen if we're trying to call getDescriptor on a inline reified function, which may not have a descriptor in JVM, as it's not visible to Java.

Caused by: java.lang.NullPointerException
	at dagger.spi.internal.shaded.androidx.room.compiler.processing.javac.kotlin.KmFunctionContainerImpl.getDescriptor(KotlinClassMetadataUtils.kt:256)
	at dagger.spi.internal.shaded.androidx.room.compiler.processing.javac.kotlin.KmClassContainer$functionByDescriptor$2.invoke(KotlinClassMetadataUtils.kt:147)
	at dagger.spi.internal.shaded.androidx.room.compiler.processing.javac.kotlin.KmClassContainer$functionByDescriptor$2.invoke(KotlinClassMetadataUtils.kt:145)
	at kotlin.SynchronizedLazyImpl.getValue(LazyJVM.kt:74)
	at dagger.spi.internal.shaded.androidx.room.compiler.processing.javac.kotlin.KmClassContainer.getFunctionByDescriptor(KotlinClassMetadataUtils.kt:145)
	at dagger.spi.internal.shaded.androidx.room.compiler.processing.javac.kotlin.KmClassContainer.getFunctionMetadata(KotlinClassMetadataUtils.kt:142)
	at dagger.spi.internal.shaded.androidx.room.compiler.processing.javac.JavacMethodElement$kotlinMetadata$2.invoke(JavacMethodElement.kt:79)
	at dagger.spi.internal.shaded.androidx.room.compiler.processing.javac.JavacMethodElement$kotlinMetadata$2.invoke(JavacMethodElement.kt:78)
	at kotlin.SynchronizedLazyImpl.getValue(LazyJVM.kt:74)
	at dagger.spi.internal.shaded.androidx.room.compiler.processing.javac.JavacMethodElement.getKotlinMetadata(JavacMethodElement.kt:78)
	at dagger.spi.internal.shaded.androidx.room.compiler.processing.javac.JavacTypeElement.getSyntheticMethodsForAnnotations(JavacTypeElement.kt:217)
	at dagger.spi.internal.shaded.androidx.room.compiler.processing.javac.JavacFieldElement$syntheticMethodForAnnotations$2.invoke(JavacFieldElement.kt:59)
	at dagger.spi.internal.shaded.androidx.room.compiler.processing.javac.JavacFieldElement$syntheticMethodForAnnotations$2.invoke(JavacFieldElement.kt:57)
	at kotlin.SynchronizedLazyImpl.getValue(LazyJVM.kt:74)
	at dagger.spi.internal.shaded.androidx.room.compiler.processing.javac.JavacFieldElement.getSyntheticMethodForAnnotations(JavacFieldElement.kt:57)
	at dagger.spi.internal.shaded.androidx.room.compiler.processing.javac.JavacFieldElement.getAllAnnotations(JavacFieldElement.kt:43)
	at dagger.spi.internal.shaded.androidx.room.compiler.processing.XAnnotated.getAnnotations(XAnnotated.kt:39)
	at dagger.spi.internal.shaded.androidx.room.compiler.processing.XAnnotated.hasAnnotation(XAnnotated.kt:104)
	at dagger.spi.internal.shaded.androidx.room.compiler.processing.XAnnotated.hasAnyAnnotation(XAnnotated.kt:126)
	at dagger.internal.codegen.binding.InjectionAnnotations.hasInjectAnnotation(InjectionAnnotations.java:349)
	at dagger.internal.codegen.validation.InjectValidator.validateForMembersInjectionInternalUncached(InjectValidator.java:380)
	at dagger.internal.codegen.base.Util.reentrantComputeIfAbsent(Util.java:33)
	at dagger.internal.codegen.validation.InjectValidator.validateForMembersInjectionInternal(InjectValidator.java:369)
	at dagger.internal.codegen.validation.InjectValidator.validateUncached(InjectValidator.java:143)
	at dagger.internal.codegen.base.Util.reentrantComputeIfAbsent(Util.java:33)
	at dagger.internal.codegen.validation.InjectValidator.validate(InjectValidator.java:138)
	at dagger.internal.codegen.validation.InjectBindingRegistryImpl.tryRegisterConstructor(InjectBindingRegistryImpl.java:255)
	at dagger.internal.codegen.validation.InjectBindingRegistryImpl.tryRegisterInjectConstructor(InjectBindingRegistryImpl.java:241)
	at dagger.internal.codegen.processingstep.InjectProcessingStep.process(InjectProcessingStep.java:73)
	at dagger.internal.codegen.processingstep.TypeCheckingProcessingStep.lambda$process$0(TypeCheckingProcessingStep.java:94)
	at com.google.common.collect.RegularImmutableMap.forEach(RegularImmutableMap.java:297)
	at dagger.internal.codegen.processingstep.TypeCheckingProcessingStep.process(TypeCheckingProcessingStep.java:72)
	at dagger.internal.codegen.processingstep.TypeCheckingProcessingStep.process(TypeCheckingProcessingStep.java:49)
	at dagger.spi.internal.shaded.androidx.room.compiler.processing.XProcessingStep.process(XProcessingStep.kt:59)
	at dagger.spi.internal.shaded.androidx.room.compiler.processing.CommonProcessorDelegate.processRound(XBasicAnnotationProcessor.kt:132)
	at dagger.spi.internal.shaded.androidx.room.compiler.processing.javac.JavacBasicAnnotationProcessor.process(JavacBasicAnnotationProcessor.kt:73)
	at org.jetbrains.kotlin.kapt3.base.incremental.IncrementalProcessor.process(incrementalProcessors.kt:90)
	at org.jetbrains.kotlin.kapt3.base.ProcessorWrapper.process(annotationProcessing.kt:216)
	at jdk.compiler/com.sun.tools.javac.processing.JavacProcessingEnvironment.callProcessor(JavacProcessingEnvironment.java:1023)
	... 44 more

@tinder-johnbuhanan2
Copy link
Author

Neat! Thank you for your attention. I feel good that y'all have everything handled.

@kuanyingchou
Copy link
Collaborator

This is due to an issue or behavior change in KAPT4. I'm making a workaround fix in an underlying library Dagger uses and it should be included in a future Dagger release.

copybara-service bot pushed a commit to androidx/androidx that referenced this issue Aug 13, 2024
Inline reified functions have a null descriptor/signature under K2 and
KAPT4 and this leads to NullPointerException even when accessing the
annotations of fields in the same class as we need to check all function
descriptors for annotations on synthetic property accessors. So we're making the descriptor nullable in this CL.

Bug: google/dagger#4373, https://youtrack.jetbrains.com/issue/KT-70600
Test: KotlinMetadataTest
Change-Id: Ic772ab2beffba01c13c69ded4284e9b8b424399b
@guuilp
Copy link

guuilp commented Sep 19, 2024

Hi @kuanyingchou! I've seen this fix didn't land on 2.52. Which release can we expect this fix?

@kuanyingchou
Copy link
Collaborator

kuanyingchou commented Sep 19, 2024

Hi, @guuilp , 2.52 was released before the fix so please watch out for the next Dagger release, or alternatively You can try Kotlin 2.1.0-Beta1, which contains a different K2 KAPT implementation and should have fixed this.

@guuilp
Copy link

guuilp commented Sep 19, 2024

Awesome! I'll definitely give it a try, thanks for the tip!

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

No branches or pull requests

3 participants