I have a condition ifthat evaluates an email address. I am testing 2 things
- It has an @ sign
- After the first @, it ends in "gmail.com".
My understanding of short circuiting is that if the first condition in the OR (||) operator is true, then the second will not be evaluated. And yet I get NullPointerExceptionit because the second statement gets the grade (I tested it).
What I do not understand about the short circuit here?
The corresponding code is given below:
FYI: emailtext is an EditText element, in which case it is "notavalidemail"
String[] split = emailtext.split("@", 2);
final AlertDialog.Builder notifier = new AlertDialog.Builder(this);
Log.i("GetToken","Split[0]=" + split[0] + "; length=" + split.length);
if (split.length == 1 || !split[1].equals("gmail.com")) {
}
Entering the code returns the following:
05-02 13:51:16.447 27553-27553/com.farmsoft.lunchguru.app I/GetToken﹕ Split[0]=notavalidemail; length=1
Scott source
share