uber / NullAway

A tool to help eliminate NullPointerExceptions (NPEs) in your Java code with low build-time overhead
MIT License
3.63k stars 293 forks source link

Android : Build did not fail due to Null Derefence. #891

Closed AbhishekIIScPhD closed 8 months ago

AbhishekIIScPhD commented 9 months ago

I am working with android application sample-app in the master branch of the repository. Issue : Build does not fail due to possible Null Dereference in the application

Android : I un-commented the code in MainActivity.java under sample-app.

I execute > ./gradlew :sample-app:build but, does not throw any error with the following code fragment.

Code Fragment:

` Object x = null;

x.hashCode();

checkModel(null);

}

static int checkModel(@NonNull String s) {`

Furthermore, I also built the Java application in the repository. Java : I made changes to the code in MyClass.java under sample.

When I execute > ./gradlew :sample:build and throws a build error for the following code fragment.

Code Fragment:

`static void log(@Nullable Object x) {

if (x == null) {

  return;

}

System.out.println(x.toString());

checkMoodel(null);

}

static int checkModel(@NonNull String s)`

Output :

Task :sample:compileJava FAILED /data/data1/abhisheku/NullAway/sample/src/main/java/com/uber/mylib/MyClass.java:15: error: [NullAway] passing @Nullable parameter 'null' where @NonNull is required checkModel(null); ^ (see http://t.uber.com/nullaway ) 1 error

Please address the build script changes, if any for the Android application.

msridhar commented 9 months ago

Thanks for the report. I think the issue is that the Gradle Errorprone Plugin no longer supports Android:

https://github.com/tbroyer/gradle-errorprone-plugin/discussions/91

I wonder if things would work with a 2.x version of the Gradle Errorprone Plugin, which also might require using an older version of the Android Gradle Plugin. @AbhishekIIScPhD any chance you could test out older versions to see what happens?

Alternately we could just try to figure out how to do everything manually with putting Error Prone and NullAway on the processor path and then passing the right compiler arguments to get things to run.

AbhishekIIScPhD commented 9 months ago

@msridhar, you are right. The older version of the plugin, For example 2.0.1 worked on my sample application by breaking the build due to possible null dereferences. Thank you for you time.

msridhar commented 9 months ago

Thanks for confirming. We need to update our instructions for Android.