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
Object
Serialization Specification, Section 4.6, Stream Unique Identifiers.
- Author(s):
- Mike Warres
- Roger Riggs
- Since:
- JDK1.1
- See also:
ObjectStreamField- Object Serialization Specification, Section 4, Class Descriptors
serialPersistentFields value indicating no serializable fields
reflection factory for obtaining serialization constructors
cache mapping local classes -> descriptors
cache mapping field group/local desc pairs -> field reflectors
queue for WeakReferences to local classes
queue for WeakReferences to field reflectors keys
class associated with this descriptor (if any)
name of class represented by this descriptor
serialVersionUID of represented class (null if not computed yet)
true if represents dynamic proxy class
true if represents enum type
true if represented class implements Serializable
true if represented class implements Externalizable
true if desc has data written by class-defined writeObject method
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)
exception (if any) thrown while attempting to resolve class
exception (if any) to throw if non-enum deserialization attempted
exception (if any) to throw if non-enum serialization attempted
exception (if any) to throw if default serialization attempted
aggregate marshalled size of primitive fields
number of non-primitive fields
reflector for setting/getting serializable field values
data layout of serialized objects described by this class desc
serialization-appropriate constructor, or null if none
class-defined writeObject method, or null if none
class-defined readObject method, or null if none
class-defined readObjectNoData method, or null if none
class-defined writeReplace method, or null if none
class-defined readResolve method, or null if none
local class descriptor for represented class (may point to self)
superclass descriptor appearing in stream
Find the descriptor for a class that can be serialized. Creates an
ObjectStreamClass instance if one does not exist yet for class. Null is
returned if the specified class does not implement java.io.Serializable
or java.io.Externalizable.
- Parameters:
cl class for which to get the descriptor- Returns:
- the class descriptor for the specified class
Returns the descriptor for any class, regardless of whether it
implements
Serializable.
- Parameters:
cl class for which to get the descriptor- Returns:
- the class descriptor for the specified class
- Since:
- 1.6
Returns the name of the class described by this descriptor.
This method returns the name of the class in the format that
is used by the
java.lang.Class.getName() method.
- Returns:
- a string representing the name of the class
Return the serialVersionUID for this class. The serialVersionUID
defines a set of classes all with the same name that have evolved from a
common root class and agree to be serialized and deserialized using a
common format. NonSerializable classes have a serialVersionUID of 0L.
- Returns:
- the SUID of the class described by this descriptor
Return the class in the local VM that this version is mapped to. Null
is returned if there is no corresponding local class.
- Returns:
- the
Class instance that this descriptor represents
Return an array of the fields of this serializable class.
- Returns:
- an array containing an element for each persistent field of
this class. Returns an array of length zero if there are no
fields.
- Since:
- 1.2
Get the field of this class by name.
- Parameters:
name the name of the data field to look for- Returns:
- The ObjectStreamField object of the named field or null if
there is no such named field.
Return a string describing this ObjectStreamClass.
return name + ": static final long serialVersionUID = " +
Looks up and returns class descriptor for given class, or null if class
is non-serializable and "all" is set to false.
- Parameters:
cl class to look upall if true, return descriptors for all classes; if false, only
return descriptors for serializable classes
} while (ref != null && entry == null);
} else if (entry instanceof Error) { Placeholder used in class descriptor and field reflector lookup tables
for an entry in the process of being initialized. (Internal) callers
which receive an EntryFuture belonging to another thread as the result
of a lookup should call the get() method of the EntryFuture; this will
return the actual entry once it is ready for use and has been set(). To
conserve objects, EntryFutures synchronize on themselves.
Attempts to set the value contained by this EntryFuture. If the
EntryFuture's value has not been set already, then the value is
saved, any callers blocked in the get() method are notified, and
true is returned. If the value has already been set, then no saving
or notification occurs, and false is returned.
Returns the value contained by this EntryFuture, blocking if
necessary until a value is set.
boolean interrupted = false;
Returns the thread that created this EntryFuture.
Creates local class descriptor representing given class.
cl, "readObjectNoData", null, Void.TYPE);
cl, "writeReplace", null, Object.class);
cl, "readResolve", null, Object.class);
} else if (cons == null) { name, "no valid constructor");
name, "unmatched serializable field(s) declared");
Creates blank class descriptor which should be initialized via a
subsequent call to initProxy(), initNonProxy() or readNonProxy().
Initializes class descriptor representing a proxy class.
"cannot bind proxy descriptor to a non-proxy class");
Initializes class descriptor representing a non-proxy class.
"cannot bind non-proxy descriptor to a proxy class");
"cannot bind enum descriptor to a non-enum class" :
"cannot bind non-enum descriptor to an enum class");
"local class incompatible: " +
"stream classdesc serialVersionUID = " + suid +
", local class serialVersionUID = " +
"local class name incompatible with stream class " +
"name \"" + name + "\"");
"Serializable incompatible with Externalizable");
"class invalid for deserialization");
Reads non-proxy class descriptor information from given input stream.
The resulting class descriptor is not fully functional; it can only be
used as input to the ObjectInputStream.resolveClass() and
ObjectStreamClass.initNonProxy() methods.
name, "serializable and externalizable flags conflict");
"enum descriptor has non-zero serialVersionUID: " + suid);
if (isEnum && numFields != 0) { "enum descriptor has non-zero field count: " + numFields);
for (int i = 0; i < numFields; i++) { String signature = ((tcode == 'L') || (tcode == '[')) ?
"invalid descriptor for field " + fname).initCause(e);
Writes non-proxy class descriptor information to given output stream.
Returns ClassNotFoundException (if any) thrown while attempting to
resolve local class corresponding to this class descriptor.
Throws an InvalidClassException if object instances referencing this
class descriptor should not be allowed to deserialize. This method does
not apply to deserialization of enum constants.
Throws an InvalidClassException if objects whose class is represented by
this descriptor should not be allowed to serialize. This method does
not apply to serialization of enum constants.
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). This method
does not apply to deserialization of enum constants.
Returns superclass descriptor. Note that on the receiving side, the
superclass descriptor may be bound to a class that is not a superclass
of the subclass descriptor's bound class.
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.
Returns arrays of ObjectStreamFields representing the serializable
fields of the represented class. If copy is true, a clone of this class
descriptor's field array is returned, otherwise the array itself is
returned.
Looks up a serializable field of the represented class by name and type.
A specified type of null matches all types, Object.class matches all
non-primitive types, and any other non-null type matches assignable
types only. Returns matching field, or null if no match found.
Returns true if class descriptor represents a dynamic proxy class, false
otherwise.
Returns true if class descriptor represents an enum type, false
otherwise.
Returns true if represented class implements Externalizable, false
otherwise.
Returns true if represented class implements Serializable, false
otherwise.
Returns true if class descriptor represents externalizable class that
has written its data in 1.2 (block data) format, false otherwise.
Returns true if class descriptor represents serializable (but not
externalizable) class which has written its data via a custom
writeObject() method, false otherwise.
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. Otherwise, returns false.
Returns true if represented class is serializable (but not
externalizable) and defines a conformant writeObject method. Otherwise,
returns false.
Returns true if represented class is serializable (but not
externalizable) and defines a conformant readObject method. Otherwise,
returns false.
Returns true if represented class is serializable (but not
externalizable) and defines a conformant readObjectNoData method.
Otherwise, returns false.
Returns true if represented class is serializable or externalizable and
defines a conformant writeReplace method. Otherwise, returns false.
Returns true if represented class is serializable or externalizable and
defines a conformant readResolve method. Otherwise, returns false.
Creates a new instance of the represented class. If the class is
externalizable, invokes its public no-arg constructor; otherwise, if the
class is serializable, invokes the no-arg constructor of the first
non-serializable superclass. Throws UnsupportedOperationException if
this class descriptor is not associated with a class, if the associated
class is non-serializable or if the appropriate no-arg constructor is
inaccessible/unavailable.
Invokes the writeObject method of the represented serializable class.
Throws UnsupportedOperationException if this class descriptor is not
associated with a class, or if the class is externalizable,
non-serializable or does not define writeObject.
Invokes the readObject method of the represented serializable class.
Throws UnsupportedOperationException if this class descriptor is not
associated with a class, or if the class is externalizable,
non-serializable or does not define readObject.
Invokes the readObjectNoData method of the represented serializable
class. Throws UnsupportedOperationException if this class descriptor is
not associated with a class, or if the class is externalizable,
non-serializable or does not define readObjectNoData.
Invokes the writeReplace method of the represented serializable class and
returns the result. Throws UnsupportedOperationException if this class
descriptor is not associated with a class, or if the class is
non-serializable or does not define writeReplace.
Invokes the readResolve method of the represented serializable class and
returns the result. Throws UnsupportedOperationException if this class
descriptor is not associated with a class, or if the class is
non-serializable or does not define readResolve.
Class representing the portion of an object's serialized form allotted
to data described by a given class descriptor. If "hasData" is false,
the object's serialized form does not contain data associated with the
class descriptor.
class descriptor "occupying" this slot
true if serialized form includes data for this slot's descriptor
Returns array of ClassDataSlot instances representing the data layout
(including superclass data) for serialized objects described by this
class descriptor. ClassDataSlots are ordered by inheritance with those
containing "higher" superclasses appearing first. The final
ClassDataSlot contains a reference to this descriptor.
ObjectStreamClass.lookup(c, true), false));
ObjectStreamClass.lookup(c, true), false));
Returns aggregate size (in bytes) of marshalled primitive field values
for represented class.
Returns number of non-primitive serializable fields of represented
class.
Fetches the serializable primitive field values of object obj and
marshals them into byte array buf starting at offset 0. It is the
responsibility of the caller to ensure that obj is of the proper type if
non-null.
Sets the serializable primitive fields of object obj using values
unmarshalled from byte array buf starting at offset 0. It is the
responsibility of the caller to ensure that obj is of the proper type if
non-null.
Fetches the serializable object field values of object obj and stores
them in array vals starting at offset 0. It is the responsibility of
the caller to ensure that obj is of the proper type if non-null.
Sets the serializable object fields of object obj using values from
array vals starting at offset 0. It is the responsibility of the caller
to ensure that obj is of the proper type if non-null.
Calculates and sets serializable field offsets, as well as primitive
data size and object field count totals. Throws InvalidClassException
if fields are illegally ordered.
if (firstObjIndex == -1) { if (firstObjIndex != -1 &&
If given class is the same as the class associated with this class
descriptor, returns reference to this class descriptor. Otherwise,
returns variant of this class descriptor bound to given class.
Returns public no-arg constructor of given class, or null if none found.
Access checks are disabled on the returned constructor (if any), since
the defining class may still be non-public.
Returns subclass-accessible no-arg constructor of first non-serializable
superclass, or null if none found. Access checks are disabled on the
returned constructor (if any).
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. Access checks are disabled on the returned
method (if any).
return (cl == defCl) ? meth : null;
Returns non-static private method with given signature defined by given
class, or null if none found. Access checks are disabled on the
returned method (if any).
Returns true if classes are defined in the same runtime package, false
otherwise.
Returns package name of given class.
Compares class names for equality, ignoring package names. Returns true
if class names equal, false otherwise.
Returns JVM type signature for given class.
Returns JVM type signature for given list of parameters and return type.
for (int i = 0; i < paramTypes.length; i++) { 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).
} else if (th instanceof Error) { Returns ObjectStreamField array describing the serializable fields of
the given class. Serializable fields backed by an actual field of the
class are represented by ObjectStreamFields with corresponding non-null
Field objects. Throws InvalidClassException if the (explicitly
declared) serializable fields are invalid.
Returns serializable fields of given class as defined explicitly by a
"serialPersistentFields" field, or null if no appropriate
"serialPersistentFields" field is defined. Serializable fields backed
by an actual field of the class are represented by ObjectStreamFields
with corresponding non-null Field objects. For compatibility with past
releases, a "serialPersistentFields" field with a null value is
considered equivalent to not declaring "serialPersistentFields". Throws
InvalidClassException if the declared serializable fields are
invalid--e.g., if multiple fields share the same name.
if (serialPersistentFields == null) { } else if (serialPersistentFields.length == 0) { Set fieldNames = new HashSet(serialPersistentFields.length);
for (int i = 0; i < serialPersistentFields.length; i++) { "multiple serializable fields named " + fname);
if (boundFields[i] == null) { Returns array of ObjectStreamFields corresponding to all non-static
non-transient fields declared by given class. Each ObjectStreamField
contains a Field object for the field it represents. If no default
serializable fields exist, NO_FIELDS is returned.
for (int i = 0; i < clFields.length; i++) { Returns explicit serial version UID value declared by given class, or
null if none.
Computes the default serial version UID value for the given class.
classMods = (methods.length > 0) ?
for (int i = 0; i < interfaces.length; i++) { ifaceNames[i] = interfaces[i].getName();
for (int i = 0; i < ifaceNames.length; i++) { for (int i = 0; i < fields.length; i++) { for (int i = 0; i < fieldSigs.length; i++) { for (int i = 0; i < cons.length; i++) { for (int i = 0; i < consSigs.length; i++) { for (int i = 0; i < methods.length; i++) { comp = ms1.signature.compareTo(ms2.signature);
for (int i = 0; i < methSigs.length; i++) { for (int i = Math.min(hashBytes.length, 8) - 1; i >= 0; i--) { hash = (hash << 8) | (hashBytes[i] & 0xFF);
Returns true if the given class defines a static initializer method,
false otherwise.
Class for computing and caching field/constructor/method signatures
during serialVersionUID calculation.
Class for setting and retrieving serializable field values in batch.
handle for performing unsafe operations
number of primitive fields
private final long[] keys;
private final Class[] types;
Constructs FieldReflector capable of setting/getting values from the
subset of fields whose ObjectStreamFields contain non-null
reflective Field objects. ObjectStreamFields with null Fields are
treated as filler, for which get operations return default values
and set operations discard given values.
int nfields = fields.length;
keys = new long[nfields];
for (int i = 0; i < nfields; i++) { Returns list of ObjectStreamFields representing fields operated on
by this reflector. The shared/unshared values and Field objects
contained by ObjectStreamFields in the list reflect their bindings
to locally defined serializable fields.
Fetches the serializable primitive field values of object obj and
marshals them into byte array buf starting at offset 0. The caller
is responsible for ensuring that obj is of the proper type.
Sets the serializable primitive fields of object obj using values
unmarshalled from byte array buf starting at offset 0. The caller
is responsible for ensuring that obj is of the proper type.
Fetches the serializable object field values of object obj and
stores them in array vals starting at offset 0. The caller is
responsible for ensuring that obj is of the proper type.
Sets the serializable object fields of object obj using values from
array vals starting at offset 0. The caller is responsible for
ensuring that obj is of the proper type; however, attempts to set a
field with a value of the wrong type will trigger an appropriate
ClassCastException.
"cannot assign instance of " +
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). Throws InvalidClassException if unresolvable
type conflicts exist between the two sets of fields.
Class cl = (localDesc != null && fields.length > 0) ?
} while (ref != null && entry == null);
} else if (entry == null) { } else if (entry instanceof Error) { FieldReflector cache lookup key. Keys are considered equal if they
refer to the same class and equivalent field formats.
for (int i = 0; i < fields.length; i++) { : ((referent = get()) != null) &&
(referent == other.get())) &&
Matches given set of serializable fields with serializable fields
obtained from the given local class descriptor (which contain bindings
to reflective Field objects). Returns list of ObjectStreamFields in
which each ObjectStreamField whose signature matches that of a local
field contains a Field object for that field; unmatched
ObjectStreamFields contain null Field objects. Shared/unshared settings
of the returned ObjectStreamFields also reflect those of matched local
ObjectStreamFields. Throws InvalidClassException if unresolvable type
conflicts exist between the two sets of fields.
for (int i = 0; i < fields.length; i++) { for (int j = 0; j < localFields.length; j++) { "incompatible types for field " + f.getName());
Removes from the specified map any keys that have been enqueued
on the specified reference queue.
while((ref = queue.poll()) != null) { Weak key for Class objects.
saved value of the referent's identity hash code, to maintain
a consistent hash code after the referent has been cleared
Create a new WeakClassKey to the given object, registered
with a queue.
Returns the identity hash code of the original referent.
Returns true if the given object is this identical
WeakClassKey instance, or, if this object's referent has not
been cleared, if the given object is another WeakClassKey
instance with the identical non-null referent as this one.
return (referent != null) &&