< prev index next >
src/hotspot/share/prims/jvm.cpp
Print this page
rev 54124 : 8218628: Add detailed message to NullPointerException describing what is null.
*** 35,44 ****
--- 35,45 ----
#include "classfile/stringTable.hpp"
#include "classfile/systemDictionary.hpp"
#include "classfile/vmSymbols.hpp"
#include "gc/shared/collectedHeap.inline.hpp"
#include "interpreter/bytecode.hpp"
+ #include "interpreter/bytecodeUtils.hpp"
#include "jfr/jfrEvents.hpp"
#include "logging/log.hpp"
#include "memory/heapShared.hpp"
#include "memory/oopFactory.hpp"
#include "memory/referenceType.hpp"
*** 532,548 ****
// java.lang.Throwable //////////////////////////////////////////////////////
-
JVM_ENTRY(void, JVM_FillInStackTrace(JNIEnv *env, jobject receiver))
JVMWrapper("JVM_FillInStackTrace");
Handle exception(thread, JNIHandles::resolve_non_null(receiver));
java_lang_Throwable::fill_in_stack_trace(exception);
JVM_END
// java.lang.StackTraceElement //////////////////////////////////////////////
JVM_ENTRY(void, JVM_InitStackTraceElementArray(JNIEnv *env, jobjectArray elements, jobject throwable))
--- 533,593 ----
// java.lang.Throwable //////////////////////////////////////////////////////
JVM_ENTRY(void, JVM_FillInStackTrace(JNIEnv *env, jobject receiver))
JVMWrapper("JVM_FillInStackTrace");
Handle exception(thread, JNIHandles::resolve_non_null(receiver));
java_lang_Throwable::fill_in_stack_trace(exception);
JVM_END
+ // java.lang.NullPointerException ///////////////////////////////////////////
+
+ JVM_ENTRY(jstring, JVM_GetExtendedNPEMessage(JNIEnv *env, jthrowable throwable))
+ oop exc = JNIHandles::resolve_non_null(throwable);
+
+ Method* method;
+ int bci;
+ if (!java_lang_Throwable::get_method_and_bci(exc, &method, &bci)) {
+ return NULL;
+ }
+ if (method->is_native()) {
+ return NULL;
+ }
+
+ ResourceMark rm(THREAD);
+ TrackingStackCreator stc(method, bci);
+ char const* reason;
+ int slot = stc.get_null_pointer_slot(bci, &reason);
+
+ // Build the message.
+ stringStream ss;
+ if (slot == -2) {
+ return NULL;
+ } else if (slot == -1) {
+ ss.print("There cannot be a NullPointerException at bci %d of method %s",
+ bci, method->name_and_sig_as_C_string());
+ } else if (reason == NULL) {
+ ss.print("Cannot get the reason for the NullPointerException at bci %d of method %s",
+ bci, method->name_and_sig_as_C_string());
+ } else {
+ TrackingStackSource source = stc.get_source(bci, slot, 5);
+ if (source.get_type() != TrackingStackSource::INVALID) {
+ const char *msg = source.as_string();
+ if (strncmp("The return value of", msg, strlen("The return value of")) == 0) {
+ ss.print("%s is null. ", msg);
+ } else {
+ ss.print("'%s' is null. ", msg);
+ }
+ }
+ ss.print("%s", reason);
+ }
+
+ oop result = java_lang_String::create_oop_from_str(ss.as_string(), CHECK_0);
+ return (jstring) JNIHandles::make_local(env, result);
+ JVM_END
// java.lang.StackTraceElement //////////////////////////////////////////////
JVM_ENTRY(void, JVM_InitStackTraceElementArray(JNIEnv *env, jobjectArray elements, jobject throwable))
< prev index next >