2

Let me try to explain..We have a server running Jboss 5.1 with really many concurrent connections, and well, sometimes we need to restart and do some maintenance/release.

The problem is, sometimes we start up the server and it looks like some library just didn't load at startup time, or for some other reason, we keep getting NullPointerException without any stacktrace.. we do know the class it is thrown, but by checking the code, where nullpointers could for some reason be thrown, and even forcing a few exceptions, all of them have at least the stacktrace.

I found here in stackoverflow many answers telling about the JVM doing some optimizations but we have just started up the server.I don't believe it does any optimization even when the first exception is thrown.I have also checked for any relevant setStackTrace or codes like ex.toString()..which we also do not have.

So my question actually is, for what reason other than this optimization thing, could such exception be thrown without stacktrace?

EDIT: My question is NOT related to the -XX:-OmitStackTraceInFastThrow, since it happens even at the first exception!

Bruno Brs
  • 673
  • 1
  • 6
  • 23
  • 3
    how do you know that you are running into a `NPE` if you are not getting a stackstrace? Maybe it´s caught anywhere and or throwmn manually? – SomeJavaGuy Oct 27 '15 at 13:35
  • I dont think JVM optimizations will result in NPE – Kumar Abhinav Oct 27 '15 at 13:39
  • @Kevin Esche, The server log prints the exception name, but not the stacktrace: [CRITICAL] java.lang.NullPointerException, this is all I get in the log. – Bruno Brs Oct 27 '15 at 13:45
  • @Kumar Its not the JVM that causes the NPE, but second to what i read, it could be the reason why the stacktrace is missing - I just dont think it is my case. – Bruno Brs Oct 27 '15 at 13:45
  • 4
    Correction: an exception is not thrown without stacktrace. It is logged without stacktrace. As in, only the message is logged (logger.error(e)). That's just buggy logging logic and it can exist anywhere, including in the thousands of classes that make up a JBoss 5.1 instance. – Gimby Oct 27 '15 at 13:49
  • 1
    I guess you can just surround all your code with try catch statements and when they catch an exception, ex.printStackTrace() – Sweeper Oct 27 '15 at 14:03
  • @Gimby I guess you are right. This NullPointer does not always happen however, it just do when the server clearly didn't started up properly. Or didn't it start up properly because of the NullPointer?! No idea..i can't get the stacktrace... :/ – Bruno Brs Oct 27 '15 at 15:26
  • 1
    I feel your pain, but now wonder what people who do not have access to your server environment can do. – Gimby Oct 27 '15 at 15:30
  • @Gimby Yes i understand, i was just wondering if someone else had similar problem..because all i read on the internet is about the "JVM optimization" issue. I agree however, the problem might be in some inner class. Thanks anyway. – Bruno Brs Oct 27 '15 at 15:43
  • @BrunoBL probably yes, but until you can narrow it down to a particular source nobody can know they're a winner. You're mixing two individual problems here which may or may not directly linked: useless logging and random startup failures. One may simply only become visible because of the other problem, and not have any further correlation. For now I'd let this go and focus on those random deployment failures. Perhaps enabling JBoss trace logging can help. – Gimby Oct 27 '15 at 19:11
  • @the8472 If you at least read my question, you gonna see that my problem is not related to the solution given in that question. – Bruno Brs Oct 28 '15 at 18:42
  • But have you actually *tried* setting that option? because your question reads like you simply *assume* that it's not the issue without actually trying it. In any case, you might want to attach a debugger on startup and set an exception breakpoint. also, something might be throwing a preallocated exception as a form of manual performance optimization. – the8472 Oct 28 '15 at 18:51
  • 1
    Try a [JVMTI agent](https://github.com/odnoklassniki/jvm-serviceability-examples/blob/master/src/demo4/agent/extrace.c) that will trace ALL exceptions, even if they are silently caught. See the [related question](http://stackoverflow.com/questions/23561555/java-exceptions-counter-on-jvm-hotspot). – apangin Oct 28 '15 at 23:15

1 Answers1

-3

Use the -XX:-OmitStackTraceInFastThrow JVM argument.

Brett Kail
  • 33,593
  • 2
  • 85
  • 90