About Question enthuware.ocajp.i.v7.2.1342 :
Posted: Thu May 15, 2014 10:51 am
I have a question with option 4:
if ( (str == null) || (i == str.length() ) )
Imagine the following scenario:
Now let's say that string is some non-threadsafe variable and after executing the first part of the if-statement (str == null, which is false) another thread modifies the variable str and sets it to null, the original thread continues evaluating the if-statement and it fails with a NPE because the other thread has set the str to null?
if ( (str == null) || (i == str.length() ) )
Imagine the following scenario:
Code: Select all
String str = "something";
if ( (str == null) || (i == str.length() ) )