...
Extending a class or interface that implements Serializable
should be avoided whenever possible. When extension of such a class is necessary, inappropriate serialization of the subclass can be prohibited by throwing NotSerializableException
from a custom writeObject()
or readResolvereadObject()
method, defined in the subclass SensitiveClass
. Note that the custom writeObject()
or readResolvereadObject()
methods must be declared private or final to prevent a malicious subclass from overriding them.
Code Block | ||
---|---|---|
| ||
class SensitiveClass extends Number { // ... private final Object readResolve(readObject(java.io.ObjectInputStream in) throws NotSerializableException { throw new NotSerializableException(); } } |
...
<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="8d245021d9b763fd-763ed5cb-4f4f41f4-af8eaa01-4cf3ab82c842eb74a3c30d42"><ac:plain-text-body><![CDATA[ | [[Bloch 2005 | AA. References#Bloch 05]] | Puzzle 83. Dyslexic monotheism | ]]></ac:plain-text-body></ac:structured-macro> | |
<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="eb1f17ac1c1c9bf6-1d523b48-42224502-bdd7acc4-c8a0fea3505e1b1d01b040c4"><ac:plain-text-body><![CDATA[ | [[Bloch 2001 | AA. References#Bloch 01]] | Item 1. Enforce the singleton property with a private constructor | ]]></ac:plain-text-body></ac:structured-macro> | |
<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="42f6ea6b1a121532-7e7456be-45194375-a771b442-ae6de05b77e40aead1b52409"><ac:plain-text-body><![CDATA[ | [[Greanier 2000 | AA. References#Greanier 00]] | [Discover the Secrets of the Java Serialization API | http://java.sun.com/developer/technicalArticles/Programming/serialization/] | ]]></ac:plain-text-body></ac:structured-macro> |
<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="4a3617b486fc0a0a-4cd09f00-45d64f16-98fcb67d-71a407534938afbc99b88f6a"><ac:plain-text-body><![CDATA[ | [[Harold 1999 | AA. References#Harold 99]] |
| ]]></ac:plain-text-body></ac:structured-macro> | |
<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="e565c8c928da0ab9-517381c7-41504b3d-8f99b61f-ff6b27e062470e394c3c7469"><ac:plain-text-body><![CDATA[ | [[JLS 2005 | AA. References#JLS 05]] | [Transient Modifier | http://java.sun.com/docs/books/jls/third_edition/html/classes.html#37020] | ]]></ac:plain-text-body></ac:structured-macro> |
<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="0f2dc1038f190f85-d36793a2-48db497a-b437b049-8db1590e6c195f2fc50fdb79"><ac:plain-text-body><![CDATA[ | [[Long 2005 | AA. References#Long 05]] | Section 2.4, Serialization | ]]></ac:plain-text-body></ac:structured-macro> | |
<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="13aebb752a0f8df9-661a4812-46d94695-94d6afbf-a72289027ec05da5d08ef076"><ac:plain-text-body><![CDATA[ | [[Sun 2006 | AA. References#Sun 06]] | Serialization Specification, A.4, Preventing Serialization of Sensitive Data | ]]></ac:plain-text-body></ac:structured-macro> |
...