johncarl81 / parceler

:package: Android Parcelables made easy through code generation.
http://parceler.org
Apache License 2.0
3.56k stars 273 forks source link

Gradle Build Error: NullPointerException #357

Closed mnefzger closed 5 years ago

mnefzger commented 6 years ago

Hi, when building our project, we receive a nullpointer exception (see stacktrace below). The error occured after we upgraded a different library that does not use Parceler. The module that makes use of Parceler did not change in any way.

Do you know what could cause this exception?

Thank you and best regards.

Parceler: 1.1.11 Build tools: 27.0.3 Gradle Build Tools: 3.0.1 Kotlin version: 1.2.50

e: [kapt] An exception occurred: java.lang.NullPointerException
        at com.sun.tools.javac.model.JavacElements.cast(JavacElements.java:605)
        at com.sun.tools.javac.model.JavacElements.getPackageOf(JavacElements.java:332)
        at org.parceler.transfuse.adapter.element.ASTElementFactory.buildPackageClass(ASTElementFactory.java:171)
        at org.parceler.transfuse.adapter.element.ASTElementFactory.getType(ASTElementFactory.java:91)
        at org.parceler.transfuse.adapter.element.ReloadableASTElementFactory$ReloadableASTTypeProvider.get(ReloadableASTElementFactory.java:63)
        at org.parceler.transfuse.adapter.element.ReloadableASTElementFactory$ReloadableASTTypeProvider.get(ReloadableASTElementFactory.java:52)
        at org.parceler.internal.ParcelTransactionWorker.innerRun(ParcelTransactionWorker.java:45)
        at org.parceler.internal.ParcelTransactionWorker.innerRun(ParcelTransactionWorker.java:31)
        at org.parceler.transfuse.transaction.AbstractCompletionTransactionWorker.run(AbstractCompletionTransactionWorker.java:35)
        at org.parceler.transfuse.transaction.CodeGenerationScopedTransactionWorker.innerRun(CodeGenerationScopedTransactionWorker.java:47)
        at org.parceler.transfuse.transaction.AbstractCompletionTransactionWorker.run(AbstractCompletionTransactionWorker.java:35)
        at org.parceler.transfuse.transaction.ScopedTransactionWorker.run(ScopedTransactionWorker.java:55)
        at org.parceler.transfuse.transaction.Transaction.run(Transaction.java:77)
        at org.parceler.guava.util.concurrent.MoreExecutors$DirectExecutorService.execute(MoreExecutors.java:299)
        at org.parceler.transfuse.transaction.TransactionProcessorPool.execute(TransactionProcessorPool.java:60)
        at org.parceler.transfuse.transaction.TransactionProcessorComposite.execute(TransactionProcessorComposite.java:37)
        at org.parceler.transfuse.transaction.TransactionProcessorChain.execute(TransactionProcessorChain.java:38)
        at org.parceler.internal.ParcelProcessor.execute(ParcelProcessor.java:83)
        at org.parceler.ParcelAnnotationProcessor.process(ParcelAnnotationProcessor.java:84)
        at org.jetbrains.kotlin.kapt3.base.ProcessorWrapper.process(annotationProcessing.kt:99)
        at com.sun.tools.javac.processing.JavacProcessingEnvironment.callProcessor(JavacProcessingEnvironment.java:794)
        at com.sun.tools.javac.processing.JavacProcessingEnvironment.discoverAndRunProcs(JavacProcessingEnvironment.java:705)
        at com.sun.tools.javac.processing.JavacProcessingEnvironment.access$1800(JavacProcessingEnvironment.java:91)
        at com.sun.tools.javac.processing.JavacProcessingEnvironment$Round.run(JavacProcessingEnvironment.java:1035)
        at com.sun.tools.javac.processing.JavacProcessingEnvironment.doProcessing(JavacProcessingEnvironment.java:1176)
        at com.sun.tools.javac.main.JavaCompiler.processAnnotations(JavaCompiler.java:1170)
        at com.sun.tools.javac.main.JavaCompiler.processAnnotations(JavaCompiler.java:1068)
        at org.jetbrains.kotlin.kapt3.base.AnnotationProcessingKt.doAnnotationProcessing(annotationProcessing.kt:55)
        at org.jetbrains.kotlin.kapt3.base.AnnotationProcessingKt.doAnnotationProcessing$default(annotationProcessing.kt:27)
        at org.jetbrains.kotlin.kapt3.AbstractKapt3Extension.runAnnotationProcessing(Kapt3Extension.kt:216)
        at org.jetbrains.kotlin.kapt3.AbstractKapt3Extension.analysisCompleted(Kapt3Extension.kt:164)
        at org.jetbrains.kotlin.kapt3.ClasspathBasedKapt3Extension.analysisCompleted(Kapt3Extension.kt:93)
        at org.jetbrains.kotlin.cli.jvm.compiler.TopDownAnalyzerFacadeForJVM$analyzeFilesWithJavaIntegration$2.invoke(TopDownAnalyzerFacadeForJVM.kt:98)
        at org.jetbrains.kotlin.cli.jvm.compiler.TopDownAnalyzerFacadeForJVM.analyzeFilesWithJavaIntegration(TopDownAnalyzerFacadeForJVM.kt:108)
        at org.jetbrains.kotlin.cli.jvm.compiler.TopDownAnalyzerFacadeForJVM.analyzeFilesWithJavaIntegration$default(TopDownAnalyzerFacadeForJVM.kt:85)
        at org.jetbrains.kotlin.cli.jvm.compiler.KotlinToJVMBytecodeCompiler$analyze$1.invoke(KotlinToJVMBytecodeCompiler.kt:370)
        at org.jetbrains.kotlin.cli.jvm.compiler.KotlinToJVMBytecodeCompiler$analyze$1.invoke(KotlinToJVMBytecodeCompiler.kt:61)
        at org.jetbrains.kotlin.cli.common.messages.AnalyzerWithCompilerReport.analyzeAndReport(AnalyzerWithCompilerReport.kt:101)
        at org.jetbrains.kotlin.cli.jvm.compiler.KotlinToJVMBytecodeCompiler.analyze(KotlinToJVMBytecodeCompiler.kt:361)
        at org.jetbrains.kotlin.cli.jvm.compiler.KotlinToJVMBytecodeCompiler.compileModules$cli(KotlinToJVMBytecodeCompiler.kt:126)
        at org.jetbrains.kotlin.cli.jvm.K2JVMCompiler.doExecute(K2JVMCompiler.kt:154)
        at org.jetbrains.kotlin.cli.jvm.K2JVMCompiler.doExecute(K2JVMCompiler.kt:51)
        at org.jetbrains.kotlin.cli.common.CLICompiler.execImpl(CLICompiler.java:95)
        at org.jetbrains.kotlin.cli.common.CLICompiler.execImpl(CLICompiler.java:50)
        at org.jetbrains.kotlin.cli.common.CLITool.exec(CLITool.kt:88)
        at org.jetbrains.kotlin.daemon.CompileServiceImpl$compile$1$1$2.invoke(CompileServiceImpl.kt:405)
        at org.jetbrains.kotlin.daemon.CompileServiceImpl$compile$1$1$2.invoke(CompileServiceImpl.kt:98)
        at org.jetbrains.kotlin.daemon.CompileServiceImpl$doCompile$$inlined$ifAlive$lambda$2.invoke(CompileServiceImpl.kt:927)
        at org.jetbrains.kotlin.daemon.CompileServiceImpl$doCompile$$inlined$ifAlive$lambda$2.invoke(CompileServiceImpl.kt:98)
        at org.jetbrains.kotlin.daemon.common.DummyProfiler.withMeasure(PerfUtils.kt:137)
        at org.jetbrains.kotlin.daemon.CompileServiceImpl.checkedCompile(CompileServiceImpl.kt:957)
        at org.jetbrains.kotlin.daemon.CompileServiceImpl.doCompile(CompileServiceImpl.kt:926)
        at org.jetbrains.kotlin.daemon.CompileServiceImpl.compile(CompileServiceImpl.kt:404)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:498)
        at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:357)
        at sun.rmi.transport.Transport$1.run(Transport.java:200)
        at sun.rmi.transport.Transport$1.run(Transport.java:197)
        at java.security.AccessController.doPrivileged(Native Method)
        at sun.rmi.transport.Transport.serviceCall(Transport.java:196)
        at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:568)
        at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(TCPTransport.java:826)
        at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.lambda$run$0(TCPTransport.java:683)
        at java.security.AccessController.doPrivileged(Native Method)
        at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:682)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
        at java.lang.Thread.run(Thread.java:748)
johncarl81 commented 6 years ago

Not really... care to share the class that's causing this or perhaps a small project to demonstrate?

mnefzger commented 6 years ago

Thank you for your quick reply. Unfortunately, I cannot point to a single class that is causing the error. I'm trying to reproduce the issue in a small project, so far without luck.

mnefzger commented 6 years ago

Hi John, it seems that the usage of Kotlin's sealed class is the cause of the NPE. I already tried the approach described in #274 (writing a custom converter) but it did not change anything. Please see two examples below.

Without a sealed class, everything works fine:

@Parcel(Parcel.Serialization.BEAN)
data class Item @ParcelConstructor constructor(
    @SerializedName("title") val title: String,
    @SerializedName("description") val description: String,
    @SerializedName("drawableId") val drawableId: Int
)

When using a sealed class, I get the described NPE:

sealed class Notification {

    @Parcel(Parcel.Serialization.BEAN)
    data class NotificationInfo @ParcelConstructor constructor(
        val status: Status,
        val id: String
    ) : Notification()

    object NoNotificationAvailable : Notification()
}
mnefzger commented 6 years ago

Update: The error also occurs when wrapping a data class with @Parcel annotation inside another data class.

johncarl81 commented 6 years ago

My guess right now is the NPE is from a package not existing? Not sure without something concrete to diagnose.

johncarl81 commented 5 years ago

Can you share Status @mnefzger ?

mnefzger commented 5 years ago

Hi John, sorry for not updating the issue. We did not find a solution and decided to replace Parceler with Kotlin Parcelize in our app so we can move on. From my side, the issue can be closed as I was not able to reproduce it in a sample project.

johncarl81 commented 5 years ago

Sounds good, good luck!