?
Solved

Why is page erroring?

Posted on 2004-03-24
3
Medium Priority
?
177 Views
Last Modified: 2011-04-14
This works:
////////////////////////////////////////////////////////////////////

if(strReferer == null){}

// is ok to continue
if (strReferer.indexOf("brocade.com") != -1) {}

///////////////////////////////////////////////////////////////////

This errors

////////////////////////////////////////////////////////////////////


// is ok to continue
if ((strReferer.indexOf("brocade.com") != -1)&&(strReferer != null)) {}

////////////////////////////////////////////////////////////////////
why?
0
Comment
Question by:894359
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 18

Expert Comment

by:bobbit31
ID: 10672580
short circuit checks in the wrong order:

if ((strReferer != null) && (strReferer.indexOf("brocade.com") != -1) {}

0
 
LVL 18

Accepted Solution

by:
bobbit31 earned 2000 total points
ID: 10672587
oops:

if ((strReferer != null) && (strReferer.indexOf("brocade.com") != -1)) {}

basically, the && operator is a short-circuit operator... what that means is it first checks the first condition (strReferer != null) if this is false, the conditional automatically returns false (b/c we don't care what the second condition is.

in your example... if strReferer is null and you try strReferer.indexOf, you'll get a nullPointerException b/c strReferer is null
0
 

Author Comment

by:894359
ID: 10672668
Thanks.. didn't know that! :) Do now!
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In the absence of a fully-fledged GPO Management product like AGPM, the script in this article will provide you with a simple way to watch the domain (or a select OU) for GPOs changes and automatically take backups when policies are added, removed o…
What's worse than having your data encrypted by ransomware? Getting attacked by a so-called "wiper," which simply destroys the data and offers you no hope of ever seeing it again.
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
Suggested Courses

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question