Skip to content

Commit 18d9905

Browse files
author
Harold Seigel
committed
8255342: Remove non-specified JVM checks on Classes with Record attributes
Reviewed-by: dholmes, coleenp
1 parent 7679650 commit 18d9905

File tree

6 files changed

+353
-43
lines changed

6 files changed

+353
-43
lines changed

src/hotspot/share/classfile/classFileParser.cpp

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3900,19 +3900,11 @@ void ClassFileParser::parse_classfile_attributes(const ClassFileStream* const cf
39003900
_nest_host = class_info_index;
39013901
} else if (_major_version >= JAVA_14_VERSION) {
39023902
if (tag == vmSymbols::tag_record()) {
3903-
// Skip over Record attribute if not supported or if super class is
3904-
// not java.lang.Record.
3905-
if (supports_records() &&
3906-
cp->klass_name_at(_super_class_index) == vmSymbols::java_lang_Record()) {
3903+
if (supports_records()) { // Skip over Record attribute if not supported.
39073904
if (parsed_record_attribute) {
39083905
classfile_parse_error("Multiple Record attributes in class file %s", THREAD);
39093906
return;
39103907
}
3911-
// Check that class is final and not abstract.
3912-
if (!_access_flags.is_final() || _access_flags.is_abstract()) {
3913-
classfile_parse_error("Record attribute in non-final or abstract class file %s", THREAD);
3914-
return;
3915-
}
39163908
parsed_record_attribute = true;
39173909
record_attribute_start = cfs->current();
39183910
record_attribute_length = attribute_length;
@@ -3922,15 +3914,9 @@ void ClassFileParser::parse_classfile_attributes(const ClassFileStream* const cf
39223914
// --enable-preview wasn't specified then a java.lang.UnsupportedClassVersionError
39233915
// exception would have been thrown.
39243916
ResourceMark rm(THREAD);
3925-
if (supports_records()) {
3926-
log_info(class, record)(
3927-
"Ignoring Record attribute in class %s because super type is not java.lang.Record",
3928-
_class_name->as_C_string());
3929-
} else {
3930-
log_info(class, record)(
3931-
"Ignoring Record attribute in class %s because class file version is not %d.65535",
3932-
_class_name->as_C_string(), JVM_CLASSFILE_MAJOR_VERSION);
3933-
}
3917+
log_info(class, record)(
3918+
"Ignoring Record attribute in class %s because class file version is not %d.65535",
3919+
_class_name->as_C_string(), JVM_CLASSFILE_MAJOR_VERSION);
39343920
}
39353921
cfs->skip_u1(attribute_length, CHECK);
39363922
} else if (_major_version >= JAVA_15_VERSION) {

test/hotspot/jtreg/runtime/records/abstractRecord.jcod

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2019, 2020, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -24,8 +24,8 @@
2424
// This test was generated from this source and then modified:
2525
// record recordNames(int x, String y) {}
2626

27-
// This test is a Record marked as abstract. It should result in a
28-
// ClassFormatError exception.
27+
// This test is a Record marked as abstract. Loading this class should
28+
// not cause a ClassFormatError exception.
2929
class abstractRecord {
3030
0xCAFEBABE;
3131
65535; // minor version

test/hotspot/jtreg/runtime/records/ignoreRecordAttribute.java

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
* @test
2626
* @summary test logging of reasons for ignoring Record attribute
2727
* @library /test/lib
28-
* @compile superNotJLRecord.jcod recordIgnoredVersion.jcod
28+
* @compile recordIgnoredVersion.jcod
2929
* @run driver ignoreRecordAttribute
3030
*/
3131

@@ -37,14 +37,8 @@ public class ignoreRecordAttribute {
3737
public static void main(String[] args) throws Exception {
3838
String MAJOR_VERSION = Integer.toString(44 + Runtime.version().feature());
3939
ProcessBuilder pb = ProcessTools.createJavaProcessBuilder("--enable-preview",
40-
"-Xlog:class+record", "-Xshare:off", "superNotJLRecord");
41-
OutputAnalyzer output = new OutputAnalyzer(pb.start());
42-
output.shouldContain("Ignoring Record attribute");
43-
output.shouldContain("because super type is not java.lang.Record");
44-
45-
pb = ProcessTools.createJavaProcessBuilder("--enable-preview",
4640
"-Xlog:class+record", "-Xshare:off", "recordIgnoredVersion");
47-
output = new OutputAnalyzer(pb.start());
41+
OutputAnalyzer output = new OutputAnalyzer(pb.start());
4842
output.shouldContain("Ignoring Record attribute");
4943
output.shouldContain("because class file version is not " + MAJOR_VERSION + ".65535");
5044
}

test/hotspot/jtreg/runtime/records/notFinalRecord.jcod

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@
2424
// This test was generated from this source and then modified:
2525
// record recordNames(int x, String y) {}
2626

27-
// This test is a Record but not marked final. It should result in a
28-
// ClassFormatError exception.
27+
// This test is a Record but not marked final. Loading this class should
28+
// not cause a ClassFormatError exception.
2929
class notFinalRecord {
3030
0xCAFEBABE;
3131
65535; // minor version

test/hotspot/jtreg/runtime/records/recordAttributeTest.java

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2019, 2020, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -54,13 +54,11 @@ public static void main(String... args) throws Throwable {
5454
runTest("twoRecordAttributes",
5555
"Multiple Record attributes in class");
5656

57-
// Test loading a Record type marked abstract. This should throw ClassFormatError.
58-
runTest("abstractRecord",
59-
"Record attribute in non-final or abstract class");
57+
// Test loading a Record type marked abstract. This should not throw ClassFormatError.
58+
Class abstractClass = Class.forName("abstractRecord");
6059

61-
// Test loading a Record type that is not final. This should throw ClassFormatError.
62-
runTest("notFinalRecord",
63-
"Record attribute in non-final or abstract class");
60+
// Test loading a Record type that is not final. This should not throw ClassFormatError.
61+
Class notFinalClass = Class.forName("notFinalRecord");
6462

6563
// Test loading a Record type that is badly formed. This should throw ClassFormatError.
6664
runTest("badRecordAttribute",
@@ -73,8 +71,13 @@ public static void main(String... args) throws Throwable {
7371
// badly formed Record attribute. No exception should be thrown.
7472
Class newClass = Class.forName("oldRecordAttribute");
7573

76-
// Test that loading a class whose super class is not java.lang.Record
77-
// ignores a badly formed Record attribute. No exception should be thrown.
78-
newClass = Class.forName("superNotJLRecord");
74+
// Test that loading a class containing an ill-formed Record attribute causes a
75+
// ClassFormatError exception even though its super class is not java.lang.Record.
76+
runTest("superNotJLRecord", "Truncated class file");
77+
78+
// Test that loading a class that contains a properly formed Record attribute
79+
// does not cause a ClassFormatError exception even though its super class is not
80+
// java.lang.Record.
81+
Class superNoJLRClass = Class.forName("superNotJLRecordOK");
7982
}
8083
}

0 commit comments

Comments
 (0)