java - NullPointerException without referencing any object -
i have piece of code, throws nullpointerexception sometimes. far not interesting. exception occurs in line, not reference object.
try { parser.parse(input);/*line 186*/ } catch(exception e) { //npe happens in next line? throw new saxexception("error parsing document", e);/*line 190*/ } here stacktrace
java.lang.nullpointerexception @ com.tejoe.myxmlparser.parse(myxmlparser.java:190) @ com.tejoe.myxmlparser.parse(myxmlparser.java:168) .... it happened twice in last 3 months , code run @ least hundred thousand times.
i decompiled code, make sure line information correct , yes are.
additional test
there seems special saxexception. did following test:
import org.xml.sax.saxexception; public class test { public static void main(string[] args) throws exception { new saxexception("error", new nullpointerexception()).printstacktrace(); } } i got following output
java.lang.nullpointerexception @ test.main(test.java:7) caused by: java.lang.nullpointerexception ... 1 more solution: saxexception overrides tostring method, return name of cause exception.
now wonder, did not caused output in production environment (aix java)
i wrote following code , generated null pointer exception. came on line 45 follow,
exception in thread "main" java.lang.nullpointerexception @ inheritance.parent.child.main(child.java:45) import org.xml.sax.saxexception; public class child { public static void main(string[] args) throws saxexception { try{ child c1 = null; c1.i=0; } catch(exception e){ throw new saxexception("error", e); //line : 45 } } } the error code proper. need find object getting null.
Comments
Post a Comment