diff --git a/src/java.base/share/classes/java/io/ObjectInputStream.java b/src/java.base/share/classes/java/io/ObjectInputStream.java index 953131dfe62..03d3aa8dc45 100644 --- a/src/java.base/share/classes/java/io/ObjectInputStream.java +++ b/src/java.base/share/classes/java/io/ObjectInputStream.java @@ -223,39 +223,14 @@ import sun.security.action.GetIntegerAction; * Similarly, any serialPersistentFields or serialVersionUID field declarations * are also ignored--all enum types have a fixed serialVersionUID of 0L. * - * @implSpec * - * Records are serialized differently than ordinary serializable or externalizable - * objects. The serialized form of a record object is a sequence of values derived - * from the record components. The stream format of a record object is the same as - * that of an ordinary object in the stream. During deserialization, if the local - * class equivalent of the specified stream class descriptor is a record class, - * then first the stream fields are read and reconstructed to serve as the record's - * component values; and second, a record object is created by invoking the - * record's canonical constructor with the component values as arguments (or the - * default value for component's type if a component value is absent from the - * stream). - * Like other serializable or externalizable objects, record objects can function - * as the target of back references appearing subsequently in the serialization - * stream. However, a cycle in the graph where the record object is referred to, - * either directly or transitively, by one of its components, is not preserved. - * The record components are deserialized prior to the invocation of the record - * constructor, hence this limitation (see - * - * Java Object Serialization Specification, - * Section 1.14, "Circular References" for additional information). - * The process by which record objects are serialized or externalized cannot be - * customized; any class-specific writeObject, readObject, readObjectNoData, - * writeExternal, and readExternal methods defined by record classes are - * ignored during serialization and deserialization. However, a substitute object - * to be serialized or a designate replacement may be specified, by the - * writeReplace and readResolve methods, respectively. Any - * serialPersistentFields field declaration is ignored. Documenting serializable - * fields and data for record classes is unnecessary, since there is no variation - * in the serial form, other than whether a substitute or replacement object is - * used. The serialVersionUID of a record class is 0L unless explicitly - * declared. The requirement for matching serialVersionUID values is waived for - * record classes. + *
Records are serialized differently than ordinary serializable or externalizable + * objects. During deserialization the record's canonical constructor is invoked + * to construct the record object. Certain serialization-related methods, such + * as readObject and writeObject, are ignored for serializable records. See + * + * Java Object Serialization Specification, Section 1.13, + * "Serialization of Records" for additional information. * * @author Mike Warres * @author Roger Riggs diff --git a/src/java.base/share/classes/java/io/ObjectOutputStream.java b/src/java.base/share/classes/java/io/ObjectOutputStream.java index 2bc0fc31f36..b10e380ca57 100644 --- a/src/java.base/share/classes/java/io/ObjectOutputStream.java +++ b/src/java.base/share/classes/java/io/ObjectOutputStream.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1996, 2019, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1996, 2020, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -150,8 +150,7 @@ import sun.reflect.misc.ReflectUtil; * defaultWriteObject and writeFields initially terminate any existing * block-data record. * - * @implSpec - * Records are serialized differently than ordinary serializable or externalizable + *
Records are serialized differently than ordinary serializable or externalizable
* objects, see record serialization.
*
* @author Mike Warres
@@ -1483,7 +1482,6 @@ public class ObjectOutputStream
}
/** Writes the record component values for the given record object. */
- @SuppressWarnings("preview")
private void writeRecordData(Object obj, ObjectStreamClass desc)
throws IOException
{
diff --git a/src/java.base/share/classes/java/io/ObjectStreamClass.java b/src/java.base/share/classes/java/io/ObjectStreamClass.java
index fc1c708cdd9..806de0aa226 100644
--- a/src/java.base/share/classes/java/io/ObjectStreamClass.java
+++ b/src/java.base/share/classes/java/io/ObjectStreamClass.java
@@ -490,11 +490,6 @@ public class ObjectStreamClass implements Serializable {
}
}
- @SuppressWarnings("preview")
- private static boolean isRecord(Class> cls) {
- return cls.isRecord();
- }
-
/**
* Creates local class descriptor representing given class.
*/
@@ -503,7 +498,7 @@ public class ObjectStreamClass implements Serializable {
name = cl.getName();
isProxy = Proxy.isProxyClass(cl);
isEnum = Enum.class.isAssignableFrom(cl);
- isRecord = isRecord(cl);
+ isRecord = cl.isRecord();
serializable = Serializable.class.isAssignableFrom(cl);
externalizable = Externalizable.class.isAssignableFrom(cl);
@@ -718,7 +713,7 @@ public class ObjectStreamClass implements Serializable {
}
if (model.serializable == osc.serializable &&
- !cl.isArray() && !isRecord(cl) &&
+ !cl.isArray() && !cl.isRecord() &&
suid != osc.getSerialVersionUID()) {
throw new InvalidClassException(osc.name,
"local class incompatible: " +
@@ -780,7 +775,7 @@ public class ObjectStreamClass implements Serializable {
deserializeEx = localDesc.deserializeEx;
}
domains = localDesc.domains;
- assert isRecord(cl) ? localDesc.cons == null : true;
+ assert cl.isRecord() ? localDesc.cons == null : true;
cons = localDesc.cons;
}
@@ -1590,9 +1585,8 @@ public class ObjectStreamClass implements Serializable {
* the not found ( which should never happen for correctly generated record
* classes ).
*/
- @SuppressWarnings("preview")
private static MethodHandle canonicalRecordCtr(Class> cls) {
- assert isRecord(cls) : "Expected record, got: " + cls;
+ assert cls.isRecord() : "Expected record, got: " + cls;
PrivilegedAction
*
+ * Record classes can implement {@code Serializable} and receive treatment defined
+ * by the
+ * Java Object Serialization Specification, Section 1.13,
+ * "Serialization of Records". Any declarations of the special
+ * handling methods discussed above are ignored for record types.
+ *
* The serialization runtime associates with each serializable class a version
* number, called a serialVersionUID, which is used during deserialization to
* verify that the sender and receiver of a serialized object have loaded
diff --git a/src/java.base/share/classes/java/lang/Record.java b/src/java.base/share/classes/java/lang/Record.java
index 121fc7ce73c..67e538978d2 100644
--- a/src/java.base/share/classes/java/lang/Record.java
+++ b/src/java.base/share/classes/java/lang/Record.java
@@ -74,8 +74,10 @@ package java.lang;
* deserialization the record's canonical constructor is invoked to construct
* the record object. Certain serialization-related methods, such as readObject
* and writeObject, are ignored for serializable records. More information about
- * serializable records can be found in
- * record serialization.
+ * serializable records can be found in the
+ *
+ * Java Object Serialization Specification, Section 1.13,
+ * "Serialization of Records".
*
* @jls 8.10 Record Types
* @since 16