3

I'm using annotations library supported by Android. It is useful for checking NullpointerExceptions. But, it also annoying if I checked the variable if it is null.

In this case:

@Nullable
String value;

boolean isValid(String target) {
    return (target != null && target.length() > 0);
}

void test() {
    if (isValid(value)) {
        Log.d("TEST", value);
        // Do something.
    }
}

In above code, I already checked if 'value' is null, but still got the warning of "It maybe produce NullPointerException".

Is there some annotations that I checked null-type in this function?

Sohyun Ahn
  • 240
  • 2
  • 9

2 Answers2

2

You can use the annotation:

@SuppressWarnings("ConstantConditions")
Xenolion
  • 12,035
  • 7
  • 33
  • 48
1

In android studio Go to

file-->other settings---> default settings (defaultpreference)--->inspections--->java---> @notnull and nullable Probelms

uncheck it and click ok.

sasikumar
  • 12,540
  • 3
  • 28
  • 48