Status Update
Comments
uc...@google.com <uc...@google.com>
at...@monzo.com <at...@monzo.com> #2
We have shared this with our product and engineering team and will update this issue with more information as it becomes available.
at...@monzo.com <at...@monzo.com> #3
Downgrading to AGP 3.6.2 (and Lint 26.6.2) doesn't appear to have this error.
cp...@twitter.com <cp...@twitter.com> #4
We're seeing plenty of instances of this issue. Looking at the expressions that cause this crash, I've seen a failure to enumerate the methods of a class made of top level functions and named with @file:JvmName
, when the class is referenced from a Java class. We've only seen this issue when running Lint on the application module and setting checkDependencies
to true.
gh...@google.com <gh...@google.com> #5
Reproducible on the
This might be related to
gh...@google.com <gh...@google.com>
gh...@google.com <gh...@google.com> #6
Notes:
- In the tivi project, this NPE happens because the Kotlin compiler is trying to inspect a Kotlin source file which does not have a corresponding entry in the
BindingTrace
. - When
checkDependencies=true
, Lint reuses the same instance ofKotlinCoreEnvironment
to analyze each module/dependency in the project. My theory is thatKotlinCoreEnvironment
is holding on to some caches between each analysis, eventually leading to this NPE. - Discussing with JetBrains folks, Ilya Chernikov added evidence to this theory: "As far as I can tell, we do not assume that it is safe to share KotlinCoreEnvironment between modules. It can work for some cases, but it was not designed to be reused this way."
- And, if I modify
LintDriver
so that a newKotlinCoreEnvironment
is created for every module, then I no longer see this NPE on the tivi project.
gh...@google.com <gh...@google.com> #7
Notes:
- The NPEs are much easier to repro by using
-XX:SoftRefLRUPolicyMSPerMB=0
- I tracked down the problematic cache in the Kotlin compiler:
org.jetbrains.kotlin.asJava.classes.FacadeCache
- If I manually reset
FacadeCache
before analyzing each module with Lint, then the NPEs no longer occur.
- If I manually reset
- There is work in progress from Tor to change how Lint works when
checkDependencies=true
, which as a side effect will fix this bug.- However, this is a large project and is not likely to make it into AGP 4.2.
- So, I'm looking into a workaround in the meantime.
ds...@gmail.com <ds...@gmail.com> #8
Downgrading Lint only (from 27.0.1 -> 26.6.3), doesn't help, another errors, but same reason: NPE AGP version is 4.0.1
Log after downgrade:
[05:54:24]The first 3 errors (out of 21) were:
[05:54:24]/app/avito-libs/account-storage/src/main/java/com/avito/android/account/account_manager/AccountManagerStorage.kt: Error: Unexpected failure during lint analysis of AccountManagerStorage.kt (this is a bug in lint or one of the libraries it depends on)
[05:54:24]
[05:54:24]
[05:54:24]The crash seems to involve the detector com.android.tools.lint.checks.ApiDetector.
[05:54:24]You can try disabling it with something like this:
[05:54:24] android {
[05:54:24] lintOptions {
[05:54:24] disable "InlinedApi", "ObsoleteSdkInt", "Override", "NewApi", "UnusedAttribute"
[05:54:24] }
[05:54:24] }
[05:54:24]
[05:54:24]Stack: NullPointerException:KtLightClassForFacade.getLightClassData(KtLightClassForFacade.kt:182)←KtLazyLightClass.getOwnMethods(KtLazyLightClass.kt:29)←KotlinClassInnerStuffCache.getAllMethods(KotlinClassInnerStuffCache.kt:150)←KotlinClassInnerStuffCache.access$getAllMethods(KotlinClassInnerStuffCache.kt:27)←KotlinClassInnerStuffCache$_getMethods$2.invoke(KotlinClassInnerStuffCache.kt:91)←KotlinClassInnerStuffCache$_getMethods$2.invoke(KotlinClassInnerStuffCache.kt:27)←KotlinClassInnerStuffCache$get$1$holder$1$1.compute(KotlinClassInnerStuffCache.kt:36)←PsiCachedValueImpl.doCompute(PsiCachedValueImpl.java:54)
[05:54:24]
[05:54:24]You can set environment variable LINT_PRINT_STACKTRACE=true to dump a full stacktrace to stdout. [LintError][05:54:24]/app/common/mvi/src/main/java/com/avito/android/mvi/v4/BaseMviEntityWithReducerQueue.kt: Error: Unexpected failure during lint analysis of BaseMviEntityWithReducerQueue.kt (this is a bug in lint or one of the libraries it depends on)
[05:54:24]
[05:54:24]
[05:54:24]The crash seems to involve the detector com.android.tools.lint.checks.ApiDetector.
[05:54:24]You can try disabling it with something like this:
[05:54:24] android {
[05:54:24] lintOptions {
[05:54:24] disable "InlinedApi", "ObsoleteSdkInt", "Override", "NewApi", "UnusedAttribute"
[05:54:24] }
[05:54:24] }
[05:54:24]
[05:54:24]Stack: NullPointerException:KtLightClassForFacade.getLightClassData(KtLightClassForFacade.kt:182)←KtLazyLightClass.getOwnMethods(KtLazyLightClass.kt:29)←KotlinClassInnerStuffCache.getAllMethods(KotlinClassInnerStuffCache.kt:150)←KotlinClassInnerStuffCache.access$getAllMethods(KotlinClassInnerStuffCache.kt:27)←KotlinClassInnerStuffCache$_getMethods$2.invoke(KotlinClassInnerStuffCache.kt:91)←KotlinClassInnerStuffCache$_getMethods$2.invoke(KotlinClassInnerStuffCache.kt:27)←KotlinClassInnerStuffCache$get$1$holder$1$1.compute(KotlinClassInnerStuffCache.kt:36)←PsiCachedValueImpl.doCompute(PsiCachedValueImpl.java:54)
[05:54:24]
[05:54:24]You can set environment variable LINT_PRINT_STACKTRACE=true to dump a full stacktrace to stdout. [LintError][05:54:24]/app/avito-app/notification/src/main/java/com/avito/android/notification_center/list/item/ErrorSnippetItemBlueprint.kt: Error: Unexpected failure during lint analysis of ErrorSnippetItemBlueprint.kt (this is a bug in lint or one of the libraries it depends on)
[05:54:24]
[05:54:24]Message: package fragment is not found for module:<lintWithKotlin> is a module[ModuleDescriptorImpl@7636bcef] file:KtFile: BaseViewHolder.kt
[05:54:24]
[05:54:24]Attachments:
[05:54:24]file.kt
[05:54:24]package com.avito.konveyor.adapter
[05:54:24]
[05:54:24]import androidx.recyclerview.widget.RecyclerView
[05:54:24]import android.view.View
[05:54:24]import com.avito.konveyor.blueprint.ItemView
[05:54:24]
[05:54:24]abstract class BaseViewHolder(view: View) : RecyclerView.ViewHolder(view), ItemView
[05:54:24]Stack: AssertionError:DefaultLogger.error(DefaultLogger.java:53)←Logger.error(Logger.java:170)←PackageCodegenImpl.getOnlyPackageFragment(PackageCodegenImpl.java:155)←PackageCodegenImpl.<init>(PackageCodegenImpl.java:62)←DefaultCodegenFactory.createPackageCodegen(CodegenFactory.kt:72)←DefaultCodegenFactory.createPackageCodegen(CodegenFactory.kt:42)←ClassFileFactory.forPackage(ClassFileFactory.java:256)←LightClassDataProviderForClassOrObject$computeLightClassData$1$1.invoke(LightClassDataProvider.kt:49)
[05:54:24]
[05:54:24]You can set environment variable LINT_PRINT_STACKTRACE=true to dump a full stacktrace to stdout. [LintError]
[Deleted User] <[Deleted User]> #9
This is a workaround that worked for us.
Hopefully this issue is fixed and we can revert back to using `checkDependencies`
[Deleted User] <[Deleted User]> #10
an...@google.com <an...@google.com> #11
al...@lyft.com <al...@lyft.com> #12
gh...@google.com <gh...@google.com> #13
There are some architectural changes coming in Lint that will fix this properly, but they will not make it into 4.2.
So, I submitted two workarounds that will be available starting in AGP 4.2 Beta 4:
-
Change I3c7422fa4 clears the
FacadeCache
in the Kotlin compiler between each module analysis. In my experiments this fixes the NPEs when running Lint on the Tivi project. -
Change Ibff843abc gives you the option to completely "reset" the Kotlin compiler between each module analysis (clearing all caches). I did not make this the default behavior because the effect on performance is unknown/risky.
To enable this behavior, either set the environment variable
LINT_DO_NOT_REUSE_UAST_ENV
to "true", or set the JVM system propertylint.do.not.reuse.uast.env
to "true". For example, you can do this from the command line:./gradlew -Dlint.do.not.reuse.uast.env=true :app:lintDebug
Or by putting this in your
gradle.properties
file:systemProp.lint.do.not.reuse.uast.env=true
ph...@monzo.com <ph...@monzo.com> #14
Did these changes make 4.2 Beta 4 in the end? I see them in the Alpha 5 notes, but not Beta 4.
ph...@monzo.com <ph...@monzo.com> #16
gh...@google.com <gh...@google.com> #17
Oh I see, thanks for pointing that out.
I did not intend for this bug to end up under the "general fixes" section (since it is not properly fixed yet).
Do let us know how 4.2-beta04 goes!
ph...@monzo.com <ph...@monzo.com> #18
I ended up having to work on other things, but eventually got round to upgrading last week.
I ran lint 100 times with 4.2.0-beta06 and saw 0 flakes. 🎉 I don't remember exact numbers, but with 4.x/4.1.x it was flaking something like 20% of the time.
gh...@google.com <gh...@google.com> #19
Yay! Thanks for confirming.
I'll mark the issue fixed, since the workaround in
ph...@monzo.com <ph...@monzo.com> #20
We also didn't need LINT_DO_NOT_REUSE_UAST_ENV
, the default behaviour was enough to get rid of the flakes.
Description
Summary
Lint fails for
WebViewApiAvailabilityDetector
at$Handler.visitCallExpression
with NPE.Retrying the build often works - it's not a consistent issue, so it's difficult to reproduce, but when it does fail, the number of Lint failures are the same (6 in our current project).
Environment
Build: AI-193.6911.18.40.6514223, 202005201507,
AI-193.6911.18.40.6514223, JRE 1.8.0_242-release-1644-b3-6222593x64 JetBrains s.r.o, OS Mac OS X(x86_64) v10.15.5, screens 2560x1440
AS: 4.0; Kotlin plugin: 1.3.72-release-Studio4.0-1; Android Gradle Plugin: 4.0.0; Gradle: 6.3; NDK: from local.properties: (not specified), latest from SDK: (not found); LLDB: pinned revision 3.1 not found, latest from SDK: (package not found); CMake: from local.properties: (not specified), latest from SDK: (not found), from PATH: (not found)
Additional environment
Stacktrace