java - Why am I getting a NullPointerException even through a check? -


stack trace:

java.lang.nullpointerexception     @ testslot.isinternetexploreravailable(testslot.java:274)     @ webproxyhtmlrendererbeta.getsingleslothtml(webproxyhtmlrendererbeta.java:168)     // rest irrelevant 

testslot#isinternetexploreravailable()

public boolean isinternetexploreravailable() {   if (currentsession.get("isinternetexploreravailable") != null) // line 274       return (boolean) currentsession.get("isinternetexploreravailable");     return false;   } 

currentsession.get(string key) simple fetcher fetch hashmap<string,object>

...getsingleslothtml()

else if (browsername.contains(browsertype.ie) || browsername.contains(browsertype.iexplore))       if (!s.isinternetexploreravailable()) { // line 168         htmlclass += "browsernotavailable ";         imgsrc = imgsrc.split(".png")[0].concat("_unavailable.png");         title = "browser not available";       } else { htmlclass += "browseravailable "; } 

the questionable thing is, tested same type of logic using sccee:

public class main {      public static void main(string[] args) {         map<string, object> settings = new hashmap<string, object>();          settings.put("something", true);          if (settings.get("something_else") != null)             system.out.println("it's not null");         else             system.out.println("it's null");     } } 

and put out "it's null" means can null check using !=. ideas why wouldn't working me in testslot#isinternetexploreravailablemethod?

the way line

if (currentsession.get("isinternetexploreravailable") != null) // line 274 

throws nullpointerexception if currentsession null. add check first:

if (currentsession != null && currentsession.get("isinternetexploreravailable") != null) // line 274 

Comments

Popular posts from this blog

jQuery Mobile app not scrolling in Firefox -

c++ - How to add Crypto++ library to Qt project -

php array slice every 2th rule -