Solved

Why is page erroring?

Posted on 2004-03-24
3
165 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
  • 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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
jquery form plugin 4 152
How to write service layer in Spring ? 4 273
form submissions on a web page 2 142
caughtSpeeding java challenge 16 132
In this article, I show you step by step with screenshots to assist you - HOW TO: Deploy and Install the VMware vCenter Server Appliance 6.5 (VCSA 6.5), with some helpful tips along the way.
Find out what the Office 365 disclaimer function is, why you would use it and its limited ability to create Office 365 signatures.
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

747 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now