Page 1 of 1

About Question enthuware.ocajp.i.v7.2.1342 :

Posted: Thu May 15, 2014 10:51 am
by musharosky
I have a question with option 4:
if ( (str == null) || (i == str.length() ) )

Imagine the following scenario:

Code: Select all

String str = "something";
if ( (str == null) || (i == str.length() ) )
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?

Re: About Question enthuware.ocajp.i.v7.2.1342 :

Posted: Thu May 15, 2014 11:36 am
by admin
You are right. It is possible. The problem statement has now been updated to make it clear that str is a local variable to eliminate the situation you described.

thank you for your feedback!
Paul.