简体   繁体   中英

How can a stacktrace show an NPE from code that can't throw an NPE?

Given code that hasn't been touched for two years, and that never saw such a problem before, is there any explanation for this stack trace:

at java.lang.Thread.run(Thread.java:818)\nCaused by: java.lang.NullPointerException
at xxx.Whatever.foo(Whatever.java:1195)
at xxx.Whatever.bar(Whatever.java:1182)

And line 1182 within that class, in the bar() method:

foo(someArguments)

And line 1195 within that class, in the foo() method:

 if (typeContainer != null && typeContainer.getEnumConstant() == TypeEnum.SOME_TYPE) 

I do not understand how this NPE stacktrace is possible. That line above can not throw an NPE.

So, are there any reasonable explanations what is going on here?

Note: "of course" the NPE can't be reproduced. When I run the corresponding test against the system that gave that stacktrace (during a functional test 4 weeks ago), there is no NPE, and the test gives the expected result.

It turns out: that specific system that showed this error was running in invalid code load. It looks like the system wasn't updated for many months, and on the other hand small "private" fixes were installed, thus leading to an invalid code level.

Thus the most likely explanation is: that code on the system is missing the check for some reason.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM