Thu, 20 Apr 2017 04:53:33 -0400
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
1.1 --- a/src/share/vm/classfile/classFileError.cpp Wed Apr 12 09:03:26 2017 -0700 1.2 +++ b/src/share/vm/classfile/classFileError.cpp Thu Apr 20 04:53:33 2017 -0400 1.3 @@ -56,6 +56,13 @@ 1.4 msg, index, name, _class_name->as_C_string()); 1.5 } 1.6 1.7 +void ClassFileParser::classfile_parse_error(const char* msg, const char* name, const char* signature, TRAPS) { 1.8 + assert(_class_name != NULL, "invariant"); 1.9 + ResourceMark rm(THREAD); 1.10 + Exceptions::fthrow(THREAD_AND_LOCATION, vmSymbols::java_lang_ClassFormatError(), 1.11 + msg, name, signature, _class_name->as_C_string()); 1.12 +} 1.13 + 1.14 PRAGMA_DIAG_POP 1.15 1.16 void StackMapStream::stackmap_format_error(const char* msg, TRAPS) {
2.1 --- a/src/share/vm/classfile/classFileParser.cpp Wed Apr 12 09:03:26 2017 -0700 2.2 +++ b/src/share/vm/classfile/classFileParser.cpp Thu Apr 20 04:53:33 2017 -0400 2.3 @@ -821,11 +821,12 @@ 2.4 THREAD, NameSigHash*, HASH_ROW_SIZE); 2.5 initialize_hashtable(interface_names); 2.6 bool dup = false; 2.7 + Symbol* name = NULL; 2.8 { 2.9 debug_only(No_Safepoint_Verifier nsv;) 2.10 for (index = 0; index < length; index++) { 2.11 Klass* k = _local_interfaces->at(index); 2.12 - Symbol* name = InstanceKlass::cast(k)->name(); 2.13 + name = InstanceKlass::cast(k)->name(); 2.14 // If no duplicates, add (name, NULL) in hashtable interface_names. 2.15 if (!put_after_lookup(name, NULL, interface_names)) { 2.16 dup = true; 2.17 @@ -834,7 +835,8 @@ 2.18 } 2.19 } 2.20 if (dup) { 2.21 - classfile_parse_error("Duplicate interface name in class file %s", CHECK_NULL); 2.22 + classfile_parse_error("Duplicate interface name \"%s\" in class file %s", 2.23 + name->as_C_string(), CHECK_NULL); 2.24 } 2.25 } 2.26 return _local_interfaces; 2.27 @@ -1279,11 +1281,13 @@ 2.28 THREAD, NameSigHash*, HASH_ROW_SIZE); 2.29 initialize_hashtable(names_and_sigs); 2.30 bool dup = false; 2.31 + Symbol* name = NULL; 2.32 + Symbol* sig = NULL; 2.33 { 2.34 debug_only(No_Safepoint_Verifier nsv;) 2.35 for (AllFieldStream fs(fields, _cp); !fs.done(); fs.next()) { 2.36 - Symbol* name = fs.name(); 2.37 - Symbol* sig = fs.signature(); 2.38 + name = fs.name(); 2.39 + sig = fs.signature(); 2.40 // If no duplicates, add name/signature in hashtable names_and_sigs. 2.41 if (!put_after_lookup(name, sig, names_and_sigs)) { 2.42 dup = true; 2.43 @@ -1292,8 +1296,8 @@ 2.44 } 2.45 } 2.46 if (dup) { 2.47 - classfile_parse_error("Duplicate field name&signature in class file %s", 2.48 - CHECK_NULL); 2.49 + classfile_parse_error("Duplicate field name \"%s\" with signature \"%s\" in class file %s", 2.50 + name->as_C_string(), sig->as_klass_external_name(), CHECK_NULL); 2.51 } 2.52 } 2.53 2.54 @@ -2580,20 +2584,24 @@ 2.55 THREAD, NameSigHash*, HASH_ROW_SIZE); 2.56 initialize_hashtable(names_and_sigs); 2.57 bool dup = false; 2.58 + Symbol* name = NULL; 2.59 + Symbol* sig = NULL; 2.60 { 2.61 debug_only(No_Safepoint_Verifier nsv;) 2.62 for (int i = 0; i < length; i++) { 2.63 Method* m = _methods->at(i); 2.64 + name = m->name(); 2.65 + sig = m->signature(); 2.66 // If no duplicates, add name/signature in hashtable names_and_sigs. 2.67 - if (!put_after_lookup(m->name(), m->signature(), names_and_sigs)) { 2.68 + if (!put_after_lookup(name, sig, names_and_sigs)) { 2.69 dup = true; 2.70 break; 2.71 } 2.72 } 2.73 } 2.74 if (dup) { 2.75 - classfile_parse_error("Duplicate method name&signature in class file %s", 2.76 - CHECK_NULL); 2.77 + classfile_parse_error("Duplicate method name \"%s\" with signature \"%s\" in class file %s", 2.78 + name->as_C_string(), sig->as_klass_external_name(), CHECK_NULL); 2.79 } 2.80 } 2.81 }
3.1 --- a/src/share/vm/classfile/classFileParser.hpp Wed Apr 12 09:03:26 2017 -0700 3.2 +++ b/src/share/vm/classfile/classFileParser.hpp Thu Apr 20 04:53:33 2017 -0400 3.3 @@ -314,6 +314,7 @@ 3.4 void classfile_parse_error(const char* msg, int index, TRAPS); 3.5 void classfile_parse_error(const char* msg, const char *name, TRAPS); 3.6 void classfile_parse_error(const char* msg, int index, const char *name, TRAPS); 3.7 + void classfile_parse_error(const char* msg, const char* name, const char* signature, TRAPS); 3.8 inline void guarantee_property(bool b, const char* msg, TRAPS) { 3.9 if (!b) { classfile_parse_error(msg, CHECK); } 3.10 }