Skip to content

Commit 1da28de

Browse files
author
Vicente Romero
committed
8255009: delta apply fixes for JDK-8246774 and JDK-8253455, pushed too soon
Reviewed-by: jlahoda
1 parent a0382cd commit 1da28de

File tree

121 files changed

+923
-312
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

121 files changed

+923
-312
lines changed

src/hotspot/share/classfile/classFileParser.cpp

Lines changed: 42 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3567,6 +3567,12 @@ bool ClassFileParser::supports_sealed_types() {
35673567
Arguments::enable_preview();
35683568
}
35693569

3570+
bool ClassFileParser::supports_records() {
3571+
return _major_version == JVM_CLASSFILE_MAJOR_VERSION &&
3572+
_minor_version == JAVA_PREVIEW_MINOR_VERSION &&
3573+
Arguments::enable_preview();
3574+
}
3575+
35703576
void ClassFileParser::parse_classfile_attributes(const ClassFileStream* const cfs,
35713577
ConstantPool* cp,
35723578
ClassFileParser::ClassAnnotationCollector* parsed_annotations,
@@ -3814,28 +3820,12 @@ void ClassFileParser::parse_classfile_attributes(const ClassFileStream* const cf
38143820
"Nest-host class_info_index %u has bad constant type in class file %s",
38153821
class_info_index, CHECK);
38163822
_nest_host = class_info_index;
3817-
3818-
} else if (_major_version >= JAVA_15_VERSION) {
3819-
// Check for PermittedSubclasses tag
3820-
if (tag == vmSymbols::tag_permitted_subclasses()) {
3821-
if (supports_sealed_types()) {
3822-
if (parsed_permitted_subclasses_attribute) {
3823-
classfile_parse_error("Multiple PermittedSubclasses attributes in class file %s", CHECK);
3824-
}
3825-
// Classes marked ACC_FINAL cannot have a PermittedSubclasses attribute.
3826-
if (_access_flags.is_final()) {
3827-
classfile_parse_error("PermittedSubclasses attribute in final class file %s", CHECK);
3828-
}
3829-
parsed_permitted_subclasses_attribute = true;
3830-
permitted_subclasses_attribute_start = cfs->current();
3831-
permitted_subclasses_attribute_length = attribute_length;
3832-
}
3833-
cfs->skip_u1(attribute_length, CHECK);
3834-
3835-
} else if (_major_version >= JAVA_16_VERSION) {
3823+
} else if (_major_version >= JAVA_14_VERSION) {
38363824
if (tag == vmSymbols::tag_record()) {
3837-
// Skip over Record attribute if super class is not java.lang.Record.
3838-
if (cp->klass_name_at(_super_class_index) == vmSymbols::java_lang_Record()) {
3825+
// Skip over Record attribute if not supported or if super class is
3826+
// not java.lang.Record.
3827+
if (supports_records() &&
3828+
cp->klass_name_at(_super_class_index) == vmSymbols::java_lang_Record()) {
38393829
if (parsed_record_attribute) {
38403830
classfile_parse_error("Multiple Record attributes in class file %s", THREAD);
38413831
return;
@@ -3849,13 +3839,44 @@ void ClassFileParser::parse_classfile_attributes(const ClassFileStream* const cf
38493839
record_attribute_start = cfs->current();
38503840
record_attribute_length = attribute_length;
38513841
} else if (log_is_enabled(Info, class, record)) {
3842+
// Log why the Record attribute was ignored. Note that if the
3843+
// class file version is JVM_CLASSFILE_MAJOR_VERSION.65535 and
3844+
// --enable-preview wasn't specified then a java.lang.UnsupportedClassVersionError
3845+
// exception would have been thrown.
38523846
ResourceMark rm(THREAD);
3847+
if (supports_records()) {
38533848
log_info(class, record)(
38543849
"Ignoring Record attribute in class %s because super type is not java.lang.Record",
38553850
_class_name->as_C_string());
3851+
} else {
3852+
log_info(class, record)(
3853+
"Ignoring Record attribute in class %s because class file version is not %d.65535",
3854+
_class_name->as_C_string(), JVM_CLASSFILE_MAJOR_VERSION);
38563855
}
38573856
}
38583857
cfs->skip_u1(attribute_length, CHECK);
3858+
} else if (_major_version >= JAVA_15_VERSION) {
3859+
// Check for PermittedSubclasses tag
3860+
if (tag == vmSymbols::tag_permitted_subclasses()) {
3861+
if (supports_sealed_types()) {
3862+
if (parsed_permitted_subclasses_attribute) {
3863+
classfile_parse_error("Multiple PermittedSubclasses attributes in class file %s", THREAD);
3864+
return;
3865+
}
3866+
// Classes marked ACC_FINAL cannot have a PermittedSubclasses attribute.
3867+
if (_access_flags.is_final()) {
3868+
classfile_parse_error("PermittedSubclasses attribute in final class file %s", THREAD);
3869+
return;
3870+
}
3871+
parsed_permitted_subclasses_attribute = true;
3872+
permitted_subclasses_attribute_start = cfs->current();
3873+
permitted_subclasses_attribute_length = attribute_length;
3874+
}
3875+
cfs->skip_u1(attribute_length, CHECK);
3876+
} else {
3877+
// Unknown attribute
3878+
cfs->skip_u1(attribute_length, CHECK);
3879+
}
38593880
} else {
38603881
// Unknown attribute
38613882
cfs->skip_u1(attribute_length, CHECK);

src/java.base/share/classes/java/lang/Class.java

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2342,6 +2342,13 @@ public Field[] getDeclaredFields() throws SecurityException {
23422342
}
23432343

23442344
/**
2345+
* {@preview Associated with records, a preview feature of the Java language.
2346+
*
2347+
* This method is associated with <i>records</i>, a preview
2348+
* feature of the Java language. Preview features
2349+
* may be removed in a future release, or upgraded to permanent
2350+
* features of the Java language.}
2351+
*
23452352
* Returns an array of {@code RecordComponent} objects representing all the
23462353
* record components of this record class, or {@code null} if this class is
23472354
* not a record class.
@@ -2378,8 +2385,11 @@ public Field[] getDeclaredFields() throws SecurityException {
23782385
* </ul>
23792386
*
23802387
* @jls 8.10 Record Types
2381-
* @since 16
2388+
* @since 14
23822389
*/
2390+
@jdk.internal.PreviewFeature(feature=jdk.internal.PreviewFeature.Feature.RECORDS,
2391+
essentialAPI=false)
2392+
@SuppressWarnings("preview")
23832393
@CallerSensitive
23842394
public RecordComponent[] getRecordComponents() {
23852395
SecurityManager sm = System.getSecurityManager();
@@ -3678,6 +3688,13 @@ private static Class<?> javaLangRecordClass() {
36783688
}
36793689

36803690
/**
3691+
* {@preview Associated with records, a preview feature of the Java language.
3692+
*
3693+
* This method is associated with <i>records</i>, a preview
3694+
* feature of the Java language. Preview features
3695+
* may be removed in a future release, or upgraded to permanent
3696+
* features of the Java language.}
3697+
*
36813698
* Returns {@code true} if and only if this class is a record class.
36823699
*
36833700
* <p> The {@linkplain #getSuperclass() direct superclass} of a record
@@ -3690,8 +3707,10 @@ private static Class<?> javaLangRecordClass() {
36903707
*
36913708
* @return true if and only if this class is a record class, otherwise false
36923709
* @jls 8.10 Record Types
3693-
* @since 16
3710+
* @since 14
36943711
*/
3712+
@jdk.internal.PreviewFeature(feature=jdk.internal.PreviewFeature.Feature.RECORDS,
3713+
essentialAPI=false)
36953714
public boolean isRecord() {
36963715
return getSuperclass() == JAVA_LANG_RECORD_CLASS && isRecord0();
36973716
}

src/java.base/share/classes/java/lang/Record.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,14 @@
2525
package java.lang;
2626

2727
/**
28+
* {@preview Associated with records, a preview feature of the Java language.
29+
*
30+
* This class is associated with <i>records</i>, a preview
31+
* feature of the Java language. Programs can only use this
32+
* class when preview features are enabled. Preview features
33+
* may be removed in a future release, or upgraded to permanent
34+
* features of the Java language.}
35+
*
2836
* This is the common base class of all Java language record classes.
2937
*
3038
* <p>More information about records, including descriptions of the
@@ -78,8 +86,10 @@
7886
* <a href="{@docRoot}/java.base/java/io/ObjectInputStream.html#record-serialization">record serialization</a>.
7987
*
8088
* @jls 8.10 Record Types
81-
* @since 16
89+
* @since 14
8290
*/
91+
@jdk.internal.PreviewFeature(feature=jdk.internal.PreviewFeature.Feature.RECORDS,
92+
essentialAPI=true)
8393
public abstract class Record {
8494
/**
8595
* Constructor for record classes to call.

src/java.base/share/classes/java/lang/annotation/ElementType.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,12 +118,22 @@ public enum ElementType {
118118
MODULE,
119119

120120
/**
121+
* {@preview Associated with records, a preview feature of the Java language.
122+
*
123+
* This constant is associated with <i>records</i>, a preview
124+
* feature of the Java language. Programs can only use this
125+
* constant when preview features are enabled. Preview features
126+
* may be removed in a future release, or upgraded to permanent
127+
* features of the Java language.}
128+
*
121129
* Record component
122130
*
123131
* @jls 8.10.3 Record Members
124132
* @jls 9.7.4 Where Annotations May Appear
125133
*
126-
* @since 16
134+
* @since 14
127135
*/
136+
@jdk.internal.PreviewFeature(feature=jdk.internal.PreviewFeature.Feature.RECORDS,
137+
essentialAPI=true)
128138
RECORD_COMPONENT;
129139
}

src/java.base/share/classes/java/lang/reflect/RecordComponent.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,23 @@
3838
import java.util.Objects;
3939

4040
/**
41+
* {@preview Associated with records, a preview feature of the Java language.
42+
*
43+
* This class is associated with <i>records</i>, a preview
44+
* feature of the Java language. Preview features
45+
* may be removed in a future release, or upgraded to permanent
46+
* features of the Java language.}
47+
*
4148
* A {@code RecordComponent} provides information about, and dynamic access to, a
4249
* component of a record class.
4350
*
4451
* @see Class#getRecordComponents()
4552
* @see java.lang.Record
4653
* @jls 8.10 Record Types
47-
* @since 16
54+
* @since 14
4855
*/
56+
@jdk.internal.PreviewFeature(feature=jdk.internal.PreviewFeature.Feature.RECORDS,
57+
essentialAPI=false)
4958
public final class RecordComponent implements AnnotatedElement {
5059
// declaring class
5160
private Class<?> clazz;

src/java.base/share/classes/java/lang/runtime/ObjectMethods.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,23 @@
3838
import java.util.Objects;
3939

4040
/**
41+
* {@preview Associated with records, a preview feature of the Java language.
42+
*
43+
* This class is associated with <i>records</i>, a preview
44+
* feature of the Java language. Preview features
45+
* may be removed in a future release, or upgraded to permanent
46+
* features of the Java language.}
47+
*
4148
* Bootstrap methods for state-driven implementations of core methods,
4249
* including {@link Object#equals(Object)}, {@link Object#hashCode()}, and
4350
* {@link Object#toString()}. These methods may be used, for example, by
4451
* Java compiler implementations to implement the bodies of {@link Object}
4552
* methods for record classes.
4653
*
47-
* @since 16
54+
* @since 14
4855
*/
56+
@jdk.internal.PreviewFeature(feature=jdk.internal.PreviewFeature.Feature.RECORDS,
57+
essentialAPI=false)
4958
public class ObjectMethods {
5059

5160
private ObjectMethods() { }

src/java.base/share/classes/jdk/internal/PreviewFeature.java

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -62,11 +62,6 @@ public enum Feature {
6262
// JDK 15. Since the JDK 14 codebase uses the enum constant, it is
6363
// necessary for PreviewFeature in JDK 15 to declare the enum constant.
6464
TEXT_BLOCKS,
65-
// The RECORDS enum constant is not used in the JDK 16 codebase, but
66-
// exists to support the bootcycle build of JDK 16. The bootcycle build
67-
// of JDK 16 is performed with JDK 15 and the PreviewFeature type from
68-
// JDK 16. Since the JDK 15 codebase uses the enum constant, it is
69-
// necessary for PreviewFeature in JDK 16 to declare the enum constant.
7065
RECORDS,
7166
SEALED_CLASSES,
7267
;

src/java.base/share/classes/sun/reflect/annotation/TypeAnnotation.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,16 @@ public static enum TypeAnnotationTarget {
9292
METHOD_FORMAL_PARAMETER,
9393
THROWS,
9494
/**
95-
* @since 16
95+
* {@preview Associated with records, a preview feature of the Java language.
96+
*
97+
* This enum constant is associated with <i>records</i>, a preview
98+
* feature of the Java language. Preview features
99+
* may be removed in a future release, or upgraded to permanent
100+
* features of the Java language.}
101+
* @since 14
96102
*/
103+
@jdk.internal.PreviewFeature(feature=jdk.internal.PreviewFeature.Feature.RECORDS,
104+
essentialAPI=false)
97105
RECORD_COMPONENT;
98106
}
99107

src/java.compiler/share/classes/javax/lang/model/element/ElementKind.java

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,15 +110,33 @@ public enum ElementKind {
110110
MODULE,
111111

112112
/**
113+
* {@preview Associated with records, a preview feature of the Java language.
114+
*
115+
* This enum constant is associated with <i>records</i>, a preview
116+
* feature of the Java language. Preview features
117+
* may be removed in a future release, or upgraded to permanent
118+
* features of the Java language.}
119+
*
113120
* A record type.
114-
* @since 16
121+
* @since 14
115122
*/
123+
@jdk.internal.PreviewFeature(feature=jdk.internal.PreviewFeature.Feature.RECORDS,
124+
essentialAPI=false)
116125
RECORD,
117126

118127
/**
128+
* {@preview Associated with records, a preview feature of the Java language.
129+
*
130+
* This enum constant is associated with <i>records</i>, a preview
131+
* feature of the Java language. Preview features
132+
* may be removed in a future release, or upgraded to permanent
133+
* features of the Java language.}
134+
*
119135
* A record component of a {@code record}.
120-
* @since 16
136+
* @since 14
121137
*/
138+
@jdk.internal.PreviewFeature(feature=jdk.internal.PreviewFeature.Feature.RECORDS,
139+
essentialAPI=false)
122140
RECORD_COMPONENT,
123141

124142
/**

src/java.compiler/share/classes/javax/lang/model/element/ElementVisitor.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,13 @@ default R visitModule(ModuleElement e, P p) {
212212
}
213213

214214
/**
215+
* {@preview Associated with records, a preview feature of the Java language.
216+
*
217+
* This method is associated with <i>records</i>, a preview
218+
* feature of the Java language. Preview features
219+
* may be removed in a future release, or upgraded to permanent
220+
* features of the Java language.}
221+
*
215222
* Visits a record component element.
216223
*
217224
* @implSpec The default implementation visits a {@code
@@ -220,8 +227,11 @@ default R visitModule(ModuleElement e, P p) {
220227
* @param e the element to visit
221228
* @param p a visitor-specified parameter
222229
* @return a visitor-specified result
223-
* @since 16
230+
* @since 14
224231
*/
232+
@jdk.internal.PreviewFeature(feature=jdk.internal.PreviewFeature.Feature.RECORDS,
233+
essentialAPI=false)
234+
@SuppressWarnings("preview")
225235
default R visitRecordComponent(RecordComponentElement e, P p) {
226236
return visitUnknown(e, p);
227237
}

0 commit comments

Comments
 (0)