jdk/src/java.base/share/specs/serialization/exceptions.md
author ihse
Sun, 23 Apr 2017 21:33:29 +0200
changeset 44787 0b323ea6d5ad
permissions -rw-r--r--
8179022: Add serialization spec as markdown Reviewed-by: erikj, mchung, rriggs
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
44787
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
     1
---
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
     2
# Copyright (c) 2005, 2017, Oracle and/or its affiliates. All rights reserved.
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
     3
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
     4
#
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
     5
# This code is free software; you can redistribute it and/or modify it
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
     6
# under the terms of the GNU General Public License version 2 only, as
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
     7
# published by the Free Software Foundation.
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
     8
#
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
     9
# This code is distributed in the hope that it will be useful, but WITHOUT
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
    10
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
    11
# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
    12
# version 2 for more details (a copy is included in the LICENSE file that
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
    13
# accompanied this code).
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
    14
#
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
    15
# You should have received a copy of the GNU General Public License version
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
    16
# 2 along with this work; if not, write to the Free Software Foundation,
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
    17
# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
    18
#
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
    19
# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
    20
# or visit www.oracle.com if you need additional information or have any
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
    21
# questions.
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
    22
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
    23
include-before: '[CONTENTS](index.html) | [PREV](security.html) | [NEXT](examples.html)'
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
    24
include-after: '[CONTENTS](index.html) | [PREV](security.html) | [NEXT](examples.html)'
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
    25
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
    26
title: 'Java Object Serialization Specification: B - Exceptions In Object Serialization'
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
    27
---
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
    28
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
    29
-------------------------------------------------------------------------------
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
    30
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
    31
All exceptions thrown by serialization classes are subclasses of
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
    32
`ObjectStreamException` which is a subclass of `IOException`.
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
    33
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
    34
### `ObjectStreamException`
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
    35
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
    36
Superclass of all serialization exceptions.
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
    37
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
    38
### `InvalidClassException`
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
    39
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
    40
Thrown when a class cannot be used to restore objects for any of these reasons:
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
    41
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
    42
-   The class does not match the serial version of the class in the stream.
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
    43
-   The class contains fields with invalid primitive data types.
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
    44
-   The `Externalizable` class does not have a public no-arg constructor.
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
    45
-   The `Serializable` class can not access the no-arg constructor of its
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
    46
    closest non-Serializable superclass.
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
    47
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
    48
### `NotSerializableException`
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
    49
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
    50
Thrown by a `readObject` or `writeObject` method to terminate serialization or
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
    51
deserialization.
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
    52
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
    53
### `StreamCorruptedException`
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
    54
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
    55
Thrown:
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
    56
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
    57
-   If the stream header is invalid.
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
    58
-   If control information not found.
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
    59
-   If control information is invalid.
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
    60
-   JDK 1.1.5 or less attempts to call `readExternal` on a `PROTOCOL_VERSION_2`
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
    61
    stream.
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
    62
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
    63
### `NotActiveException`
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
    64
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
    65
Thrown if `writeObject` state is invalid within the following
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
    66
`ObjectOutputStream` methods:
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
    67
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
    68
-   `defaultWriteObject`
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
    69
-   `putFields`
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
    70
-   `writeFields`
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
    71
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
    72
Thrown if `readObject` state is invalid within the following
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
    73
`ObjectInputStream` methods:
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
    74
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
    75
-   `defaultReadObject`
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
    76
-   `readFields`
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
    77
-   `registerValidation`
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
    78
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
    79
### `InvalidObjectException`
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
    80
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
    81
Thrown when a restored object cannot be made valid.
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
    82
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
    83
### `OptionalDataException`
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
    84
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
    85
Thrown by `readObject` when there is primitive data in the stream and an object
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
    86
is expected. The length field of the exception indicates the number of bytes
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
    87
that are available in the current block.
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
    88
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
    89
### `WriteAbortedException`
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
    90
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
    91
Thrown when reading a stream terminated by an exception that occurred while the
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
    92
stream was being written.
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
    93
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
    94
-------------------------------------------------------------------------------
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
    95
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
    96
*[Copyright](../../../legal/SMICopyright.html) © 2005, 2017, Oracle
0b323ea6d5ad 8179022: Add serialization spec as markdown
ihse
parents:
diff changeset
    97
and/or its affiliates. All rights reserved.*