提交 7122fc6e 编写于 作者: S shshahma

8171194: Exception "Duplicate field name&signature in class file" should...

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
上级 e0052d8a
......@@ -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) {
......
......@@ -821,11 +821,12 @@ Array<Klass*>* 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<Klass*>* 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<u2>* 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<u2>* 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<Method*>* 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);
}
}
}
......
......@@ -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); }
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册