Solved

Why is page erroring?

Posted on 2004-03-24
3
176 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 500 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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

In part one, we reviewed the prerequisites required for installing SQL Server vNext. In this part we will explore how to install Microsoft's SQL Server on Ubuntu 16.04.
Multi-threading long-running processes can have a significant increase in overall performance and drastically decrease over time it takes for a process to complete. Unfortunately, not all applications support native multi-threading, some by design a…
If you're a developer or IT admin, you’re probably tasked with managing multiple websites, servers, applications, and levels of security on a daily basis. While this can be extremely time consuming, it can also be frustrating when systems aren't wor…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

688 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