src/hotspot/share/prims/jvm.cpp
branchJEP-8220715-NPE_messages
changeset 57319 aa400d41ebd6
parent 57272 472db1657c6d
equal deleted inserted replaced
57318:cb67307942f3 57319:aa400d41ebd6
   554   if (method->is_native()) {
   554   if (method->is_native()) {
   555     return NULL;
   555     return NULL;
   556   }
   556   }
   557 
   557 
   558   ResourceMark rm(THREAD);
   558   ResourceMark rm(THREAD);
       
   559 
       
   560   // Analyse the bytecodes.
   559   TrackingStackCreator stc(method, bci);
   561   TrackingStackCreator stc(method, bci);
   560   char const* reason;
   562 
   561   int slot = stc.get_null_pointer_slot(bci, &reason);
   563   // The slot of the operand stack that contains the null reference.
       
   564   int slot = stc.get_NPE_null_slot(bci);
   562 
   565 
   563   // Build the message.
   566   // Build the message.
   564   stringStream ss;
   567   stringStream ss;
   565   if (slot == -2) {
   568   if (slot == -2) {
       
   569     // We don't want to print a message.
   566     return NULL;
   570     return NULL;
   567   } else if (slot == -1) {
   571   } else if (slot == -1) {
   568     ss.print("There cannot be a NullPointerException at bci %d of method %s",
   572     // We encoutered a bytecode that does not dereference a reference.
   569              bci, method->name_and_sig_as_C_string());
   573     DEBUG_ONLY(ss.print("There cannot be a NullPointerException at bci %d of method %s",
   570   } else if (reason == NULL) {
   574                         bci, method->external_name()));
   571     ss.print("Cannot get the reason for the NullPointerException at bci %d of method %s",
   575     NOT_DEBUG(return NULL);
   572              bci, method->name_and_sig_as_C_string());
       
   573   } else {
   576   } else {
   574     TrackingStackSource source = stc.get_source(bci, slot, 5);
   577     // Print a description of what is null.
   575     if (source.get_type() != TrackingStackSource::INVALID) {
   578     stc.print_NPE_cause(&ss, bci, slot);
   576       const char *msg = source.as_string();
   579     // Print string describing which action (bytecode) could not be
   577       if (strncmp("The return value of", msg, strlen("The return value of")) == 0) {
   580     // perfromed because of the null reference.
   578         ss.print("%s is null. ", msg);
   581     stc.print_NPE_failedAction(&ss, bci);
   579       } else {
       
   580         ss.print("'%s' is null. ", msg);
       
   581       }
       
   582     }
       
   583     ss.print("%s", reason);
       
   584   }
   582   }
   585 
   583 
   586   oop result = java_lang_String::create_oop_from_str(ss.as_string(), CHECK_0);
   584   oop result = java_lang_String::create_oop_from_str(ss.as_string(), CHECK_0);
   587   return (jstring) JNIHandles::make_local(env, result);
   585   return (jstring) JNIHandles::make_local(env, result);
   588 JVM_END
   586 JVM_END