< prev index next >

src/hotspot/share/interpreter/linkResolver.cpp

Print this page
rev 59277 : [mq]: v3

@@ -577,28 +577,49 @@
   bool can_access = Reflection::verify_member_access(ref_klass,
                                                      resolved_klass,
                                                      sel_klass,
                                                      flags,
                                                      true, false, CHECK);
-  // Any existing exceptions that may have been thrown, for example LinkageErrors
-  // from nest-host resolution, have been allowed to propagate.
+  // Any existing exceptions that may have been thrown
+  // have been allowed to propagate.
   if (!can_access) {
     ResourceMark rm(THREAD);
+    stringStream ss;
     bool same_module = (sel_klass->module() == ref_klass->module());
-    Exceptions::fthrow(
-      THREAD_AND_LOCATION,
-      vmSymbols::java_lang_IllegalAccessError(),
-      "class %s tried to access %s%s%smethod '%s' (%s%s%s)",
+    ss.print("class %s tried to access %s%s%smethod '%s' (%s%s%s)",
       ref_klass->external_name(),
       sel_method->is_abstract()  ? "abstract "  : "",
       sel_method->is_protected() ? "protected " : "",
       sel_method->is_private()   ? "private "   : "",
       sel_method->external_name(),
       (same_module) ? ref_klass->joint_in_module_of_loader(sel_klass) : ref_klass->class_in_module_of_loader(),
       (same_module) ? "" : "; ",
       (same_module) ? "" : sel_klass->class_in_module_of_loader()
     );
+
+    // For private access check if there was a problem with nest host
+    // resolution, and if so report that as part of the message.
+    if (sel_method->is_private()) {
+      assert(ref_klass->is_instance_klass(), "must be");
+      assert(sel_klass->is_instance_klass(), "must be");
+      InstanceKlass* ref_ik = InstanceKlass::cast(ref_klass);
+      InstanceKlass* sel_ik = InstanceKlass::cast(sel_klass);
+      const char* nest_host_error_1 = ref_ik->nest_host_resolution_error();
+      const char* nest_host_error_2 = sel_ik->nest_host_resolution_error();
+      if (nest_host_error_1 != NULL || nest_host_error_2 != NULL) {
+        ss.print(", (%s%s%s)",
+                 (nest_host_error_1 != NULL) ? nest_host_error_1 : "",
+                 (nest_host_error_1 != NULL && nest_host_error_2 != NULL) ? ", " : "",
+                 (nest_host_error_2 != NULL) ? nest_host_error_2 : "");
+      }
+    }
+
+    Exceptions::fthrow(THREAD_AND_LOCATION,
+                       vmSymbols::java_lang_IllegalAccessError(),
+                       "%s",
+                       ss.as_string()
+                       );
     return;
   }
 }
 
 Method* LinkResolver::resolve_method_statically(Bytecodes::Code code,

@@ -913,23 +934,42 @@
   // Any existing exceptions that may have been thrown, for example LinkageErrors
   // from nest-host resolution, have been allowed to propagate.
   if (!can_access) {
     bool same_module = (sel_klass->module() == ref_klass->module());
     ResourceMark rm(THREAD);
-    Exceptions::fthrow(
-      THREAD_AND_LOCATION,
-      vmSymbols::java_lang_IllegalAccessError(),
-      "class %s tried to access %s%sfield %s.%s (%s%s%s)",
+    stringStream ss;
+    ss.print("class %s tried to access %s%sfield %s.%s (%s%s%s)",
       ref_klass->external_name(),
       fd.is_protected() ? "protected " : "",
       fd.is_private()   ? "private "   : "",
       sel_klass->external_name(),
       fd.name()->as_C_string(),
       (same_module) ? ref_klass->joint_in_module_of_loader(sel_klass) : ref_klass->class_in_module_of_loader(),
       (same_module) ? "" : "; ",
       (same_module) ? "" : sel_klass->class_in_module_of_loader()
     );
+    // For private access check if there was a problem with nest host
+    // resolution, and if so report that as part of the message.
+    if (fd.is_private()) {
+      assert(ref_klass->is_instance_klass(), "must be");
+      assert(sel_klass->is_instance_klass(), "must be");
+      InstanceKlass* ref_ik = InstanceKlass::cast(ref_klass);
+      InstanceKlass* sel_ik = InstanceKlass::cast(sel_klass);
+      const char* nest_host_error_1 = ref_ik->nest_host_resolution_error();
+      const char* nest_host_error_2 = sel_ik->nest_host_resolution_error();
+      if (nest_host_error_1 != NULL || nest_host_error_2 != NULL) {
+        ss.print(", (%s%s%s)",
+                 (nest_host_error_1 != NULL) ? nest_host_error_1 : "",
+                 (nest_host_error_1 != NULL && nest_host_error_2 != NULL) ? ", " : "",
+                 (nest_host_error_2 != NULL) ? nest_host_error_2 : "");
+      }
+    }
+    Exceptions::fthrow(THREAD_AND_LOCATION,
+                       vmSymbols::java_lang_IllegalAccessError(),
+                       "%s",
+                       ss.as_string()
+                       );
     return;
   }
 }
 
 void LinkResolver::resolve_field_access(fieldDescriptor& fd, const constantPoolHandle& pool, int index, const methodHandle& method, Bytecodes::Code byte, TRAPS) {
< prev index next >