From 7122fc6ecc28a5ce1716ac3314edce41c7d33964 Mon Sep 17 00:00:00 2001 From: shshahma Date: Thu, 20 Apr 2017 04:53:33 -0400 Subject: [PATCH] 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 --- src/share/vm/classfile/classFileError.cpp | 7 ++++++ src/share/vm/classfile/classFileParser.cpp | 26 ++++++++++++++-------- src/share/vm/classfile/classFileParser.hpp | 1 + 3 files changed, 25 insertions(+), 9 deletions(-) diff --git a/src/share/vm/classfile/classFileError.cpp b/src/share/vm/classfile/classFileError.cpp index 3c3302fb2..a2ca47930 100644 --- a/src/share/vm/classfile/classFileError.cpp +++ b/src/share/vm/classfile/classFileError.cpp @@ -56,6 +56,13 @@ void ClassFileParser::classfile_parse_error(const char* msg, int index, const ch 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) { diff --git a/src/share/vm/classfile/classFileParser.cpp b/src/share/vm/classfile/classFileParser.cpp index 33a289f9f..59a68f83e 100644 --- a/src/share/vm/classfile/classFileParser.cpp +++ b/src/share/vm/classfile/classFileParser.cpp @@ -821,11 +821,12 @@ Array* ClassFileParser::parse_interfaces(int length, 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 @@ Array* ClassFileParser::parse_interfaces(int length, } } 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 @@ Array* ClassFileParser::parse_fields(Symbol* class_name, 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 @@ Array* ClassFileParser::parse_fields(Symbol* class_name, } } 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 @@ Array* ClassFileParser::parse_methods(bool is_interface, 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); } } } diff --git a/src/share/vm/classfile/classFileParser.hpp b/src/share/vm/classfile/classFileParser.hpp index 74367f5b9..73ccdeb72 100644 --- a/src/share/vm/classfile/classFileParser.hpp +++ b/src/share/vm/classfile/classFileParser.hpp @@ -314,6 +314,7 @@ class ClassFileParser VALUE_OBJ_CLASS_SPEC { 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); } } -- GitLab