8171194: Exception "Duplicate field name&signature in class file" should report the name and signature of the field
authorshshahma
Tue, 28 Feb 2017 20:32:06 -0800
changeset 46301 57f01b1bd33c
parent 46300 b8c77e61e99e
child 46303 9cb271e01558
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
hotspot/src/share/vm/classfile/classFileError.cpp
hotspot/src/share/vm/classfile/classFileParser.cpp
hotspot/src/share/vm/classfile/classFileParser.hpp
--- a/hotspot/src/share/vm/classfile/classFileError.cpp	Wed Mar 01 14:59:36 2017 -0800
+++ b/hotspot/src/share/vm/classfile/classFileError.cpp	Tue Feb 28 20:32:06 2017 -0800
@@ -68,6 +68,16 @@
                      msg, index, name, _class_name->as_C_string());
 }
 
+void ClassFileParser::classfile_parse_error(const char* msg,
+                                            const char* name,
+                                            const char* signature,
+                                            TRAPS) const {
+  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/hotspot/src/share/vm/classfile/classFileParser.cpp	Wed Mar 01 14:59:36 2017 -0800
+++ b/hotspot/src/share/vm/classfile/classFileParser.cpp	Tue Feb 28 20:32:06 2017 -0800
@@ -863,11 +863,12 @@
                                                                  HASH_ROW_SIZE);
     initialize_hashtable(interface_names);
     bool dup = false;
+    const Symbol* name = NULL;
     {
       debug_only(NoSafepointVerifier nsv;)
       for (index = 0; index < itfs_len; index++) {
         const Klass* const k = _local_interfaces->at(index);
-        const Symbol* const 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;
@@ -876,7 +877,8 @@
       }
     }
     if (dup) {
-      classfile_parse_error("Duplicate interface name in class file %s", CHECK);
+      classfile_parse_error("Duplicate interface name \"%s\" in class file %s",
+                             name->as_C_string(), CHECK);
     }
   }
 }
@@ -1628,11 +1630,13 @@
       THREAD, NameSigHash*, HASH_ROW_SIZE);
     initialize_hashtable(names_and_sigs);
     bool dup = false;
+    const Symbol* name = NULL;
+    const Symbol* sig = NULL;
     {
       debug_only(NoSafepointVerifier nsv;)
       for (AllFieldStream fs(_fields, cp); !fs.done(); fs.next()) {
-        const Symbol* const name = fs.name();
-        const Symbol* const 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;
@@ -1641,8 +1645,8 @@
       }
     }
     if (dup) {
-      classfile_parse_error("Duplicate field name&signature in class file %s",
-                            CHECK);
+      classfile_parse_error("Duplicate field name \"%s\" with signature \"%s\" in class file %s",
+                             name->as_C_string(), sig->as_klass_external_name(), CHECK);
     }
   }
 }
@@ -2884,20 +2888,24 @@
         THREAD, NameSigHash*, HASH_ROW_SIZE);
       initialize_hashtable(names_and_sigs);
       bool dup = false;
+      const Symbol* name = NULL;
+      const Symbol* sig = NULL;
       {
         debug_only(NoSafepointVerifier nsv;)
         for (int i = 0; i < length; i++) {
           const Method* const 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);
+        classfile_parse_error("Duplicate method name \"%s\" with signature \"%s\" in class file %s",
+                               name->as_C_string(), sig->as_klass_external_name(), CHECK);
       }
     }
   }
--- a/hotspot/src/share/vm/classfile/classFileParser.hpp	Wed Mar 01 14:59:36 2017 -0800
+++ b/hotspot/src/share/vm/classfile/classFileParser.hpp	Tue Feb 28 20:32:06 2017 -0800
@@ -301,6 +301,10 @@
                              int index,
                              const char *name,
                              TRAPS) const;
+  void classfile_parse_error(const char* msg,
+                             const char* name,
+                             const char* signature,
+                             TRAPS) const;
 
   inline void guarantee_property(bool b, const char* msg, TRAPS) const {
     if (!b) { classfile_parse_error(msg, CHECK); }