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

NullPointerException in 2.1.1 in Android compilation #771

Closed
leepa opened this issue Oct 11, 2017 · 24 comments
Closed

NullPointerException in 2.1.1 in Android compilation #771

leepa opened this issue Oct 11, 2017 · 24 comments

Comments

@leepa
Copy link

leepa commented Oct 11, 2017

I can't see an obvious check that's failing here. This is compiling an Android application.

3 warnings
An exception has occurred in the compiler (1.8.0_112-release). Please file a bug against the Java compiler via the Java bug reporting page (http://bugreport.java.com) after checking the Bug Database (http://bugs.java.com) for duplicates. Include your program and the following diagnostic in your report. Thank you.
java.lang.NullPointerException
	at com.sun.tools.javac.comp.Flow$FlowAnalyzer.visitApply(Flow.java:1233)
	at com.sun.tools.javac.tree.JCTree$JCMethodInvocation.accept(JCTree.java:1628)
	at com.sun.tools.javac.tree.TreeScanner.scan(TreeScanner.java:49)
	at com.sun.tools.javac.comp.Flow$BaseAnalyzer.scan(Flow.java:393)
	at com.sun.tools.javac.tree.TreeScanner.visitExec(TreeScanner.java:213)
	at com.sun.tools.javac.tree.JCTree$JCExpressionStatement.accept(JCTree.java:1446)
	at com.sun.tools.javac.tree.TreeScanner.scan(TreeScanner.java:49)
	at com.sun.tools.javac.comp.Flow$BaseAnalyzer.scan(Flow.java:393)
	at com.sun.tools.javac.tree.TreeScanner.scan(TreeScanner.java:57)
	at com.sun.tools.javac.comp.Flow$FlowAnalyzer.visitBlock(Flow.java:995)
	at com.sun.tools.javac.tree.JCTree$JCBlock.accept(JCTree.java:1014)
	at com.sun.tools.javac.tree.TreeScanner.scan(TreeScanner.java:49)
	at com.sun.tools.javac.comp.Flow$BaseAnalyzer.scan(Flow.java:393)
	at com.sun.tools.javac.comp.Flow$FlowAnalyzer.visitMethodDef(Flow.java:962)
	at com.sun.tools.javac.tree.JCTree$JCMethodDecl.accept(JCTree.java:866)
	at com.sun.tools.javac.tree.TreeScanner.scan(TreeScanner.java:49)
	at com.sun.tools.javac.comp.Flow$BaseAnalyzer.scan(Flow.java:393)
	at com.sun.tools.javac.comp.Flow$FlowAnalyzer.visitClassDef(Flow.java:925)
	at com.sun.tools.javac.tree.JCTree$JCClassDecl.accept(JCTree.java:774)
	at com.sun.tools.javac.tree.TreeScanner.scan(TreeScanner.java:49)
	at com.sun.tools.javac.comp.Flow$BaseAnalyzer.scan(Flow.java:393)
	at com.sun.tools.javac.comp.Flow$FlowAnalyzer.analyzeTree(Flow.java:1325)
	at com.sun.tools.javac.comp.Flow$FlowAnalyzer.analyzeTree(Flow.java:1315)
	at com.sun.tools.javac.comp.Flow.analyzeTree(Flow.java:213)
	at com.sun.tools.javac.main.JavaCompiler.flow(JavaCompiler.java:1410)
	at com.sun.tools.javac.main.JavaCompiler.flow(JavaCompiler.java:1374)
	at com.sun.tools.javac.main.JavaCompiler.compile(JavaCompiler.java:973)
	at com.sun.tools.javac.api.JavacTaskImpl.lambda$doCall$0(JavacTaskImpl.java:100)
	at com.sun.tools.javac.api.JavacTaskImpl.handleExceptions(JavacTaskImpl.java:142)
	at com.sun.tools.javac.api.JavacTaskImpl.doCall(JavacTaskImpl.java:96)
	at com.sun.tools.javac.api.JavacTaskImpl.call(JavacTaskImpl.java:90)
	at com.google.errorprone.BaseErrorProneCompiler.run(BaseErrorProneCompiler.java:137)
	at com.google.errorprone.BaseErrorProneCompiler.run(BaseErrorProneCompiler.java:108)
	at com.google.errorprone.ErrorProneCompiler.run(ErrorProneCompiler.java:118)
	at com.google.errorprone.ErrorProneCompiler.compile(ErrorProneCompiler.java:65)
	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 net.ltgt.gradle.errorprone.ErrorProneCompiler.execute(ErrorProneCompiler.java:76)
	at net.ltgt.gradle.errorprone.ErrorProneCompiler.execute(ErrorProneCompiler.java:26)
	at org.gradle.api.internal.tasks.compile.NormalizingJavaCompiler.delegateAndHandleErrors(NormalizingJavaCompiler.java:104)
	at org.gradle.api.internal.tasks.compile.NormalizingJavaCompiler.execute(NormalizingJavaCompiler.java:53)
	at org.gradle.api.internal.tasks.compile.NormalizingJavaCompiler.execute(NormalizingJavaCompiler.java:38)
	at org.gradle.api.internal.tasks.compile.CleaningJavaCompilerSupport.execute(CleaningJavaCompilerSupport.java:35)
	at org.gradle.api.internal.tasks.compile.CleaningJavaCompilerSupport.execute(CleaningJavaCompilerSupport.java:25)
	at org.gradle.api.tasks.compile.JavaCompile.performCompilation(JavaCompile.java:206)
	at org.gradle.api.tasks.compile.JavaCompile.compile(JavaCompile.java:187)
	at org.gradle.api.tasks.compile.JavaCompile.compile(JavaCompile.java:130)
	at com.android.build.gradle.tasks.factory.AndroidJavaCompile.compile(AndroidJavaCompile.java:49)
	at sun.reflect.GeneratedMethodAccessor1187.invoke(Unknown Source)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at org.gradle.internal.reflect.JavaMethod.invoke(JavaMethod.java:73)
	at org.gradle.api.internal.project.taskfactory.DefaultTaskClassInfoStore$IncrementalTaskAction.doExecute(DefaultTaskClassInfoStore.java:163)
	at org.gradle.api.internal.project.taskfactory.DefaultTaskClassInfoStore$StandardTaskAction.execute(DefaultTaskClassInfoStore.java:134)
	at org.gradle.api.internal.project.taskfactory.DefaultTaskClassInfoStore$StandardTaskAction.execute(DefaultTaskClassInfoStore.java:123)
	at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeAction(ExecuteActionsTaskExecuter.java:95)
	at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(ExecuteActionsTaskExecuter.java:76)
	at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.execute(ExecuteActionsTaskExecuter.java:55)
	at org.gradle.api.internal.tasks.execution.SkipUpToDateTaskExecuter.execute(SkipUpToDateTaskExecuter.java:62)
	at org.gradle.api.internal.tasks.execution.ValidatingTaskExecuter.execute(ValidatingTaskExecuter.java:58)
	at org.gradle.api.internal.tasks.execution.SkipEmptySourceFilesTaskExecuter.execute(SkipEmptySourceFilesTaskExecuter.java:88)
	at org.gradle.api.internal.tasks.execution.ResolveTaskArtifactStateTaskExecuter.execute(ResolveTaskArtifactStateTaskExecuter.java:46)
	at org.gradle.api.internal.tasks.execution.SkipTaskWithNoActionsExecuter.execute(SkipTaskWithNoActionsExecuter.java:51)
	at org.gradle.api.internal.tasks.execution.SkipOnlyIfTaskExecuter.execute(SkipOnlyIfTaskExecuter.java:54)
	at org.gradle.api.internal.tasks.execution.ExecuteAtMostOnceTaskExecuter.execute(ExecuteAtMostOnceTaskExecuter.java:43)
	at org.gradle.api.internal.tasks.execution.CatchExceptionTaskExecuter.execute(CatchExceptionTaskExecuter.java:34)
	at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter$EventFiringTaskWorker$1.execute(DefaultTaskGraphExecuter.java:236)
	at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter$EventFiringTaskWorker$1.execute(DefaultTaskGraphExecuter.java:228)
	at org.gradle.internal.Transformers$4.transform(Transformers.java:169)
	at org.gradle.internal.progress.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:106)
	at org.gradle.internal.progress.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:61)
	at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter$EventFiringTaskWorker.execute(DefaultTaskGraphExecuter.java:228)
	at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter$EventFiringTaskWorker.execute(DefaultTaskGraphExecuter.java:215)
	at org.gradle.execution.taskgraph.AbstractTaskPlanExecutor$TaskExecutorWorker.processTask(AbstractTaskPlanExecutor.java:77)
	at org.gradle.execution.taskgraph.AbstractTaskPlanExecutor$TaskExecutorWorker.run(AbstractTaskPlanExecutor.java:58)
	at org.gradle.internal.concurrent.ExecutorPolicy$CatchAndRecordFailures.onExecute(ExecutorPolicy.java:54)
	at org.gradle.internal.concurrent.StoppableExecutorImpl$1.run(StoppableExecutorImpl.java:40)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
	at java.lang.Thread.run(Thread.java:745)

 FAILED

FAILURE: Build failed with an exception.
@cushon
Copy link
Collaborator

cushon commented Oct 11, 2017

An exception has occurred in the compiler (1.8.0_112-release).

How are you invoking Error Prone? It looks like you aren't using the version of javac we distribute.

@leepa
Copy link
Author

leepa commented Oct 11, 2017

It's just an Android Gradle project. Is there anything specific I need to add beyond the plugin?

@cushon
Copy link
Collaborator

cushon commented Oct 11, 2017

@tbroyer FYI

I think gradle-errorprone-plugin uses an isolated classloader to make sure the plugin uses the right version of javac, but something is going wrong here. Do you have a self-contained example that reproduces the problem?

@leepa
Copy link
Author

leepa commented Oct 12, 2017

I'll try and make a self-contained example today.

@leepa
Copy link
Author

leepa commented Oct 12, 2017

I have solved this - it's caused by Android projects using Java 7 (but with retrofit lambda etc.) and Error Prone > 2.0.5 requiring Java 8. Or at least when I downgraded to 2.0.5 it all worked again. Unfortunately that's awkward as there's fixes post 2.0.5 which fix other issues. Guess I won't be using it until I upgrade to Android Studio 3.

@bubenheimer
Copy link

This should be reopened. As I mention in the referenced issue I see the same problem on an Android project regardless of using Java 7 or 8. It's a matter of using errorprone 2.0.19 vs. 2.0.20.

Minimal sample project for reproduction here: https://github.com/bubenheimer/errorpronebug

A few more details in the referenced issue.

@eaftan eaftan reopened this Oct 23, 2017
@andyken
Copy link

andyken commented Nov 14, 2017

I solved this problem by updating error-prone to the newest version 2.1.2.
errorprone "com.google.errorprone:error_prone_core:2.1.2"

update:
The problem happened again...

@bubenheimer
Copy link

The sample project build continues to fail with 2.1.2.

@andyken
Copy link

andyken commented Nov 15, 2017

I removed the options.compilerArgs += ["-Xep:MissingCasesInEnumSwitch:WARN"].And the problem does not appear

@bubenheimer
Copy link

bubenheimer commented Feb 14, 2018

The issue remains present with Android Studio 3.1.0-beta2, the new Android databinding compiler, and errorprone 2.2.0. Errorprone seems incompatible with databinding, for all versions after 2.0.19. Is there any plan to change this?

@rickytribbia
Copy link

rickytribbia commented Mar 2, 2018

Same issue here.

My gradle in Android Studio 3.0.1

using classpath 'com.android.tools.build:gradle:3.0.1'

buildscript {
    repositories {
        ...
        maven { url 'https://plugins.gradle.org/m2/' }
    }

    dependencies {
        ...
        classpath "com.android.databinding:dataBinder:1.0-rc0"
        classpath "net.ltgt.gradle:gradle-errorprone-plugin:0.0.13"
    }
}

apply plugin: 'net.ltgt.errorprone'

... 

android {
    ...
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
}

tasks.withType(JavaCompile) {
    options.compilerArgs += ['-Xep:DeadException:WARN', '-XepExcludedPaths:.*/build/generated/.*', '-XepAllErrorsAsWarnings', '-XepAllDisabledChecksAsWarnings']
}

dependencies {
    errorprone "com.google.errorprone:error_prone_core:2.2.0"
    ...
}

@bubenheimer
Copy link

Adding the following in gradle.properties has resolved all errorprone-related compile crashes on my Android builds. This would require a recent Android Studio/AGP version, at least 3.3-alpha11 (I'm using alpha13).

android.enableSeparateAnnotationProcessing=true

@bubenheimer
Copy link

Can anything be done to address this issue? The reliable "enableSeparateAnnotationProcessing" flag workaround I described above is being removed. Or is someone able to exert their clout on the Android Developer Tools team to keep the flag around, perhaps with a different name, to keep errorprone usable on Android? https://issuetracker.google.com/issues/115774858

@cushon
Copy link
Collaborator

cushon commented May 20, 2020

Is this still reproducible when using recent versions of Error Prone / databinding / gradle / the Android plugin, and running on JDK 11?

I think the NullPointerException in Flow$FlowAnalyzer.visitApply was fixed in JDK 11 by JDK-8187950. If that's the culprit, it's not clear to me that we can do anything to mitigate this is Error Prone when running on older javac versions.

@bubenheimer
Copy link

Android Studio uses OpenJDK 9 AFAIK, so I don't think I'd be able to test out this theory anytime soon.

@bubenheimer
Copy link

OpenJDK 8, actually

@cushon
Copy link
Collaborator

cushon commented May 20, 2020

Thanks. Are you seeing the same issue with the latest version of databinding? I started trying to update versions in https://github.com/bubenheimer/errorpronebug but am less familiar with the Android/databinding side of this.

@bubenheimer
Copy link

Yes, and I don't think it is tied to databinding, that just brings it out more easily. Pretty sure I have Gradle modules that break without databinding. The issue is intermittent in nature. Thank you for looking into it again.

I've updated the project to all the latest dependencies and pushed it. The compiler crash has remained the same for me.

@cushon
Copy link
Collaborator

cushon commented May 21, 2020

Thanks. I can still reproduce:

$ JAVA_HOME=$JAVA8_HOME ./gradlew -version
...
JVM:          1.8.0_202 (Oracle Corporation 25.202-b08)
$ JAVA_HOME=$JAVA8_HOME ./gradlew build
...
> Task :app:compileDebugJavaWithJavac FAILED
An exception has occurred in the compiler ((version info not available)). Please file a bug against the Java compiler via the Java bug reporting page (http://bugreport.java.com) after checking the Bug Database (http://bugs.java.com) for duplicates. Include your program and the following diagnostic in your report. Thank you.
java.lang.NullPointerException
        at com.sun.tools.javac.comp.Flow$FlowAnalyzer.visitApply(Flow.java:1233)

... but it builds cleanly with JDK 11 (and the fix for JDK-8187950.)

$ JAVA_HOME=$JAVA11_HOME ./gradlew -version
...
JVM:          11.0.7 (Oracle Corporation 11.0.7+10)
$ JAVA_HOME=$JAVA11_HOME ./gradlew build
...

> Task :app:compileDebugJavaWithJavac app/build/generated/ap_generated_sources/debug/out/org/bubenheimer/errorpronebug/databinding/ActivityMainBindingImpl.java:72: warning: [UnusedVariable] The local variable 'dirtyFlags' is never read.
        long dirtyFlags = 0;
             ^
    (see https://errorprone.info/bugpattern/UnusedVariable)
  Did you mean to remove this line?
1 warning
...
BUILD SUCCESSFUL

@bubenheimer
Copy link

Nice!

@cushon
Copy link
Collaborator

cushon commented May 21, 2020

Does using JDK 11 solve the problem you're seeing? I didn't try getting it working with Android Studio, just command line gradle.

@bubenheimer
Copy link

It may be possible to do Android builds with JDK 11, but it would be hardly supported from the Android team's side right now, so chances are it would be a head-splitting migraine to use for real work. Android Studio comes with OpenJDK 8, that is what is officially supported. I'm guessing Android will at some point support JDK 11, but there is no official timeline out. Possible that June 3 will bring some news.

@JakeWharton
Copy link
Contributor

Android Studio is switching to 11 because the platform on which it's based, IntelliJ, switched to only offer 11 in 2020.1. Previously you could run either on 8 or 11. Because AS will solely run on 11, this means the actual build system (usually referred to as AGP, that is, the Android Gradle Plugin) will also need to fully work on JDK 11.

For what it's worth, I'm using JDK 14 for Android builds and it's actually working fine today for the most part. It's third-party tools that sometimes break because of the increasing VM restrictions on reflection. What doesn't work is using a source version higher than 8 because Android builds rely on the bootclasspath which doesn't exist anymore once your source version is 9 or higher. That, too, will be mitigating by switching to a module for at least the framework APIs.

@cushon
Copy link
Collaborator

cushon commented May 21, 2020

Thanks @JakeWharton!

It sounds like using JDK 11 or newer is the way to go.

The javac fix for the underlying issue is unlikely to get backported to earlier versions at this point, and I don't see any good options for mitigating this in Error Prone.

@cushon cushon closed this as completed May 21, 2020
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

7 participants