Skip to content

Commit 446d7d5

Browse files
committed
8294051: [lworld] runtime/AccModule/ConstModule.java fails with incorrect error message
Reviewed-by: dsimms
1 parent c3bad8f commit 446d7d5

File tree

3 files changed

+31
-48
lines changed

3 files changed

+31
-48
lines changed

src/hotspot/share/classfile/classFileParser.cpp

Lines changed: 30 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -3063,15 +3063,15 @@ u2 ClassFileParser::parse_classfile_inner_classes_attribute(const ClassFileStrea
30633063
"Class is both outer and inner class in class file %s", CHECK_0);
30643064
}
30653065

3066-
u2 recognized_modifiers = RECOGNIZED_INNER_CLASS_MODIFIERS;
3066+
// Access flags
3067+
u2 flags;
30673068
// JVM_ACC_MODULE is defined in JDK-9 and later.
30683069
if (_major_version >= JAVA_9_VERSION) {
3069-
recognized_modifiers |= JVM_ACC_MODULE;
3070+
flags = cfs->get_u2_fast() & (RECOGNIZED_INNER_CLASS_MODIFIERS | JVM_ACC_MODULE);
3071+
} else {
3072+
flags = cfs->get_u2_fast() & RECOGNIZED_INNER_CLASS_MODIFIERS;
30703073
}
30713074

3072-
// Access flags
3073-
u2 flags = cfs->get_u2_fast() & recognized_modifiers;
3074-
30753075
if ((flags & JVM_ACC_INTERFACE) && _major_version < JAVA_6_VERSION) {
30763076
// Set abstract bit for old class files for backward compatibility
30773077
flags |= JVM_ACC_ABSTRACT;
@@ -3085,8 +3085,7 @@ u2 ClassFileParser::parse_classfile_inner_classes_attribute(const ClassFileStrea
30853085
}
30863086
}
30873087

3088-
const char* name = inner_name_index == 0 ? "unnamed" : cp->symbol_at(inner_name_index)->as_utf8();
3089-
verify_legal_class_modifiers(flags, name, false, CHECK_0);
3088+
verify_legal_class_modifiers(flags, CHECK_0);
30903089
AccessFlags inner_access_flags(flags);
30913090

30923091
inner_classes->at_put(index++, inner_class_info_index);
@@ -4427,9 +4426,8 @@ static void check_illegal_static_method(const InstanceKlass* this_klass, TRAPS)
44274426

44284427
// utility methods for format checking
44294428

4430-
void ClassFileParser::verify_legal_class_modifiers(jint flags, const char* name, bool is_Object, TRAPS) const {
4429+
void ClassFileParser::verify_legal_class_modifiers(jint flags, TRAPS) const {
44314430
const bool is_module = (flags & JVM_ACC_MODULE) != 0;
4432-
const bool is_inner_class = name != nullptr;
44334431
assert(_major_version >= JAVA_9_VERSION || !is_module, "JVM_ACC_MODULE should not be set");
44344432
if (is_module) {
44354433
ResourceMark rm(THREAD);
@@ -4464,24 +4462,13 @@ void ClassFileParser::verify_legal_class_modifiers(jint flags, const char* name,
44644462
if (!valid_value_class) {
44654463
class_note = " (a value class must be final or else abstract)";
44664464
}
4467-
if (name == nullptr) { // Not an inner class
4468-
Exceptions::fthrow(
4469-
THREAD_AND_LOCATION,
4470-
vmSymbols::java_lang_ClassFormatError(),
4471-
"Illegal class modifiers in class %s%s: 0x%X",
4472-
_class_name->as_C_string(), class_note, flags
4473-
);
4474-
return;
4475-
} else {
4476-
// Names are all known to be < 64k so we know this formatted message is not excessively large.
4477-
Exceptions::fthrow(
4478-
THREAD_AND_LOCATION,
4479-
vmSymbols::java_lang_ClassFormatError(),
4480-
"Illegal class modifiers in declaration of inner class %s%s of class %s: 0x%X",
4481-
name, class_note, _class_name->as_C_string(), flags
4482-
);
4483-
return;
4484-
}
4465+
Exceptions::fthrow(
4466+
THREAD_AND_LOCATION,
4467+
vmSymbols::java_lang_ClassFormatError(),
4468+
"Illegal class modifiers in class %s%s: 0x%X",
4469+
_class_name->as_C_string(), class_note, flags
4470+
);
4471+
return;
44854472
}
44864473
}
44874474

@@ -5793,15 +5780,15 @@ void ClassFileParser::parse_stream(const ClassFileStream* const stream,
57935780
// ACCESS FLAGS
57945781
stream->guarantee_more(8, CHECK); // flags, this_class, super_class, infs_len
57955782

5796-
u2 recognized_modifiers = JVM_RECOGNIZED_CLASS_MODIFIERS;
5783+
// Access flags
5784+
u2 flags;
57975785
// JVM_ACC_MODULE is defined in JDK-9 and later.
57985786
if (_major_version >= JAVA_9_VERSION) {
5799-
recognized_modifiers |= JVM_ACC_MODULE;
5787+
flags = stream->get_u2_fast() & (JVM_RECOGNIZED_CLASS_MODIFIERS | JVM_ACC_MODULE);
5788+
} else {
5789+
flags = stream->get_u2_fast() & JVM_RECOGNIZED_CLASS_MODIFIERS;
58005790
}
58015791

5802-
// Access flags
5803-
u2 flags = stream->get_u2_fast() & recognized_modifiers;
5804-
58055792
if ((flags & JVM_ACC_INTERFACE) && _major_version < JAVA_6_VERSION) {
58065793
// Set abstract bit for old class files for backward compatibility
58075794
flags |= JVM_ACC_ABSTRACT;
@@ -5816,6 +5803,17 @@ void ClassFileParser::parse_stream(const ClassFileStream* const stream,
58165803
}
58175804
}
58185805

5806+
verify_legal_class_modifiers(flags, CHECK);
5807+
5808+
short bad_constant = class_bad_constant_seen();
5809+
if (bad_constant != 0) {
5810+
// Do not throw CFE until after the access_flags are checked because if
5811+
// ACC_MODULE is set in the access flags, then NCDFE must be thrown, not CFE.
5812+
classfile_parse_error("Unknown constant tag %u in class file %s", bad_constant, THREAD);
5813+
return;
5814+
}
5815+
5816+
_access_flags.set_flags(flags);
58195817

58205818
// This class and superclass
58215819
_this_class_index = stream->get_u2_fast();
@@ -5828,20 +5826,6 @@ void ClassFileParser::parse_stream(const ClassFileStream* const stream,
58285826
Symbol* const class_name_in_cp = cp->klass_name_at(_this_class_index);
58295827
assert(class_name_in_cp != nullptr, "class_name can't be null");
58305828

5831-
bool is_java_lang_Object = class_name_in_cp == vmSymbols::java_lang_Object();
5832-
5833-
verify_legal_class_modifiers(flags, nullptr, is_java_lang_Object, CHECK);
5834-
5835-
_access_flags.set_flags(flags);
5836-
5837-
short bad_constant = class_bad_constant_seen();
5838-
if (bad_constant != 0) {
5839-
// Do not throw CFE until after the access_flags are checked because if
5840-
// ACC_MODULE is set in the access flags, then NCDFE must be thrown, not CFE.
5841-
classfile_parse_error("Unknown constant tag %u in class file %s", bad_constant, THREAD);
5842-
return;
5843-
}
5844-
58455829
// Don't need to check whether this class name is legal or not.
58465830
// It has been checked when constant pool is parsed.
58475831
// However, make sure it is not an array type.

src/hotspot/share/classfile/classFileParser.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -464,7 +464,7 @@ class ClassFileParser {
464464

465465
void verify_class_version(u2 major, u2 minor, Symbol* class_name, TRAPS);
466466

467-
void verify_legal_class_modifiers(jint flags, const char* name, bool is_Object, TRAPS) const;
467+
void verify_legal_class_modifiers(jint flags, TRAPS) const;
468468
void verify_legal_field_modifiers(jint flags,
469469
AccessFlags class_access_flags,
470470
TRAPS) const;

test/hotspot/jtreg/ProblemList.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,6 @@ containers/docker/TestJcmdWithSideCar.java 8341518 linux-x64
135135

136136

137137
# Valhalla
138-
runtime/AccModule/ConstModule.java 8294051 generic-all
139138
runtime/valhalla/inlinetypes/CircularityTest.java 8349037 generic-all
140139
runtime/valhalla/inlinetypes/classloading/ConcurrentClassLoadingTest.java 8367412 linux-aarch64
141140
runtime/valhalla/inlinetypes/verifier/StrictInstanceFieldsTest.java CODETOOLS-7904031 generic-all

0 commit comments

Comments
 (0)