changeset 8401:4c3cae5323bb

8171194: Exception "Duplicate field name&signature in class file" should report the name and signature of the field Summary: Added code to emit name and signature of duplicate field in java.lang.ClassFormatError exception message Reviewed-by: dholmes, coleenp
author shshahma
date Thu, 20 Apr 2017 04:53:33 -0400
parents 857e77fd668d
children 654eaca01d61
files src/share/vm/classfile/classFileError.cpp src/share/vm/classfile/classFileParser.cpp src/share/vm/classfile/classFileParser.hpp
diffstat 3 files changed, 25 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/src/share/vm/classfile/classFileError.cpp	Wed Apr 12 09:03:26 2017 -0700
+++ b/src/share/vm/classfile/classFileError.cpp	Thu Apr 20 04:53:33 2017 -0400
@@ -56,6 +56,13 @@
                        msg, index, name, _class_name->as_C_string());
 }
 
+void ClassFileParser::classfile_parse_error(const char* msg, const char* name, const char* signature, TRAPS) {
+  assert(_class_name != NULL, "invariant");
+  ResourceMark rm(THREAD);
+  Exceptions::fthrow(THREAD_AND_LOCATION, vmSymbols::java_lang_ClassFormatError(),
+                     msg, name, signature, _class_name->as_C_string());
+}
+
 PRAGMA_DIAG_POP
 
 void StackMapStream::stackmap_format_error(const char* msg, TRAPS) {
--- a/src/share/vm/classfile/classFileParser.cpp	Wed Apr 12 09:03:26 2017 -0700
+++ b/src/share/vm/classfile/classFileParser.cpp	Thu Apr 20 04:53:33 2017 -0400
@@ -821,11 +821,12 @@
       THREAD, NameSigHash*, HASH_ROW_SIZE);
     initialize_hashtable(interface_names);
     bool dup = false;
+    Symbol* name = NULL;
     {
       debug_only(No_Safepoint_Verifier nsv;)
       for (index = 0; index < length; index++) {
         Klass* k = _local_interfaces->at(index);
-        Symbol* name = InstanceKlass::cast(k)->name();
+        name = InstanceKlass::cast(k)->name();
         // If no duplicates, add (name, NULL) in hashtable interface_names.
         if (!put_after_lookup(name, NULL, interface_names)) {
           dup = true;
@@ -834,7 +835,8 @@
       }
     }
     if (dup) {
-      classfile_parse_error("Duplicate interface name in class file %s", CHECK_NULL);
+      classfile_parse_error("Duplicate interface name \"%s\" in class file %s",
+               name->as_C_string(), CHECK_NULL);
     }
   }
   return _local_interfaces;
@@ -1279,11 +1281,13 @@
       THREAD, NameSigHash*, HASH_ROW_SIZE);
     initialize_hashtable(names_and_sigs);
     bool dup = false;
+    Symbol* name = NULL;
+    Symbol* sig = NULL;
     {
       debug_only(No_Safepoint_Verifier nsv;)
       for (AllFieldStream fs(fields, _cp); !fs.done(); fs.next()) {
-        Symbol* name = fs.name();
-        Symbol* sig = fs.signature();
+        name = fs.name();
+        sig = fs.signature();
         // If no duplicates, add name/signature in hashtable names_and_sigs.
         if (!put_after_lookup(name, sig, names_and_sigs)) {
           dup = true;
@@ -1292,8 +1296,8 @@
       }
     }
     if (dup) {
-      classfile_parse_error("Duplicate field name&signature in class file %s",
-                            CHECK_NULL);
+      classfile_parse_error("Duplicate field name \"%s\" with signature \"%s\" in class file %s",
+                             name->as_C_string(), sig->as_klass_external_name(), CHECK_NULL);
     }
   }
 
@@ -2580,20 +2584,24 @@
         THREAD, NameSigHash*, HASH_ROW_SIZE);
       initialize_hashtable(names_and_sigs);
       bool dup = false;
+      Symbol* name = NULL;
+      Symbol* sig = NULL;
       {
         debug_only(No_Safepoint_Verifier nsv;)
         for (int i = 0; i < length; i++) {
           Method* m = _methods->at(i);
+          name = m->name();
+          sig = m->signature();
           // If no duplicates, add name/signature in hashtable names_and_sigs.
-          if (!put_after_lookup(m->name(), m->signature(), names_and_sigs)) {
+          if (!put_after_lookup(name, sig, names_and_sigs)) {
             dup = true;
             break;
           }
         }
       }
       if (dup) {
-        classfile_parse_error("Duplicate method name&signature in class file %s",
-                              CHECK_NULL);
+        classfile_parse_error("Duplicate method name \"%s\" with signature \"%s\" in class file %s",
+                              name->as_C_string(), sig->as_klass_external_name(), CHECK_NULL);
       }
     }
   }
--- a/src/share/vm/classfile/classFileParser.hpp	Wed Apr 12 09:03:26 2017 -0700
+++ b/src/share/vm/classfile/classFileParser.hpp	Thu Apr 20 04:53:33 2017 -0400
@@ -314,6 +314,7 @@
   void classfile_parse_error(const char* msg, int index, TRAPS);
   void classfile_parse_error(const char* msg, const char *name, TRAPS);
   void classfile_parse_error(const char* msg, int index, const char *name, TRAPS);
+  void classfile_parse_error(const char* msg, const char* name, const char* signature, TRAPS);
   inline void guarantee_property(bool b, const char* msg, TRAPS) {
     if (!b) { classfile_parse_error(msg, CHECK); }
   }