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

null cannot be cast to non-null type org.jetbrains.uast.UParameter in PermissionsLaunchDetector #1811

Closed
FelixZY opened this issue Dec 12, 2024 · 5 comments · Fixed by #1812
Assignees

Comments

@FelixZY
Copy link
Contributor

FelixZY commented Dec 12, 2024

Describe the bug

We started receiving this issue in our CI environment after upgrading dependencies (100% repro in my local environment as well). From what I can see, it seems like a bug in the com.google.accompanist.permissions.lint.PermissionsLaunchDetector detector.

* What went wrong:
Execution failed for task ':app:lintAnalyzeAppDebug'.
> A failure occurred while executing com.android.build.gradle.internal.lint.AndroidLintWorkAction
   > Unexpected failure during lint analysis (this is a bug in lint or one of the libraries it depends on)
     
     Message: Unexpected failure during lint analysis (this is a bug in lint or one of the libraries it depends on)
     
     Message: Unexpected failure during lint analysis of Permissions.kt (this is a bug in lint or one of the libraries it depends on)
     
     Message: null cannot be cast to non-null type org.jetbrains.uast.UParameter
     
     The crash seems to involve the detector \\\`com.google.accompanist.permissions.lint.PermissionsLaunchDetector\\\`.
     You can try disabling it with something like this:
         android {
             lint {
                 disable "PermissionLaunchedDuringComposition"
             }
         }
Full stack trace

(Stack traces have been prettified for readability)

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:lintAnalyzeAppDebug'.
> A failure occurred while executing com.android.build.gradle.internal.lint.AndroidLintWorkAction
   > Unexpected failure during lint analysis (this is a bug in lint or one of the libraries it depends on)
     
     Message: Unexpected failure during lint analysis (this is a bug in lint or one of the libraries it depends on)
     
     Message: Unexpected failure during lint analysis of Permissions.kt (this is a bug in lint or one of the libraries it depends on)
     
     Message: null cannot be cast to non-null type org.jetbrains.uast.UParameter
     
     The crash seems to involve the detector \\\`com.google.accompanist.permissions.lint.PermissionsLaunchDetector\\\`.
     You can try disabling it with something like this:
         android {
             lint {
                 disable "PermissionLaunchedDuringComposition"
             }
         }

Stack:
  NullPointerException:
    ComposableUtilsKt.isComposable(ComposableUtils.kt:124)
    ←ComposableUtilsKt.isComposable(ComposableUtils.kt:135)
    ←ComposableBodyVisitor.isComposable(ComposableUtils.kt:161)
    ←ComposableUtilsKt.isInvokedWithinComposable(ComposableUtils.kt:59)
    ←PermissionsLaunchDetector.visitMethodCall(PermissionsLaunchDetector.kt:52)
    ←UElementVisitor$DelegatingUastVisitor.visitMethodCallExpression(UElementVisitor.kt:780)
    ←UElementVisitor$DelegatingUastVisitor.visitCallExpression(UElementVisitor.kt:761)
    ←UCallExpression.accept(UCallExpression.kt:94)
    ←UQualifiedReferenceExpression.accept(UQualifiedReferenceExpression.kt:34)
    ←UReturnExpression.accept(UReturnExpression.kt:22)
    ←ImplementationUtilsKt.acceptList(implementationUtils.kt:15)
    ←UBlockExpression.accept(UBlockExpression.kt:21)
    ←ULambdaExpression.accept(ULambdaExpression.kt:40)
    ←ImplementationUtilsKt.acceptList(implementationUtils.kt:15)
    ←UCallExpression.accept(UCallExpression.kt:98)
    ←UReturnExpression.accept(UReturnExpression.kt:22)
    ←ImplementationUtilsKt.acceptList(implementationUtils.kt:15)
    ←UBlockExpression.accept(UBlockExpression.kt:21)
    ←ULambdaExpression.accept(ULambdaExpression.kt:40)
    ←ImplementationUtilsKt.acceptList(implementationUtils.kt:15)
    ←UCallExpression.accept(UCallExpression.kt:98)
    ←ImplementationUtilsKt.acceptList(implementationUtils.kt:15)
    ←UBlockExpression.accept(UBlockExpression.kt:21)
    ←UMethod.accept(UMethod.kt:45)
    ←ImplementationUtilsKt.acceptList(implementationUtils.kt:15)
    ←AbstractKotlinUClass.accept(AbstractKotlinUClass.kt:213)
    ←ImplementationUtilsKt.acceptList(implementationUtils.kt:15)
    ←UFile.accept(UFile.kt:89)
    ←UastLintUtilsKt.acceptSourceFile(UastLintUtils.kt:953)
    ←UElementVisitor$visitFile$3.run(UElementVisitor.kt:216)
    ←LintClient.runReadAction(LintClient.kt:1781)
    ←LintDriver$LintClientWrapper.runReadAction(LintDriver.kt:2747)
    ←UElementVisitor.visitFile(UElementVisitor.kt:213)
    ←LintDriver$visitUastDetectors$1.run(LintDriver.kt:2048)
    ←LintClient.runReadAction(LintClient.kt:1781)
    ←LintDriver$LintClientWrapper.runReadAction(LintDriver.kt:2747)
    ←LintDriver.visitUastDetectors(LintDriver.kt:2048)
    ←LintDriver.visitUast(LintDriver.kt:2010)
    ←LintDriver.runFileDetectors(LintDriver.kt:1284)
    ←LintDriver.checkProject(LintDriver.kt:1070)
    ←LintDriver.checkProjectRoot(LintDriver.kt:622)
    ←LintDriver.access$checkProjectRoot(LintDriver.kt:174)
    ←LintDriver$analyzeOnly$1.invoke(LintDriver.kt:445)
    ←LintDriver$analyzeOnly$1.invoke(LintDriver.kt:442)
    ←LintDriver.doAnalyze(LintDriver.kt:501)
    ←LintDriver.analyzeOnly(LintDriver.kt:442)
    ←LintCliClient$analyzeOnly$1.invoke(LintCliClient.kt:258)
    ←LintCliClient$analyzeOnly$1.invoke(LintCliClient.kt:255)
    ←LintCliClient.run(LintCliClient.kt:312)
    ←LintCliClient.analyzeOnly(LintCliClient.kt:255)
    ←Main.run(Main.java:1766)
    ←Main.run(Main.java:282)
    ←DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:104)
    ←Method.invoke(Method.java:578)
    ←AndroidLintWorkAction.invokeLintMainRunMethod(AndroidLintWorkAction.kt:103)
    ←AndroidLintWorkAction.runLint(AndroidLintWorkAction.kt:90)
    ←AndroidLintWorkAction.execute(AndroidLintWorkAction.kt:64)
    ←DefaultWorkerServer.execute(DefaultWorkerServer.java:63)
    ←NoIsolationWorkerFactory$1$1.create(NoIsolationWorkerFactory.java:66)
    ←NoIsolationWorkerFactory$1$1.create(NoIsolationWorkerFactory.java:62)
    ←ClassLoaderUtils.executeInClassloader(ClassLoaderUtils.java:100)
    ←NoIsolationWorkerFactory$1.lambda$execute$0(NoIsolationWorkerFactory.java:62)
    ←AbstractWorker$1.call(AbstractWorker.java:44)
    ←AbstractWorker$1.call(AbstractWorker.java:41)
    ←DefaultBuildOperationRunner$CallableBuildOperationWorker.execute(DefaultBuildOperationRunner.java:209)
    ←DefaultBuildOperationRunner$CallableBuildOperationWorker.execute(DefaultBuildOperationRunner.java:204)
    ←DefaultBuildOperationRunner$2.execute(DefaultBuildOperationRunner.java:66)
    ←DefaultBuildOperationRunner$2.execute(DefaultBuildOperationRunner.java:59)
    ←DefaultBuildOperationRunner.execute(DefaultBuildOperationRunner.java:166)
    ←DefaultBuildOperationRunner.execute(DefaultBuildOperationRunner.java:59)
    ←DefaultBuildOperationRunner.call(DefaultBuildOperationRunner.java:53)
    ←AbstractWorker.executeWrappedInBuildOperation(AbstractWorker.java:41)
    ←NoIsolationWorkerFactory$1.execute(NoIsolationWorkerFactory.java:59)
    ←DefaultWorkerExecutor.lambda$submitWork$0(DefaultWorkerExecutor.java:174)
    ←FutureTask.run(FutureTask.java:317)
    ←DefaultConditionalExecutionQueue$ExecutionRunner.runExecution(DefaultConditionalExecutionQueue.java:195)
    ←DefaultConditionalExecutionQueue$ExecutionRunner.access$700(DefaultConditionalExecutionQueue.java:128)
    ←DefaultConditionalExecutionQueue$ExecutionRunner$1.run(DefaultConditionalExecutionQueue.java:170)
    ←Factories$1.create(Factories.java:31)
    ←DefaultWorkerLeaseService.withLocks(DefaultWorkerLeaseService.java:267)
    ←DefaultWorkerLeaseService.runAsWorkerThread(DefaultWorkerLeaseService.java:131)
    ←DefaultWorkerLeaseService.runAsWorkerThread(DefaultWorkerLeaseService.java:136)
    ←DefaultConditionalExecutionQueue$ExecutionRunner.runBatch(DefaultConditionalExecutionQueue.java:165)
    ←DefaultConditionalExecutionQueue$ExecutionRunner.run(DefaultConditionalExecutionQueue.java:134)
    ←Executors$RunnableAdapter.call(Executors.java:577)
    ←FutureTask.run(FutureTask.java:317)
    ←ExecutorPolicy$CatchAndRecordFailures.onExecute(ExecutorPolicy.java:64)
    ←AbstractManagedExecutor$1.run(AbstractManagedExecutor.java:48)
    ←ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1144)
    ←ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:642)
    ←Thread.run(Thread.java:1589)

Stack:
  RuntimeException:
    LintDriver$Companion.handleDetectorError(LintDriver.kt:3740)
    ←LintDriver$Companion.handleDetectorError$default(LintDriver.kt:3607)
    ←LintDriver$Companion.handleDetectorError(LintDriver.kt:3603)
    ←UElementVisitor.visitFile(UElementVisitor.kt:242)
    ←LintDriver$visitUastDetectors$1.run(LintDriver.kt:2048)
    ←LintClient.runReadAction(LintClient.kt:1781)
    ←LintDriver$LintClientWrapper.runReadAction(LintDriver.kt:2747)
    ←LintDriver.visitUastDetectors(LintDriver.kt:2048)
    ←LintDriver.visitUast(LintDriver.kt:2010)
    ←LintDriver.runFileDetectors(LintDriver.kt:1284)
    ←LintDriver.checkProject(LintDriver.kt:1070)
    ←LintDriver.checkProjectRoot(LintDriver.kt:622)
    ←LintDriver.access$checkProjectRoot(LintDriver.kt:174)
    ←LintDriver$analyzeOnly$1.invoke(LintDriver.kt:445)
    ←LintDriver$analyzeOnly$1.invoke(LintDriver.kt:442)
    ←LintDriver.doAnalyze(LintDriver.kt:501)
    ←LintDriver.analyzeOnly(LintDriver.kt:442)
    ←LintCliClient$analyzeOnly$1.invoke(LintCliClient.kt:258)
    ←LintCliClient$analyzeOnly$1.invoke(LintCliClient.kt:255)
    ←LintCliClient.run(LintCliClient.kt:312)
    ←LintCliClient.analyzeOnly(LintCliClient.kt:255)
    ←Main.run(Main.java:1766)
    ←Main.run(Main.java:282)
    ←DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:104)
    ←Method.invoke(Method.java:578)
    ←AndroidLintWorkAction.invokeLintMainRunMethod(AndroidLintWorkAction.kt:103)
    ←AndroidLintWorkAction.runLint(AndroidLintWorkAction.kt:90)
    ←AndroidLintWorkAction.execute(AndroidLintWorkAction.kt:64)
    ←DefaultWorkerServer.execute(DefaultWorkerServer.java:63)
    ←NoIsolationWorkerFactory$1$1.create(NoIsolationWorkerFactory.java:66)
    ←NoIsolationWorkerFactory$1$1.create(NoIsolationWorkerFactory.java:62)
    ←ClassLoaderUtils.executeInClassloader(ClassLoaderUtils.java:100)
    ←NoIsolationWorkerFactory$1.lambda$execute$0(NoIsolationWorkerFactory.java:62)
    ←AbstractWorker$1.call(AbstractWorker.java:44)
    ←AbstractWorker$1.call(AbstractWorker.java:41)
    ←DefaultBuildOperationRunner$CallableBuildOperationWorker.execute(DefaultBuildOperationRunner.java:209)
    ←DefaultBuildOperationRunner$CallableBuildOperationWorker.execute(DefaultBuildOperationRunner.java:204)
    ←DefaultBuildOperationRunner$2.execute(DefaultBuildOperationRunner.java:66)
    ←DefaultBuildOperationRunner$2.execute(DefaultBuildOperationRunner.java:59)
    ←DefaultBuildOperationRunner.execute(DefaultBuildOperationRunner.java:166)
    ←DefaultBuildOperationRunner.execute(DefaultBuildOperationRunner.java:59)
    ←DefaultBuildOperationRunner.call(DefaultBuildOperationRunner.java:53)
    ←AbstractWorker.executeWrappedInBuildOperation(AbstractWorker.java:41)
    ←NoIsolationWorkerFactory$1.execute(NoIsolationWorkerFactory.java:59)
    ←DefaultWorkerExecutor.lambda$submitWork$0(DefaultWorkerExecutor.java:174)
    ←FutureTask.run(FutureTask.java:317)
    ←DefaultConditionalExecutionQueue$ExecutionRunner.runExecution(DefaultConditionalExecutionQueue.java:195)
    ←DefaultConditionalExecutionQueue$ExecutionRunner.access$700(DefaultConditionalExecutionQueue.java:128)
    ←DefaultConditionalExecutionQueue$ExecutionRunner$1.run(DefaultConditionalExecutionQueue.java:170)
    ←Factories$1.create(Factories.java:31)
    ←DefaultWorkerLeaseService.withLocks(DefaultWorkerLeaseService.java:267)
    ←DefaultWorkerLeaseService.runAsWorkerThread(DefaultWorkerLeaseService.java:131)
    ←DefaultWorkerLeaseService.runAsWorkerThread(DefaultWorkerLeaseService.java:136)
    ←DefaultConditionalExecutionQueue$ExecutionRunner.runBatch(DefaultConditionalExecutionQueue.java:165)
    ←DefaultConditionalExecutionQueue$ExecutionRunner.run(DefaultConditionalExecutionQueue.java:134)
    ←Executors$RunnableAdapter.call(Executors.java:577)
    ←FutureTask.run(FutureTask.java:317)
    ←ExecutorPolicy$CatchAndRecordFailures.onExecute(ExecutorPolicy.java:64)
    ←AbstractManagedExecutor$1.run(AbstractManagedExecutor.java:48)
    ←ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1144)
    ←ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:642)
    ←Thread.run(Thread.java:1589)

Stack:
  RuntimeException:
    LintDriver$Companion.handleDetectorError(LintDriver.kt:3740)
    ←LintDriver$Companion.handleDetectorError$default(LintDriver.kt:3607)
    ←LintDriver$Companion.handleDetectorError(LintDriver.kt:3603)
    ←LintDriver$analyzeOnly$1.invoke(LintDriver.kt:447)
    ←LintDriver$analyzeOnly$1.invoke(LintDriver.kt:442)
    ←LintDriver.doAnalyze(LintDriver.kt:501)
    ←LintDriver.analyzeOnly(LintDriver.kt:442)
    ←LintCliClient$analyzeOnly$1.invoke(LintCliClient.kt:258)
    ←LintCliClient$analyzeOnly$1.invoke(LintCliClient.kt:255)
    ←LintCliClient.run(LintCliClient.kt:312)
    ←LintCliClient.analyzeOnly(LintCliClient.kt:255)
    ←Main.run(Main.java:1766)
    ←Main.run(Main.java:282)
    ←DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:104)
    ←Method.invoke(Method.java:578)
    ←AndroidLintWorkAction.invokeLintMainRunMethod(AndroidLintWorkAction.kt:103)
    ←AndroidLintWorkAction.runLint(AndroidLintWorkAction.kt:90)
    ←AndroidLintWorkAction.execute(AndroidLintWorkAction.kt:64)
    ←DefaultWorkerServer.execute(DefaultWorkerServer.java:63)
    ←NoIsolationWorkerFactory$1$1.create(NoIsolationWorkerFactory.java:66)
    ←NoIsolationWorkerFactory$1$1.create(NoIsolationWorkerFactory.java:62)
    ←ClassLoaderUtils.executeInClassloader(ClassLoaderUtils.java:100)
    ←NoIsolationWorkerFactory$1.lambda$execute$0(NoIsolationWorkerFactory.java:62)
    ←AbstractWorker$1.call(AbstractWorker.java:44)
    ←AbstractWorker$1.call(AbstractWorker.java:41)
    ←DefaultBuildOperationRunner$CallableBuildOperationWorker.execute(DefaultBuildOperationRunner.java:209)
    ←DefaultBuildOperationRunner$CallableBuildOperationWorker.execute(DefaultBuildOperationRunner.java:204)
    ←DefaultBuildOperationRunner$2.execute(DefaultBuildOperationRunner.java:66)
    ←DefaultBuildOperationRunner$2.execute(DefaultBuildOperationRunner.java:59)
    ←DefaultBuildOperationRunner.execute(DefaultBuildOperationRunner.java:166)
    ←DefaultBuildOperationRunner.execute(DefaultBuildOperationRunner.java:59)
    ←DefaultBuildOperationRunner.call(DefaultBuildOperationRunner.java:53)
    ←AbstractWorker.executeWrappedInBuildOperation(AbstractWorker.java:41)
    ←NoIsolationWorkerFactory$1.execute(NoIsolationWorkerFactory.java:59)
    ←DefaultWorkerExecutor.lambda$submitWork$0(DefaultWorkerExecutor.java:174)
    ←FutureTask.run(FutureTask.java:317)
    ←DefaultConditionalExecutionQueue$ExecutionRunner.runExecution(DefaultConditionalExecutionQueue.java:195)
    ←DefaultConditionalExecutionQueue$ExecutionRunner.access$700(DefaultConditionalExecutionQueue.java:128)
    ←DefaultConditionalExecutionQueue$ExecutionRunner$1.run(DefaultConditionalExecutionQueue.java:170)
    ←Factories$1.create(Factories.java:31)
    ←DefaultWorkerLeaseService.withLocks(DefaultWorkerLeaseService.java:267)
    ←DefaultWorkerLeaseService.runAsWorkerThread(DefaultWorkerLeaseService.java:131)
    ←DefaultWorkerLeaseService.runAsWorkerThread(DefaultWorkerLeaseService.java:136)
    ←DefaultConditionalExecutionQueue$ExecutionRunner.runBatch(DefaultConditionalExecutionQueue.java:165)
    ←DefaultConditionalExecutionQueue$ExecutionRunner.run(DefaultConditionalExecutionQueue.java:134)
    ←Executors$RunnableAdapter.call(Executors.java:577)
    ←FutureTask.run(FutureTask.java:317)
    ←ExecutorPolicy$CatchAndRecordFailures.onExecute(ExecutorPolicy.java:64)
    ←AbstractManagedExecutor$1.run(AbstractManagedExecutor.java:48)
    ←ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1144)
    ←ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:642)
    ←Thread.run(Thread.java:1589)

To Reproduce

Sorry, no repro at this time.

$ ./gradlew :app:lintAnalyzeAppDebug

Expected behavior

No crash - build should succeed.

Environment:

  • GitHub Actions
  • Accompanist version: com.google.accompanist:accompanist-permissions:0.32.0
$ ./gradlew --version

------------------------------------------------------------
Gradle 8.9
------------------------------------------------------------

Build time:    2024-07-11 14:37:41 UTC
Revision:      d536ef36a19186ccc596d8817123e5445f30fef8

Kotlin:        1.9.23
Groovy:        3.0.21
Ant:           Apache Ant(TM) version 1.10.13 compiled on January 4 2023
Launcher JVM:  19.0.2 (Private Build 19.0.2+7-Ubuntu-0ubuntu322.04)
Daemon JVM:    /usr/lib/jvm/java-19-openjdk-amd64 (no JDK specified, using current Java home)
OS:            Linux 6.8.0-49-generic amd64
@FelixZY
Copy link
Contributor Author

FelixZY commented Dec 13, 2024

Just realized 0.36.0 is the latest release. However, the same error occurs on this version.

@FelixZY
Copy link
Contributor Author

FelixZY commented Dec 13, 2024

Git bisect indicates that the bug started appearing after upgrading kotlin from 1.9 to 2.1.0. This specific commit includes adding the compose compiler (org.jetbrains.kotlin.plugin.compose) to our build gradle as well.

@FelixZY
Copy link
Contributor Author

FelixZY commented Dec 13, 2024

Actually, it looks like @bentrengrove fixed this in #1804 (4a6828b) just three days ago:

ComposableUtils.kt

-        else -> (toUElement() as UParameter).typeReference!!.isComposable
+            else -> (toUElement() as? UParameter)?.typeReference?.isComposable == true

@bentrengrove
Copy link
Collaborator

I'll get out a new release for you

@FelixZY
Copy link
Contributor Author

FelixZY commented Dec 13, 2024

Confirmed, issue resolved. Thank you for the release @bentrengrove !

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