error_prone_core 2.0.6 adds Objects.requireNonNull() to source (which can crash Android)
See original GitHub issueI’ve been using the error-prone compiler for my Android application. java.util.Objects
was only added recently to Android (API 19). The most recent version of error_prone_core (2.0.6) can add Objects.requireNonNull()
to the source, which causes the Android app to crash if run on an older device.
I haven’t been able to track down exactly how this happens; I’m not super familiar with error-prone’s internals.
I’ve been using error-prone via the gradle-errorprone-plugin for Android builds. By default it pulls in the latest error_prone_core for use. As a workaround you can force it to use 2.0.5.
As an aside, the stack traces that result are quite mystifying since the source will contain no references to java.util.Objects
. For example:
Fatal Exception: java.lang.NoClassDefFoundError: java.util.Objects
at com.trello.syncadapter.StarredBoardsSync.execute(StarredBoardsSync.java:66)
at com.trello.syncadapter.StarredBoardsSync.performSync(StarredBoardsSync.java:58)
at com.trello.syncadapter.TSyncAdapter.onPerformSync(TSyncAdapter.java:49)
at android.content.AbstractThreadedSyncAdapter$SyncThread.run(AbstractThreadedSyncAdapter.java:254)
…Where StarredBoardsSync
didn’t even import java.util.Objects
in the original source.
Issue Analytics
- State:
- Created 8 years ago
- Comments:17
Top GitHub Comments
This happens even when not using retrolambda. Specifically this line
https://github.com/google/error-prone-javac/blob/a68a002c508b9b862ab4b966c70aad0a1686d328/src/jdk.compiler/share/classes/com/sun/tools/javac/jvm/Target.java#L126
Will make it so that
Objects.requireNonNull()
is always used when source and target levels are set to 7. This is not a problem when using oracle’s javac because it does not have this check. This makes it so that when using error prone with any android codeabse, if you do not use retrolambda, the app will always crash on api levels below 19.cc @cushon Can we get this fixed in error-prone-javac or consider making this an option?
The fix has been released in 2.0.16.