author | alanb |
Thu, 18 Aug 2011 16:47:20 +0100 | |
changeset 10347 | 1c9efe1ec7d3 |
parent 9734 | b33a24d77590 |
child 13020 | 2122dfcf3677 |
permissions | -rw-r--r-- |
7030
90cf66131063
6559775: Race allows defaultReadObject to be invoked instead of readFields during deserialization
skoppar
parents:
diff
changeset
|
1 |
/* |
9734
b33a24d77590
7044486: open jdk repos have files with incorrect copyright headers, which can end up in src bundles
katleman
parents:
8158
diff
changeset
|
2 |
* Copyright (c) 2006, 2010, Oracle and/or its affiliates. All rights reserved. |
7030
90cf66131063
6559775: Race allows defaultReadObject to be invoked instead of readFields during deserialization
skoppar
parents:
diff
changeset
|
3 |
* ORACLE PROPRIETARY/CONFIDENTIAL. Use is subject to license terms. |
90cf66131063
6559775: Race allows defaultReadObject to be invoked instead of readFields during deserialization
skoppar
parents:
diff
changeset
|
4 |
*/ |
90cf66131063
6559775: Race allows defaultReadObject to be invoked instead of readFields during deserialization
skoppar
parents:
diff
changeset
|
5 |
|
90cf66131063
6559775: Race allows defaultReadObject to be invoked instead of readFields during deserialization
skoppar
parents:
diff
changeset
|
6 |
package java.io; |
90cf66131063
6559775: Race allows defaultReadObject to be invoked instead of readFields during deserialization
skoppar
parents:
diff
changeset
|
7 |
|
90cf66131063
6559775: Race allows defaultReadObject to be invoked instead of readFields during deserialization
skoppar
parents:
diff
changeset
|
8 |
/** |
90cf66131063
6559775: Race allows defaultReadObject to be invoked instead of readFields during deserialization
skoppar
parents:
diff
changeset
|
9 |
* Context during upcalls from object stream to class-defined |
90cf66131063
6559775: Race allows defaultReadObject to be invoked instead of readFields during deserialization
skoppar
parents:
diff
changeset
|
10 |
* readObject/writeObject methods. |
90cf66131063
6559775: Race allows defaultReadObject to be invoked instead of readFields during deserialization
skoppar
parents:
diff
changeset
|
11 |
* Holds object currently being deserialized and descriptor for current class. |
90cf66131063
6559775: Race allows defaultReadObject to be invoked instead of readFields during deserialization
skoppar
parents:
diff
changeset
|
12 |
* |
90cf66131063
6559775: Race allows defaultReadObject to be invoked instead of readFields during deserialization
skoppar
parents:
diff
changeset
|
13 |
* This context keeps track of the thread it was constructed on, and allows |
90cf66131063
6559775: Race allows defaultReadObject to be invoked instead of readFields during deserialization
skoppar
parents:
diff
changeset
|
14 |
* only a single call of defaultReadObject, readFields, defaultWriteObject |
90cf66131063
6559775: Race allows defaultReadObject to be invoked instead of readFields during deserialization
skoppar
parents:
diff
changeset
|
15 |
* or writeFields which must be invoked on the same thread before the class's |
90cf66131063
6559775: Race allows defaultReadObject to be invoked instead of readFields during deserialization
skoppar
parents:
diff
changeset
|
16 |
* readObject/writeObject method has returned. |
90cf66131063
6559775: Race allows defaultReadObject to be invoked instead of readFields during deserialization
skoppar
parents:
diff
changeset
|
17 |
* If not set to the current thread, the getObj method throws NotActiveException. |
90cf66131063
6559775: Race allows defaultReadObject to be invoked instead of readFields during deserialization
skoppar
parents:
diff
changeset
|
18 |
*/ |
90cf66131063
6559775: Race allows defaultReadObject to be invoked instead of readFields during deserialization
skoppar
parents:
diff
changeset
|
19 |
final class SerialCallbackContext { |
90cf66131063
6559775: Race allows defaultReadObject to be invoked instead of readFields during deserialization
skoppar
parents:
diff
changeset
|
20 |
private final Object obj; |
90cf66131063
6559775: Race allows defaultReadObject to be invoked instead of readFields during deserialization
skoppar
parents:
diff
changeset
|
21 |
private final ObjectStreamClass desc; |
90cf66131063
6559775: Race allows defaultReadObject to be invoked instead of readFields during deserialization
skoppar
parents:
diff
changeset
|
22 |
/** |
90cf66131063
6559775: Race allows defaultReadObject to be invoked instead of readFields during deserialization
skoppar
parents:
diff
changeset
|
23 |
* Thread this context is in use by. |
90cf66131063
6559775: Race allows defaultReadObject to be invoked instead of readFields during deserialization
skoppar
parents:
diff
changeset
|
24 |
* As this only works in one thread, we do not need to worry about thread-safety. |
90cf66131063
6559775: Race allows defaultReadObject to be invoked instead of readFields during deserialization
skoppar
parents:
diff
changeset
|
25 |
*/ |
90cf66131063
6559775: Race allows defaultReadObject to be invoked instead of readFields during deserialization
skoppar
parents:
diff
changeset
|
26 |
private Thread thread; |
90cf66131063
6559775: Race allows defaultReadObject to be invoked instead of readFields during deserialization
skoppar
parents:
diff
changeset
|
27 |
|
90cf66131063
6559775: Race allows defaultReadObject to be invoked instead of readFields during deserialization
skoppar
parents:
diff
changeset
|
28 |
public SerialCallbackContext(Object obj, ObjectStreamClass desc) { |
90cf66131063
6559775: Race allows defaultReadObject to be invoked instead of readFields during deserialization
skoppar
parents:
diff
changeset
|
29 |
this.obj = obj; |
90cf66131063
6559775: Race allows defaultReadObject to be invoked instead of readFields during deserialization
skoppar
parents:
diff
changeset
|
30 |
this.desc = desc; |
90cf66131063
6559775: Race allows defaultReadObject to be invoked instead of readFields during deserialization
skoppar
parents:
diff
changeset
|
31 |
this.thread = Thread.currentThread(); |
90cf66131063
6559775: Race allows defaultReadObject to be invoked instead of readFields during deserialization
skoppar
parents:
diff
changeset
|
32 |
} |
90cf66131063
6559775: Race allows defaultReadObject to be invoked instead of readFields during deserialization
skoppar
parents:
diff
changeset
|
33 |
|
90cf66131063
6559775: Race allows defaultReadObject to be invoked instead of readFields during deserialization
skoppar
parents:
diff
changeset
|
34 |
public Object getObj() throws NotActiveException { |
90cf66131063
6559775: Race allows defaultReadObject to be invoked instead of readFields during deserialization
skoppar
parents:
diff
changeset
|
35 |
checkAndSetUsed(); |
90cf66131063
6559775: Race allows defaultReadObject to be invoked instead of readFields during deserialization
skoppar
parents:
diff
changeset
|
36 |
return obj; |
90cf66131063
6559775: Race allows defaultReadObject to be invoked instead of readFields during deserialization
skoppar
parents:
diff
changeset
|
37 |
} |
90cf66131063
6559775: Race allows defaultReadObject to be invoked instead of readFields during deserialization
skoppar
parents:
diff
changeset
|
38 |
|
90cf66131063
6559775: Race allows defaultReadObject to be invoked instead of readFields during deserialization
skoppar
parents:
diff
changeset
|
39 |
public ObjectStreamClass getDesc() { |
90cf66131063
6559775: Race allows defaultReadObject to be invoked instead of readFields during deserialization
skoppar
parents:
diff
changeset
|
40 |
return desc; |
90cf66131063
6559775: Race allows defaultReadObject to be invoked instead of readFields during deserialization
skoppar
parents:
diff
changeset
|
41 |
} |
90cf66131063
6559775: Race allows defaultReadObject to be invoked instead of readFields during deserialization
skoppar
parents:
diff
changeset
|
42 |
|
90cf66131063
6559775: Race allows defaultReadObject to be invoked instead of readFields during deserialization
skoppar
parents:
diff
changeset
|
43 |
private void checkAndSetUsed() throws NotActiveException { |
90cf66131063
6559775: Race allows defaultReadObject to be invoked instead of readFields during deserialization
skoppar
parents:
diff
changeset
|
44 |
if (thread != Thread.currentThread()) { |
90cf66131063
6559775: Race allows defaultReadObject to be invoked instead of readFields during deserialization
skoppar
parents:
diff
changeset
|
45 |
throw new NotActiveException( |
90cf66131063
6559775: Race allows defaultReadObject to be invoked instead of readFields during deserialization
skoppar
parents:
diff
changeset
|
46 |
"not in readObject invocation or fields already read"); |
90cf66131063
6559775: Race allows defaultReadObject to be invoked instead of readFields during deserialization
skoppar
parents:
diff
changeset
|
47 |
} |
90cf66131063
6559775: Race allows defaultReadObject to be invoked instead of readFields during deserialization
skoppar
parents:
diff
changeset
|
48 |
thread = null; |
90cf66131063
6559775: Race allows defaultReadObject to be invoked instead of readFields during deserialization
skoppar
parents:
diff
changeset
|
49 |
} |
90cf66131063
6559775: Race allows defaultReadObject to be invoked instead of readFields during deserialization
skoppar
parents:
diff
changeset
|
50 |
|
90cf66131063
6559775: Race allows defaultReadObject to be invoked instead of readFields during deserialization
skoppar
parents:
diff
changeset
|
51 |
public void setUsed() { |
90cf66131063
6559775: Race allows defaultReadObject to be invoked instead of readFields during deserialization
skoppar
parents:
diff
changeset
|
52 |
thread = null; |
90cf66131063
6559775: Race allows defaultReadObject to be invoked instead of readFields during deserialization
skoppar
parents:
diff
changeset
|
53 |
} |
90cf66131063
6559775: Race allows defaultReadObject to be invoked instead of readFields during deserialization
skoppar
parents:
diff
changeset
|
54 |
} |