I have an interface with a method like this:
public interface MyInterface {
void myMethod(@Nonnull String userEmail);
}
The interface has the following implementation:
public class MyInterfaceImpl implements MyInterface {
@Override
public void myMethod(@Nonnull String userEmail) {
if ((userEmail== null) || !userEmail.endsWith("something")) {
throw new SomeException("...");
}
...
}
}
The compiler is raising me a warning saying that Condition 'userEmail == null' is always 'false'
, but that doesn't look right.
As for my understanding, the annotation javax.annotation.Nonnull
will warn the compiler in case someone calls my method with a null
value, but does not prevent the code to compile if someone passes a null value to it. So yes, my code can be called with a null
value at some point:
Note that I get the same warning if I compile on command line with the option -Xlint:all
(so it does not look like just a bug in my IDE).
Does anyone have any idea how can I get rid of this warning and why is it occurring?
Disclaimer: the example I showed is just an example, the actual code does some stuff before to get to that condition, but nothing that can make userEmail == null
always false
(as it's proven by the debugger screenshot that I attached).