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

All the posts and topics that contain only an error report will be moved here after the error is corrected. This is to ensure that when users view a question in ETS Viewer, the "Discuss" button will not indicate the presence of a discussion that adds no value to the question.

Moderators: Site Manager, fjwalraven

Post Reply
musharosky
Posts: 1
Joined: Thu May 15, 2014 10:47 am
Contact:

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

Post 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?

admin
Site Admin
Posts: 10388
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

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

Post 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.

Post Reply

Who is online

Users browsing this forum: No registered users and 5 guests