-
Notifications
You must be signed in to change notification settings - Fork 2k
Expand file tree
/
Copy pathMissingVoidConstructorOnExternalizable.qhelp
More file actions
49 lines (38 loc) · 1.45 KB
/
MissingVoidConstructorOnExternalizable.qhelp
File metadata and controls
49 lines (38 loc) · 1.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
<!DOCTYPE qhelp PUBLIC
"-//Semmle//qhelp//EN"
"qhelp.dtd">
<qhelp>
<overview>
<p>
A class that implements <code>java.io.Externalizable</code> must have a public no-argument
constructor. The constructor is used by the Java serialization framework when it creates the object
during deserialization. If the class does not define such a constructor, the Java
serialization framework throws an <code>InvalidClassException</code>.
</p>
<p>
The Java Development Kit API documentation for <code>Externalizable</code> states:
</p>
<blockquote>
<p>When an <code>Externalizable</code> object is reconstructed, an instance is created using the public no-arg constructor,
then the <code>readExternal</code> method called.</p>
</blockquote>
</overview>
<recommendation>
<p>
Make sure that externalizable classes always have a no-argument constructor.
</p>
</recommendation>
<example>
<p>In the following example, <code>WrongMemo</code> does not declare a public no-argument constructor.
When the Java serialization framework tries to deserialize the object, an <code>InvalidClassException</code>
is thrown. However, <code>Memo</code> does declare a public no-argument constructor, so that the
object is deserialized successfully.</p>
<sample src="MissingVoidConstructorOnExternalizable.java" />
</example>
<references>
<li>
Java API Documentation:
<a href="http://docs.oracle.com/javase/6/docs/api/java/io/Externalizable.html">Externalizable</a>.
</li>
</references>
</qhelp>