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

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

Closed
AbhishekIIScPhD opened this issue Jan 10, 2024 · 3 comments · Fixed by #900
Closed

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

AbhishekIIScPhD opened this issue Jan 10, 2024 · 3 comments · Fixed by #900

Comments

@AbhishekIIScPhD
Copy link

AbhishekIIScPhD commented Jan 10, 2024

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
Copy link
Collaborator

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

tbroyer/gradle-errorprone-plugin#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
Copy link
Author

AbhishekIIScPhD commented Jan 11, 2024

@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
Copy link
Collaborator

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

msridhar added a commit that referenced this issue Jan 25, 2024
Fixes #891. It's hard to add a regression test for this, but I manually
tested that with the new configuration, NullAway errors are detected in
the sample app. After this lands, I'd like to update the readme further
to refer to this particular commit, so users can see the changes we
needed to make.
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

Successfully merging a pull request may close this issue.

2 participants