NullPointerException in Java with no StackTrace
You are probably using the HotSpot JVM (originally by Sun Microsystems, later bought by Oracle, part of the OpenJDK), which performs a lot of optimization. To get the stack traces back, you need to pass the following option to the JVM:
-XX:-OmitStackTraceInFastThrow
The optimization is that when an exception (typically a NullPointerException
) occurs for the first time, the full stack trace is printed and the JVM remembers the stack trace (or maybe just the location of the code). When that exception occurs often enough, the stack trace is not printed anymore, both to achieve better performance and not to flood the log with identical stack traces.
To see how this is implemented in the HotSpot JVM, grab a copy of it and search for the global variable OmitStackTraceInFastThrow
. Last time I looked at the code (in 2019), it was in the file graphKit.cpp.
NullPointerException with no stack trace
Probably issue with JVM, pass this argument to it in order to have full stack trace:
-XX:-OmitStackTraceInFastThrow
Now, NPE
is there because something out there is null
and you try to call a method from it. Potential candidates are entity
since you call entity.getLocation()
, then entity.getLocation()
, since you call entity.getLocation().getBlock()
, or even object you get when calling entity.getLocation().getBlock().getType()
Check them out too not only lastpos
.
How can an Exception be created/thrown with no stack trace?
Sometimes, especially when it comes to NullPointers (in my experience), the jvm can optimize the creation and casting of exceptions, and the stack trace is lost (or more correctly, never created). I suspect that your issue is not related to certain java libs, but rather the jvm itself.
If you add this argument when starting your jvm-process you will get your stack traces back, if my suspicion is correct.
-XX:-OmitStackTraceInFastThrow
This has been asked before, look here for more details:
- NullPointerException in Java with no StackTrace
- Recurring Exception without a stack trace - how to reset?
Note, that this applies sun/oracle jvm
Java NullPointerException with truncated stacktrace
After long investigation it turned out there is nothing wrong with Spring or rabbitMQ. Root cause was in my own code.
Log attached to question has complete stacktrace, but java truncates stacktraces!
Java 1.5.0 introduced flag OmitStackTraceInFastThrow, enabled by default. This is performance optimization. It removes common part of stacktraces from exceptions.
In my case, I had full stacktrace for first 130 occurences of this exception. Further occurences had stacktrace truncated. Easiest way to get full stacktrace was to restart the application.
See http://jawspeak.com/2010/05/26/hotspot-caused-exceptions-to-lose-their-stack-traces-in-production-and-the-fix/ for details.
why null pointer exception stack trace doesn't show the line where it occured
You can see the NullPointerException
with correct file and line information below in your logcat output, as the "caused by" exception.
Exceptions thrown out from lifecycle callbacks such as Activity
onCreate()
get wrapped in RuntimeException
and what you posted was just the the stacktrace for this wrapper.
Related Topics
Variable Is Accessed Within Inner Class. Needs to Be Declared Final
Webview and Cookies on Android
Getting Java.Net.Sockettimeoutexception: Connection Timed Out in Android
Why Does the Jvm Consume Less Memory Than -Xms Specified
How to Convert a Char Array Back to a String
How to Load Rsa Private Key from File
How to Change JPAnel Inside a Jframe on the Fly
Why Is the String Class Declared Final in Java
Java - When to Use 'This' Keyword
Java - Transparent Jscrollpane
Android/Java -- Post Simple Text to Facebook Wall
Android - Change App Theme on Onclick
How to Convert an Array to a Set in Java
Spring Boot, Spring Data JPA with Multiple Datasources
Uninitialized Variables and Members in Java
Why Can't We Have Static Method in a (Non-Static) Inner Class (Pre-Java 16)