In java, Does the following line have a possibility (even 0.01%) to throw a NullPointerException??
public static void handleRequest(String str1){
if (str1 == null){ // this line throws NPE, how come !! is it a JDK1.5 bug!!
return null;
}
// other staff
}
Actually I am falling some bug in the code and It says that the exact above line in the method throws a java.lang.NullPointerException ?!
No, that line won’t throw a
NullPointerExceptionunder any circumstances.But it depends what you mean by “similar”. For example, if your actual line of code is
then you’ll get a NullPointerException if
foois null.