Skip to content

Commit d05401d

Browse files
author
Julia Boes
committed
8256679: Update serialization javadoc once JOSS changes for records are complete
Reviewed-by: chegar, rriggs
1 parent 7620124 commit d05401d

File tree

5 files changed

+24
-50
lines changed

5 files changed

+24
-50
lines changed

src/java.base/share/classes/java/io/ObjectInputStream.java

Lines changed: 7 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -223,39 +223,14 @@
223223
* Similarly, any serialPersistentFields or serialVersionUID field declarations
224224
* are also ignored--all enum types have a fixed serialVersionUID of 0L.
225225
*
226-
* @implSpec
227226
* <a id="record-serialization"></a>
228-
* Records are serialized differently than ordinary serializable or externalizable
229-
* objects. The serialized form of a record object is a sequence of values derived
230-
* from the record components. The stream format of a record object is the same as
231-
* that of an ordinary object in the stream. During deserialization, if the local
232-
* class equivalent of the specified stream class descriptor is a record class,
233-
* then first the stream fields are read and reconstructed to serve as the record's
234-
* component values; and second, a record object is created by invoking the
235-
* record's <i>canonical</i> constructor with the component values as arguments (or the
236-
* default value for component's type if a component value is absent from the
237-
* stream).
238-
* Like other serializable or externalizable objects, record objects can function
239-
* as the target of back references appearing subsequently in the serialization
240-
* stream. However, a cycle in the graph where the record object is referred to,
241-
* either directly or transitively, by one of its components, is not preserved.
242-
* The record components are deserialized prior to the invocation of the record
243-
* constructor, hence this limitation (see
244-
* <a href="{@docRoot}/../specs/serialization/serial-arch.html#cyclic-references">
245-
* <cite>Java Object Serialization Specification,</cite>
246-
* Section 1.14, "Circular References"</a> for additional information).
247-
* The process by which record objects are serialized or externalized cannot be
248-
* customized; any class-specific writeObject, readObject, readObjectNoData,
249-
* writeExternal, and readExternal methods defined by record classes are
250-
* ignored during serialization and deserialization. However, a substitute object
251-
* to be serialized or a designate replacement may be specified, by the
252-
* writeReplace and readResolve methods, respectively. Any
253-
* serialPersistentFields field declaration is ignored. Documenting serializable
254-
* fields and data for record classes is unnecessary, since there is no variation
255-
* in the serial form, other than whether a substitute or replacement object is
256-
* used. The serialVersionUID of a record class is 0L unless explicitly
257-
* declared. The requirement for matching serialVersionUID values is waived for
258-
* record classes.
227+
* <p>Records are serialized differently than ordinary serializable or externalizable
228+
* objects. During deserialization the record's canonical constructor is invoked
229+
* to construct the record object. Certain serialization-related methods, such
230+
* as readObject and writeObject, are ignored for serializable records. See
231+
* <a href="{@docRoot}/../specs/serialization/serial-arch.html#serialization-of-records">
232+
* <cite>Java Object Serialization Specification,</cite> Section 1.13,
233+
* "Serialization of Records"</a> for additional information.
259234
*
260235
* @author Mike Warres
261236
* @author Roger Riggs

src/java.base/share/classes/java/io/ObjectOutputStream.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 1996, 2019, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 1996, 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
@@ -150,8 +150,7 @@
150150
* defaultWriteObject and writeFields initially terminate any existing
151151
* block-data record.
152152
*
153-
* @implSpec
154-
* Records are serialized differently than ordinary serializable or externalizable
153+
* <p>Records are serialized differently than ordinary serializable or externalizable
155154
* objects, see <a href="ObjectInputStream.html#record-serialization">record serialization</a>.
156155
*
157156
* @author Mike Warres
@@ -1483,7 +1482,6 @@ private void writeExternalData(Externalizable obj) throws IOException {
14831482
}
14841483

14851484
/** Writes the record component values for the given record object. */
1486-
@SuppressWarnings("preview")
14871485
private void writeRecordData(Object obj, ObjectStreamClass desc)
14881486
throws IOException
14891487
{

src/java.base/share/classes/java/io/ObjectStreamClass.java

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -490,11 +490,6 @@ Thread getOwner() {
490490
}
491491
}
492492

493-
@SuppressWarnings("preview")
494-
private static boolean isRecord(Class<?> cls) {
495-
return cls.isRecord();
496-
}
497-
498493
/**
499494
* Creates local class descriptor representing given class.
500495
*/
@@ -503,7 +498,7 @@ private ObjectStreamClass(final Class<?> cl) {
503498
name = cl.getName();
504499
isProxy = Proxy.isProxyClass(cl);
505500
isEnum = Enum.class.isAssignableFrom(cl);
506-
isRecord = isRecord(cl);
501+
isRecord = cl.isRecord();
507502
serializable = Serializable.class.isAssignableFrom(cl);
508503
externalizable = Externalizable.class.isAssignableFrom(cl);
509504

@@ -718,7 +713,7 @@ void initNonProxy(ObjectStreamClass model,
718713
}
719714

720715
if (model.serializable == osc.serializable &&
721-
!cl.isArray() && !isRecord(cl) &&
716+
!cl.isArray() && !cl.isRecord() &&
722717
suid != osc.getSerialVersionUID()) {
723718
throw new InvalidClassException(osc.name,
724719
"local class incompatible: " +
@@ -780,7 +775,7 @@ void initNonProxy(ObjectStreamClass model,
780775
deserializeEx = localDesc.deserializeEx;
781776
}
782777
domains = localDesc.domains;
783-
assert isRecord(cl) ? localDesc.cons == null : true;
778+
assert cl.isRecord() ? localDesc.cons == null : true;
784779
cons = localDesc.cons;
785780
}
786781

@@ -1590,9 +1585,8 @@ private static Constructor<?> getSerializableConstructor(Class<?> cl) {
15901585
* the not found ( which should never happen for correctly generated record
15911586
* classes ).
15921587
*/
1593-
@SuppressWarnings("preview")
15941588
private static MethodHandle canonicalRecordCtr(Class<?> cls) {
1595-
assert isRecord(cls) : "Expected record, got: " + cls;
1589+
assert cls.isRecord() : "Expected record, got: " + cls;
15961590
PrivilegedAction<MethodHandle> pa = () -> {
15971591
Class<?>[] paramTypes = Arrays.stream(cls.getRecordComponents())
15981592
.map(RecordComponent::getType)
@@ -1743,7 +1737,7 @@ private static ObjectStreamField[] getSerialFields(Class<?> cl)
17431737
return NO_FIELDS;
17441738

17451739
ObjectStreamField[] fields;
1746-
if (isRecord(cl)) {
1740+
if (cl.isRecord()) {
17471741
fields = getDefaultSerialFields(cl);
17481742
Arrays.sort(fields);
17491743
} else if (!Externalizable.class.isAssignableFrom(cl) &&
@@ -2663,7 +2657,6 @@ static final class RecordSupport {
26632657
* and return
26642658
* {@code Object}
26652659
*/
2666-
@SuppressWarnings("preview")
26672660
static MethodHandle deserializationCtr(ObjectStreamClass desc) {
26682661
// check the cached value 1st
26692662
MethodHandle mh = desc.deserializationCtr;

src/java.base/share/classes/java/io/Serializable.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,12 @@
139139
* serialization and deserialization. Any declarations of the special
140140
* handling methods discussed above are ignored for enum types.<p>
141141
*
142+
* Record classes can implement {@code Serializable} and receive treatment defined
143+
* by the <a href="{@docRoot}/../specs/serialization/serial-arch.html#serialization-of-records">
144+
* <cite>Java Object Serialization Specification,</cite> Section 1.13,
145+
* "Serialization of Records"</a>. Any declarations of the special
146+
* handling methods discussed above are ignored for record types.<p>
147+
*
142148
* The serialization runtime associates with each serializable class a version
143149
* number, called a serialVersionUID, which is used during deserialization to
144150
* verify that the sender and receiver of a serialized object have loaded

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,10 @@
7474
* deserialization the record's canonical constructor is invoked to construct
7575
* the record object. Certain serialization-related methods, such as readObject
7676
* and writeObject, are ignored for serializable records. More information about
77-
* serializable records can be found in
78-
* <a href="{@docRoot}/java.base/java/io/ObjectInputStream.html#record-serialization">record serialization</a>.
77+
* serializable records can be found in the
78+
* <a href="{@docRoot}/../specs/serialization/serial-arch.html#serialization-of-records">
79+
* <cite>Java Object Serialization Specification,</cite> Section 1.13,
80+
* "Serialization of Records"</a>.
7981
*
8082
* @jls 8.10 Record Types
8183
* @since 16

0 commit comments

Comments
 (0)