Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Studio nullability annoying warning

The problem:

@Nullable
private View view;

public doSomethingWithView() {
   checkNotNull(view); //<- this throws NPE if parameter is null
   view.showWarningAboutIssue(); //<- IDE reports about possible null here
}

Is there a way to configure the IDE, so that it doesn't report for a possible NPE on the second line?

UPDATE: I'm using Dagger checkNotNull method which is identical to Guava ones. If I change import from Dagger to Guava my IDE removes the warning.

UPDATE #2 With latest update of Android studio I can not reproduce it anymore

like image 782
Eugen Martynov Avatar asked Sep 06 '26 01:09

Eugen Martynov


1 Answers

You need to add the following comment before view.showWarningAboutIssue() statement:

//noinspection ConstantConditions

This can also be performed by the GUI : Alt+Enter (or "bubblelight" menu), then choose Assert view!=null and then Suppress for statement:

enter image description here

like image 79
DenisGL Avatar answered Sep 08 '26 05:09

DenisGL



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!