Top Description Inners Fields Constructors Methods
java.io

public final Class ObjectStreamClass

extends Object
implements Serializable
Class Inheritance
All Implemented Interfaces
java.io.Serializable
Imports
java.lang.invoke.MethodHandle, .MethodHandles, .MethodType, java.lang.reflect.Constructor, .Field, .InvocationTargetException, .RecordComponent, .UndeclaredThrowableException, .Member, .Method, .Modifier, .Proxy, java.security.AccessControlContext, .AccessController, .MessageDigest, .NoSuchAlgorithmException, .PermissionCollection, .Permissions, .PrivilegedAction, .PrivilegedActionException, .PrivilegedExceptionAction, .ProtectionDomain, java.util.ArrayList, .Arrays, .Collections, .Comparator, .HashSet, .Map, .Set, java.util.concurrent.ConcurrentHashMap, jdk.internal.misc.Unsafe, jdk.internal.reflect.CallerSensitive, .Reflection, .ReflectionFactory, jdk.internal.access.SharedSecrets, .JavaSecurityAccess, jdk.internal.util.ByteArray, sun.reflect.misc.ReflectUtil

Serialization's descriptor for classes. It contains the name and serialVersionUID of the class. The ObjectStreamClass for a specific class loaded in this Java VM can be found/created using the lookup method.

The algorithm to compute the SerialVersionUID is described in Java Object Serialization Specification, Section 4.6, "Stream Unique Identifiers".

Authors
Mike Warres, Roger Riggs
Since
1.1
External Specification
Java Object Serialization Specification
See Also
ObjectStreamField, Java Object Serialization Specification, Section 4, "Class Descriptors"

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class
pack-priv static class
ObjectStreamClass.ClassDataSlot

Class representing the portion of an object's serialized form allotted to data described by a given class descriptor.

private static class
ObjectStreamClass.DeserializationConstructorsCache

A LRA cache of record deserialization constructors.

private static class
ObjectStreamClass.ExceptionInfo

Contains information about InvalidClassException instances to be thrown when attempting operations on an invalid class.

private static class
ObjectStreamClass.FieldReflector

Class for setting and retrieving serializable field values in batch.

private static class
ObjectStreamClass.FieldReflectorKey

FieldReflector cache lookup key.

private static class
ObjectStreamClass.MemberSignature

Class for computing and caching field/constructor/method signatures during serialVersionUID calculation.

pack-priv static class
ObjectStreamClass.RecordSupport

Record specific support for retrieving and binding stream field values.

Field Summary

Modifier and TypeField and Description
private MethodHandle
canonicalCtr

record canonical constructor (shared among OSCs for same class), or null

private Class<?>
cl

class associated with this descriptor (if any)

private Constructor<?>
cons

serialization-appropriate constructor, or null if none

private volatile ObjectStreamClass.ClassDataSlot[]
dataLayout

data layout of serialized objects described by this class desc

private ObjectStreamClass.ExceptionInfo
defaultSerializeEx

exception (if any) to throw if default serialization attempted

private MethodHandle
deserializationCtr

session-cache of record deserialization constructor (in de-serialized OSC only), or null

private ObjectStreamClass.DeserializationConstructorsCache
deserializationCtrs

cache of record deserialization constructors per unique set of stream fields (shared among OSCs for same class), or null

private ObjectStreamClass.ExceptionInfo
deserializeEx

exception (if any) to throw if non-enum deserialization attempted

private ProtectionDomain[]
domains

protection domains that need to be checked when calling the constructor

private boolean
externalizable

true if represented class implements Externalizable

private ObjectStreamClass.FieldReflector
fieldRefl

reflector for setting/getting serializable field values

private ObjectStreamField[]
fields

serializable fields

private boolean
hasBlockExternalData

true if desc has externalizable data written in block data format; this must be true by default to accommodate ObjectInputStream subclasses which override readClassDescriptor() to return class descriptors obtained from ObjectStreamClass.lookup() (see 4461737)

private boolean
hasWriteObjectData

true if desc has data written by class-defined writeObject method

private boolean
initialized

true if, and only if, the object has been correctly initialized

private boolean
isEnum

true if represents enum type

private boolean
isProxy

true if represents dynamic proxy class

private boolean
isRecord

true if represents record type

private ObjectStreamClass
localDesc

local class descriptor for represented class (may point to self)

private String
name

name of class represented by this descriptor

public static final ObjectStreamField[]
NO_FIELDS

serialPersistentFields value indicating no serializable fields

private int
numObjFields

number of non-primitive fields

private int
primDataSize

aggregate marshalled size of primitive fields

private Method
readObjectMethod

class-defined readObject method, or null if none

private Method
readObjectNoDataMethod

class-defined readObjectNoData method, or null if none

private Method
readResolveMethod

class-defined readResolve method, or null if none

private static final ReflectionFactory
reflFactory

reflection factory for obtaining serialization constructors

private ClassNotFoundException
resolveEx

exception (if any) thrown while attempting to resolve class

private boolean
serializable

true if represented class implements Serializable

private ObjectStreamClass.ExceptionInfo
serializeEx

exception (if any) to throw if non-enum serialization attempted

private static final ObjectStreamField[]
serialPersistentFields

ObjectStreamClass has no fields for default serialization.

private static final long
private volatile Long
suid

serialVersionUID of represented class (null if not computed yet)

private ObjectStreamClass
superDesc

superclass descriptor appearing in stream

private Method
writeObjectMethod

class-defined writeObject method, or null if none

private Method
writeReplaceMethod

class-defined writeReplace method, or null if none

Constructor Summary

AccessConstructor and Description
private
ObjectStreamClass(final Class<?> cl)

Creates local class descriptor representing given class.

pack-priv
ObjectStreamClass()

Creates blank class descriptor which should be initialized via a subsequent call to initProxy(), initNonProxy() or readNonProxy().

Method Summary

Modifier and TypeMethod and Description
private static MethodHandle
canonicalRecordCtr(Class<?> cls)

Returns the canonical constructor for the given record class, or null if the not found ( which should never happen for correctly generated record classes ).

pack-priv void
checkDefaultSerialize()

Throws an InvalidClassException if objects whose class is represented by this descriptor should not be permitted to use default serialization (e.g., if the class declares serializable fields that do not correspond to actual fields, and hence must use the GetField API).

pack-priv void
checkDeserialize()

Throws an InvalidClassException if object instances referencing this class descriptor should not be allowed to deserialize.

pack-priv final void
checkInitialized()

Throws InvalidClassException if not initialized.

pack-priv void
checkObjFieldValueTypes(Object obj, Object[] vals)

Checks that the given values, from array vals starting at offset 0, are assignable to the given serializable object fields.

pack-priv void
checkSerialize()

Throws an InvalidClassException if objects whose class is represented by this descriptor should not be allowed to serialize.

private static boolean
classNamesEqual(String name1, String name2)

Compares class names for equality, ignoring package names.

private static long
computeDefaultSUID(Class<?> cl)

Computes the default serial version UID value for the given class.

private void
computeFieldOffsets()

Calculates and sets serializable field offsets, as well as primitive data size and object field count totals.

public Class<?>

Returns:

the Class instance that this descriptor represents
forClass
()

Return the class in the local VM that this version is mapped to.

pack-priv ObjectStreamClass.ClassDataSlot[]
getClassDataLayout()

Returns array of ClassDataSlot instances representing the data layout (including superclass data) for serialized objects described by this class descriptor.

private ObjectStreamClass.ClassDataSlot[]
private static ObjectStreamField[]
getDeclaredSerialFields(Class<?> cl)

Returns serializable fields of given class as defined explicitly by a "serialPersistentFields" field, or null if no appropriate "serialPersistentFields" field is defined.

private static Long
getDeclaredSUID(Class<?> cl)

Returns explicit serial version UID value declared by given class, or null if none.

private static ObjectStreamField[]
getDefaultSerialFields(Class<?> cl)

Returns array of ObjectStreamFields corresponding to all non-static non-transient fields declared by given class.

private static Constructor<?>
getExternalizableConstructor(Class<?> cl)

Returns public no-arg constructor of given class, or null if none found.

public ObjectStreamField

Returns:

The ObjectStreamField object of the named field or null if there is no such named field.
getField
(String
the name of the data field to look for
name
)

Get the field of this class by name.

pack-priv ObjectStreamField
getField(String name, Class<?> type)

Looks up a serializable field of the represented class by name and type.

public ObjectStreamField[]

Returns:

an array containing an element for each persistent field of this class. Returns an array of length zero if there are no fields.
getFields
()

Return an array of the fields of this serializable class.

pack-priv ObjectStreamField[]
getFields(boolean copy)

Returns arrays of ObjectStreamFields representing the serializable fields of the represented class.

private static Method
getInheritableMethod(Class<?> cl, String name, Class<?>[] argTypes, Class<?> returnType)

Returns non-static, non-abstract method with given signature provided it is defined by or accessible (via inheritance) by the given class, or null if no match found.

pack-priv ObjectStreamClass
getLocalDesc()

Returns the "local" class descriptor for the class associated with this class descriptor (i.e., the result of ObjectStreamClass.lookup(this.forClass())) or null if there is no class associated with this descriptor.

private static String
getMethodSignature(Class<?>[] paramTypes, Class<?> retType)

Returns JVM type signature for given list of parameters and return type.

public String

Returns:

a string representing the name of the class
getName
()

Returns the name of the class described by this descriptor.

pack-priv int
getNumObjFields()

Returns number of non-primitive serializable fields of represented class.

pack-priv void
getObjFieldValues(Object obj, Object[] vals)

Fetches the serializable object field values of object obj and stores them in array vals starting at offset 0.

pack-priv int
getPrimDataSize()

Returns aggregate size (in bytes) of marshalled primitive field values for represented class.

pack-priv void
getPrimFieldValues(Object obj, byte[] buf)

Fetches the serializable primitive field values of object obj and marshals them into byte array buf starting at offset 0.

private static Method
getPrivateMethod(Class<?> cl, String name, Class<?>[] argTypes, Class<?> returnType)

Returns non-static private method with given signature defined by given class, or null if none found.

private ProtectionDomain[]

Returns:

An array of ProtectionDomain representing the set of ProtectionDomain that separate the concrete class cl from its ancestor's declaring cons, or null.
getProtectionDomains
(Constructor<?>
A constructor declared by cl or one of its ancestors.
cons
,
Class<?>
A concrete class, which is either the class declaring the constructor cons, or a serializable subclass of that class.
cl
)

Aggregate the ProtectionDomains of all the classes that separate a concrete class cl from its ancestor's class declaring a constructor cons.

pack-priv MethodHandle
getRecordConstructor()

Returns the canonical constructor, if the local class equivalent of this stream class descriptor is a record class, otherwise null.

private static ObjectStreamClass.FieldReflector
getReflector(ObjectStreamField[] fields, ObjectStreamClass localDesc)

Matches given set of serializable fields with serializable fields described by the given local class descriptor, and returns a FieldReflector instance capable of setting/getting values from the subset of fields that match (non-matching fields are treated as filler, for which get operations return default values and set operations discard given values).

pack-priv ClassNotFoundException
getResolveException()

Returns ClassNotFoundException (if any) thrown while attempting to resolve local class corresponding to this class descriptor.

private static ObjectStreamField[]
getSerialFields(Class<?> cl)

Returns ObjectStreamField array describing the serializable fields of the given class.

private static Constructor<?>
getSerializableConstructor(Class<?> cl)

Returns subclass-accessible no-arg constructor of first non-serializable superclass, or null if none found.

public long

Returns:

the SUID of the class described by this descriptor
getSerialVersionUID
()

Return the serialVersionUID for this class.

pack-priv ObjectStreamClass
getSuperDesc()

Returns superclass descriptor.

private ObjectStreamClass
getVariantFor(Class<?> cl)

If given class is the same as the class associated with this class descriptor, returns reference to this class descriptor.

pack-priv boolean
hasBlockExternalData()

Returns true if class descriptor represents externalizable class that has written its data in 1.2 (block data) format, false otherwise.

pack-priv boolean
hasReadObjectMethod()

Returns true if represented class is serializable (but not externalizable) and defines a conformant readObject method.

pack-priv boolean
hasReadObjectNoDataMethod()

Returns true if represented class is serializable (but not externalizable) and defines a conformant readObjectNoData method.

pack-priv boolean
hasReadResolveMethod()

Returns true if represented class is serializable or externalizable and defines a conformant readResolve method.

private static native boolean
hasStaticInitializer(Class<?> cl)

Returns true if the given class defines a static initializer method, false otherwise.

pack-priv boolean
hasWriteObjectData()

Returns true if class descriptor represents serializable (but not externalizable) class which has written its data via a custom writeObject() method, false otherwise.

pack-priv boolean
hasWriteObjectMethod()

Returns true if represented class is serializable (but not externalizable) and defines a conformant writeObject method.

pack-priv boolean
hasWriteReplaceMethod()

Returns true if represented class is serializable or externalizable and defines a conformant writeReplace method.

private static native void
initNative()

Initializes native code.

pack-priv void
initNonProxy(ObjectStreamClass model, Class<?> cl, ClassNotFoundException resolveEx, ObjectStreamClass superDesc)

Initializes class descriptor representing a non-proxy class.

pack-priv void
initProxy(Class<?> cl, ClassNotFoundException resolveEx, ObjectStreamClass superDesc)

Initializes class descriptor representing a proxy class.

pack-priv void
invokeReadObject(Object obj, ObjectInputStream in)

Invokes the readObject method of the represented serializable class.

pack-priv void
invokeReadObjectNoData(Object obj)

Invokes the readObjectNoData method of the represented serializable class.

pack-priv Object
invokeReadResolve(Object obj)

Invokes the readResolve method of the represented serializable class and returns the result.

pack-priv void
invokeWriteObject(Object obj, ObjectOutputStream out)

Invokes the writeObject method of the represented serializable class.

pack-priv Object
invokeWriteReplace(Object obj)

Invokes the writeReplace method of the represented serializable class and returns the result.

pack-priv boolean
isEnum()

Returns true if class descriptor represents an enum type, false otherwise.

pack-priv boolean
isExternalizable()

Returns true if represented class implements Externalizable, false otherwise.

pack-priv boolean
isInstantiable()

Returns true if represented class is serializable/externalizable and can be instantiated by the serialization runtime--i.e., if it is externalizable and defines a public no-arg constructor, or if it is non-externalizable and its first non-serializable superclass defines an accessible no-arg constructor.

pack-priv boolean
isProxy()

Returns true if class descriptor represents a dynamic proxy class, false otherwise.

pack-priv boolean
isRecord()

Returns true if class descriptor represents a record type, false otherwise.

pack-priv boolean
isSerializable()

Returns true if represented class implements Serializable, false otherwise.

public static ObjectStreamClass

Returns:

the class descriptor for the specified class
lookup
(Class<?>
class for which to get the descriptor
cl
)

Find the descriptor for a class that can be serialized.

pack-priv static ObjectStreamClass
lookup(Class<?>
class to look up
cl
,
boolean
if true, return descriptors for all classes; if false, only return descriptors for serializable classes
all
)

Looks up and returns class descriptor for given class, or null if class is non-serializable and "all" is set to false.

public static ObjectStreamClass

Returns:

the class descriptor for the specified class
lookupAny
(Class<?>
class for which to get the descriptor
cl
)

Returns the descriptor for any class, regardless of whether it implements Serializable.

private static ObjectStreamField[]
matchFields(ObjectStreamField[] fields, ObjectStreamClass localDesc)

Matches given set of serializable fields with serializable fields obtained from the given local class descriptor (which contain bindings to reflective Field objects).

pack-priv Object
newInstance()

Creates a new instance of the represented class.

private ProtectionDomain
noPermissionsDomain()

Creates a PermissionDomain that grants no permission.

private static boolean
packageEquals(Class<?> cl1, Class<?> cl2)

Returns true if classes are defined in the same runtime package, false otherwise.

pack-priv void
readNonProxy(ObjectInputStream in)

Reads non-proxy class descriptor information from given input stream.

private final void
requireInitialized()

Throws InternalError if not initialized.

pack-priv void
setObjFieldValues(Object obj, Object[] vals)

Sets the serializable object fields of object obj using values from array vals starting at offset 0.

pack-priv void
setPrimFieldValues(Object obj, byte[] buf)

Sets the serializable primitive fields of object obj using values unmarshalled from byte array buf starting at offset 0.

private static void
throwMiscException(Throwable th)

Convenience method for throwing an exception that is either a RuntimeException, Error, or of some unexpected type (in which case it is wrapped inside an IOException).

public String
toString()

Overrides java.lang.Object.toString.

Return a string describing this ObjectStreamClass.

pack-priv void
writeNonProxy(ObjectOutputStream out)

Writes non-proxy class descriptor information to given output stream.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAllwaitwaitwait