- Java Object Serialization Specification: B — Exceptions In Object Serialization
- ObjectStreamException
- InvalidClassException
- NotSerializableException
- StreamCorruptedException
- NotActiveException
- InvalidObjectException
- OptionalDataException
- WriteAbortedException
- Java Object Serialization Specification: B — Exceptions In Object Serialization
- ObjectStreamException
- InvalidClassException
- NotSerializableException
- StreamCorruptedException
- NotActiveException
- InvalidObjectException
- OptionalDataException
- WriteAbortedException
- Java Object Serialization Specification: B — Exceptions In Object Serialization
- ObjectStreamException
- InvalidClassException
- NotSerializableException
- StreamCorruptedException
- NotActiveException
- InvalidObjectException
- OptionalDataException
- WriteAbortedException
- Java: Serialization Exception Handling
- References
- Share this with others:
Java Object Serialization Specification: B — Exceptions In Object Serialization
All exceptions thrown by serialization classes are subclasses of ObjectStreamException which is a subclass of IOException .
ObjectStreamException
Superclass of all serialization exceptions.
InvalidClassException
Thrown when a class cannot be used to restore objects for any of these reasons:
- The class does not match the serial version of the class in the stream.
- The class contains fields with invalid primitive data types.
- The Externalizable class does not have a public no-arg constructor.
- The Serializable class can not access the no-arg constructor of its closest non-Serializable superclass.
NotSerializableException
Thrown by a readObject or writeObject method to terminate serialization or deserialization.
StreamCorruptedException
- If the stream header is invalid.
- If control information not found.
- If control information is invalid.
- JDK 1.1.5 or less attempts to call readExternal on a PROTOCOL_VERSION_2 stream.
NotActiveException
Thrown if writeObject state is invalid within the following ObjectOutputStream methods:
Thrown if readObject state is invalid within the following ObjectInputStream methods:
InvalidObjectException
Thrown when a restored object cannot be made valid.
OptionalDataException
Thrown by readObject when there is primitive data in the stream and an object is expected. The length field of the exception indicates the number of bytes that are available in the current block.
WriteAbortedException
Thrown when reading a stream terminated by an exception that occurred while the stream was being written.
Copyright © 1993, 2023, Oracle and/or its affiliates, 500 Oracle Parkway, Redwood Shores, CA 94065 USA.
All rights reserved. Use is subject to license terms and the documentation redistribution policy.
Java Object Serialization Specification: B — Exceptions In Object Serialization
All exceptions thrown by serialization classes are subclasses of ObjectStreamException which is a subclass of IOException .
ObjectStreamException
Superclass of all serialization exceptions.
InvalidClassException
Thrown when a class cannot be used to restore objects for any of these reasons:
- The class does not match the serial version of the class in the stream.
- The class contains fields with invalid primitive data types.
- The Externalizable class does not have a public no-arg constructor.
- The Serializable class can not access the no-arg constructor of its closest non-Serializable superclass.
NotSerializableException
Thrown by a readObject or writeObject method to terminate serialization or deserialization.
StreamCorruptedException
- If the stream header is invalid.
- If control information not found.
- If control information is invalid.
- JDK 1.1.5 or less attempts to call readExternal on a PROTOCOL_VERSION_2 stream.
NotActiveException
Thrown if writeObject state is invalid within the following ObjectOutputStream methods:
Thrown if readObject state is invalid within the following ObjectInputStream methods:
InvalidObjectException
Thrown when a restored object cannot be made valid.
OptionalDataException
Thrown by readObject when there is primitive data in the stream and an object is expected. The length field of the exception indicates the number of bytes that are available in the current block.
WriteAbortedException
Thrown when reading a stream terminated by an exception that occurred while the stream was being written.
Copyright © 2005, 2017, Oracle and/or its affiliates. All rights reserved.
Java Object Serialization Specification: B — Exceptions In Object Serialization
All exceptions thrown by serialization classes are subclasses of ObjectStreamException which is a subclass of IOException .
ObjectStreamException
Superclass of all serialization exceptions.
InvalidClassException
Thrown when a class cannot be used to restore objects for any of these reasons:
- The class does not match the serial version of the class in the stream.
- The class contains fields with invalid primitive data types.
- The Externalizable class does not have a public no-arg constructor.
- The Serializable class can not access the no-arg constructor of its closest non-Serializable superclass.
NotSerializableException
Thrown by a readObject or writeObject method to terminate serialization or deserialization.
StreamCorruptedException
- If the stream header is invalid.
- If control information not found.
- If control information is invalid.
- JDK 1.1.5 or less attempts to call readExternal on a PROTOCOL_VERSION_2 stream.
NotActiveException
Thrown if writeObject state is invalid within the following ObjectOutputStream methods:
Thrown if readObject state is invalid within the following ObjectInputStream methods:
InvalidObjectException
Thrown when a restored object cannot be made valid.
OptionalDataException
Thrown by readObject when there is primitive data in the stream and an object is expected. The length field of the exception indicates the number of bytes that are available in the current block.
WriteAbortedException
Thrown when reading a stream terminated by an exception that occurred while the stream was being written.
Copyright © 1993, 2023, Oracle and/or its affiliates, 500 Oracle Parkway, Redwood Shores, CA 94065 USA.
All rights reserved. Use is subject to license terms and the documentation redistribution policy.
Java: Serialization Exception Handling
All these exceptions are related to serialization which occurred while doing serialization and deserialization of objects. These exceptions are subclasses of ObjectStreamException which is a subclass of IOException.
Pre-requisite:
- The class does not match the serialversionUID of the class in the stream.
- The class contains properties with invalid primitive data types.
- The Externalizable class doesn’t have a public no-arg constructor.
- The Serializable class can’t access the no-arg constructor of its closest non-serializable superclass.
- If the stream header is invalid.
- If control information not found.
- If control information is invalid.
- JDK 1.1.5 or fewer attempts to call readExternal on a PROTOCOL_VERSION_2 stream.
This exception has thrown if readObject state is invalid within the following ObjectInputStream methods:
- Java: transient Serialization
- Java: static Serialization
- Java: Externalizable/Custom Serialization
- Java: Object Serialization with Inheritance
- Java: Object Externalizable Serialization with Inheritance
- Java: Array and Collection Serialization
- Java: Serialization Exception Handling