5

While running lint a strange error occurred. This appears to happen after a androidx.lifecycle update from 2.2.0 to 2.3.0:

../../src/main/java/my/project/MyService.kt: Unexpected failure during lint analysis of MyService.kt
(this is a bug in lint or one of the libraries it depends on)

Message: org.jetbrains.uast.UastErrorType cannot be cast to com.intellij.psi.PsiClassType

The crash seems to involve the detector androidx.lifecycle.lint.NonNullableMutableLiveDataDetector.
You can try disabling it with something like this:
    android {
        lintOptions {
            disable "NullSafeMutableLiveData"
        }
    }

Stack: ClassCastException:NonNullableMutableLiveDataDetector.visitMethodCall(NonNullableMutableLiveDataDetector.kt:103)
←UElementVisitor$DelegatingPsiVisitor.visitMethodCallExpression(UElementVisitor.kt:1079)
←UElementVisitor$DelegatingPsiVisitor.visitCallExpression(UElementVisitor.kt:1059)
←UCallExpression$DefaultImpls.accept(UCallExpression.kt:85)
←UCallExpressionEx$DefaultImpls.accept(UCallExpression.kt:-1)
←KotlinUSimpleReferenceExpression$KotlinAccessorCallExpression.accept(KotlinUSimpleReferenceExpression.kt:129)
←KotlinUSimpleReferenceExpression.visitAccessorCalls(KotlinUSimpleReferenceExpression.kt:116)
←KotlinUSimpleReferenceExpression.accept(KotlinUSimpleReferenceExpression.kt:83)

You can set environment variable LINT_PRINT_STACKTRACE=true to dump a full stacktrace to stdout.
This issue type represents a problem running lint itself. Examples include failure to find bytecode for source files (which means certain detectors could not be run), parsing errors in lint configuration files, etc.

These errors are not errors in your own code, but they are shown to make it clear that some checks were not completed.
To suppress this error, use the issue id "LintError" as explained in the Suppressing Warnings and Errors section.

When I disable NullSafeMutableLiveData - as suggested - the error doesn't occur anymore, great! But I wonder where this issue comes from and if there's a better solution than simply ignoring that specific check completely. Is it a bug in the androidx.lifecycle dependency I could report, or is it possible to somehow conflict with an error in my project I could fix? (if so, any advice finding out where?)

Note: this only happened when lint was run on Bitrise, I didn't encounter this when running lint in Android Studio. Not sure if this is somehow related though.

P Kuijpers
  • 1,593
  • 15
  • 27
  • 1
    There's already [one fix to that lint rule](https://issuetracker.google.com/issues/169249668#comment8) that is going to be in the next Lifecycle release. You could try using the snapshot instructions there or [file a new bug](https://issuetracker.google.com/issues/new?component=413132&template=1096619) with your `MyService.kt` file that reproduces your issue (even if only on the command line and not in Studio). – ianhanniballake Mar 14 '21 at 15:42
  • Thanks, I noticed that one and several other related (recently reported) issues when I was adding an issue on issuetracker this morning. Guess it's solved soon! – P Kuijpers Mar 15 '21 at 16:07

0 Answers0