I usually code stuff like this:
public void myMethod(@NonNull String sName) {
//noinspection ConstantConditions
if (sName == null) {
throw new IllegalArgumentException("Name argument cannot be null");
}
[...]
}
I want Android Studio to preventively warn me about calls to myMethod with null parameters. However, if bad things happen and null is passed to the method, I want a clear stack trace as soon as possible, so I do the null check.
However Android Studio keeps complaining that the check will never be null. That is actually wrong. I have to keep adding //noinspection ConstantConditions to suppress the warning and clutter code.
Is there any better way to do this in java?