author | chegar |
Thu, 06 Feb 2014 14:45:12 +0000 (2014-02-06) | |
changeset 22936 | 1263cd9144d7 |
parent 13020 | 2122dfcf3677 |
permissions | -rw-r--r-- |
13020
2122dfcf3677
7156963: Incorrect copyright header in java/io/SerialCallbackContext
coffeys
parents:
9734
diff
changeset
|
1 |
/* |
2122dfcf3677
7156963: Incorrect copyright header in java/io/SerialCallbackContext
coffeys
parents:
9734
diff
changeset
|
2 |
* Copyright (c) 2006, 2012, Oracle and/or its affiliates. All rights reserved. |
2122dfcf3677
7156963: Incorrect copyright header in java/io/SerialCallbackContext
coffeys
parents:
9734
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
2122dfcf3677
7156963: Incorrect copyright header in java/io/SerialCallbackContext
coffeys
parents:
9734
diff
changeset
|
4 |
* |
2122dfcf3677
7156963: Incorrect copyright header in java/io/SerialCallbackContext
coffeys
parents:
9734
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
2122dfcf3677
7156963: Incorrect copyright header in java/io/SerialCallbackContext
coffeys
parents:
9734
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
2122dfcf3677
7156963: Incorrect copyright header in java/io/SerialCallbackContext
coffeys
parents:
9734
diff
changeset
|
7 |
* published by the Free Software Foundation. Oracle designates this |
2122dfcf3677
7156963: Incorrect copyright header in java/io/SerialCallbackContext
coffeys
parents:
9734
diff
changeset
|
8 |
* particular file as subject to the "Classpath" exception as provided |
2122dfcf3677
7156963: Incorrect copyright header in java/io/SerialCallbackContext
coffeys
parents:
9734
diff
changeset
|
9 |
* by Oracle in the LICENSE file that accompanied this code. |
2122dfcf3677
7156963: Incorrect copyright header in java/io/SerialCallbackContext
coffeys
parents:
9734
diff
changeset
|
10 |
* |
2122dfcf3677
7156963: Incorrect copyright header in java/io/SerialCallbackContext
coffeys
parents:
9734
diff
changeset
|
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
2122dfcf3677
7156963: Incorrect copyright header in java/io/SerialCallbackContext
coffeys
parents:
9734
diff
changeset
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
2122dfcf3677
7156963: Incorrect copyright header in java/io/SerialCallbackContext
coffeys
parents:
9734
diff
changeset
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
2122dfcf3677
7156963: Incorrect copyright header in java/io/SerialCallbackContext
coffeys
parents:
9734
diff
changeset
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
2122dfcf3677
7156963: Incorrect copyright header in java/io/SerialCallbackContext
coffeys
parents:
9734
diff
changeset
|
15 |
* accompanied this code). |
2122dfcf3677
7156963: Incorrect copyright header in java/io/SerialCallbackContext
coffeys
parents:
9734
diff
changeset
|
16 |
* |
2122dfcf3677
7156963: Incorrect copyright header in java/io/SerialCallbackContext
coffeys
parents:
9734
diff
changeset
|
17 |
* You should have received a copy of the GNU General Public License version |
2122dfcf3677
7156963: Incorrect copyright header in java/io/SerialCallbackContext
coffeys
parents:
9734
diff
changeset
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
2122dfcf3677
7156963: Incorrect copyright header in java/io/SerialCallbackContext
coffeys
parents:
9734
diff
changeset
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
2122dfcf3677
7156963: Incorrect copyright header in java/io/SerialCallbackContext
coffeys
parents:
9734
diff
changeset
|
20 |
* |
2122dfcf3677
7156963: Incorrect copyright header in java/io/SerialCallbackContext
coffeys
parents:
9734
diff
changeset
|
21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
2122dfcf3677
7156963: Incorrect copyright header in java/io/SerialCallbackContext
coffeys
parents:
9734
diff
changeset
|
22 |
* or visit www.oracle.com if you need additional information or have any |
2122dfcf3677
7156963: Incorrect copyright header in java/io/SerialCallbackContext
coffeys
parents:
9734
diff
changeset
|
23 |
* questions. |
2122dfcf3677
7156963: Incorrect copyright header in java/io/SerialCallbackContext
coffeys
parents:
9734
diff
changeset
|
24 |
*/ |
7030
90cf66131063
6559775: Race allows defaultReadObject to be invoked instead of readFields during deserialization
skoppar
parents:
diff
changeset
|
25 |
|
13020
2122dfcf3677
7156963: Incorrect copyright header in java/io/SerialCallbackContext
coffeys
parents:
9734
diff
changeset
|
26 |
package java.io; |
7030
90cf66131063
6559775: Race allows defaultReadObject to be invoked instead of readFields during deserialization
skoppar
parents:
diff
changeset
|
27 |
|
13020
2122dfcf3677
7156963: Incorrect copyright header in java/io/SerialCallbackContext
coffeys
parents:
9734
diff
changeset
|
28 |
/** |
2122dfcf3677
7156963: Incorrect copyright header in java/io/SerialCallbackContext
coffeys
parents:
9734
diff
changeset
|
29 |
* Context during upcalls from object stream to class-defined |
2122dfcf3677
7156963: Incorrect copyright header in java/io/SerialCallbackContext
coffeys
parents:
9734
diff
changeset
|
30 |
* readObject/writeObject methods. |
2122dfcf3677
7156963: Incorrect copyright header in java/io/SerialCallbackContext
coffeys
parents:
9734
diff
changeset
|
31 |
* Holds object currently being deserialized and descriptor for current class. |
2122dfcf3677
7156963: Incorrect copyright header in java/io/SerialCallbackContext
coffeys
parents:
9734
diff
changeset
|
32 |
* |
2122dfcf3677
7156963: Incorrect copyright header in java/io/SerialCallbackContext
coffeys
parents:
9734
diff
changeset
|
33 |
* This context keeps track of the thread it was constructed on, and allows |
2122dfcf3677
7156963: Incorrect copyright header in java/io/SerialCallbackContext
coffeys
parents:
9734
diff
changeset
|
34 |
* only a single call of defaultReadObject, readFields, defaultWriteObject |
2122dfcf3677
7156963: Incorrect copyright header in java/io/SerialCallbackContext
coffeys
parents:
9734
diff
changeset
|
35 |
* or writeFields which must be invoked on the same thread before the class's |
2122dfcf3677
7156963: Incorrect copyright header in java/io/SerialCallbackContext
coffeys
parents:
9734
diff
changeset
|
36 |
* readObject/writeObject method has returned. |
2122dfcf3677
7156963: Incorrect copyright header in java/io/SerialCallbackContext
coffeys
parents:
9734
diff
changeset
|
37 |
* If not set to the current thread, the getObj method throws NotActiveException. |
2122dfcf3677
7156963: Incorrect copyright header in java/io/SerialCallbackContext
coffeys
parents:
9734
diff
changeset
|
38 |
*/ |
2122dfcf3677
7156963: Incorrect copyright header in java/io/SerialCallbackContext
coffeys
parents:
9734
diff
changeset
|
39 |
final class SerialCallbackContext { |
2122dfcf3677
7156963: Incorrect copyright header in java/io/SerialCallbackContext
coffeys
parents:
9734
diff
changeset
|
40 |
private final Object obj; |
2122dfcf3677
7156963: Incorrect copyright header in java/io/SerialCallbackContext
coffeys
parents:
9734
diff
changeset
|
41 |
private final ObjectStreamClass desc; |
2122dfcf3677
7156963: Incorrect copyright header in java/io/SerialCallbackContext
coffeys
parents:
9734
diff
changeset
|
42 |
/** |
2122dfcf3677
7156963: Incorrect copyright header in java/io/SerialCallbackContext
coffeys
parents:
9734
diff
changeset
|
43 |
* Thread this context is in use by. |
2122dfcf3677
7156963: Incorrect copyright header in java/io/SerialCallbackContext
coffeys
parents:
9734
diff
changeset
|
44 |
* As this only works in one thread, we do not need to worry about thread-safety. |
2122dfcf3677
7156963: Incorrect copyright header in java/io/SerialCallbackContext
coffeys
parents:
9734
diff
changeset
|
45 |
*/ |
2122dfcf3677
7156963: Incorrect copyright header in java/io/SerialCallbackContext
coffeys
parents:
9734
diff
changeset
|
46 |
private Thread thread; |
7030
90cf66131063
6559775: Race allows defaultReadObject to be invoked instead of readFields during deserialization
skoppar
parents:
diff
changeset
|
47 |
|
13020
2122dfcf3677
7156963: Incorrect copyright header in java/io/SerialCallbackContext
coffeys
parents:
9734
diff
changeset
|
48 |
public SerialCallbackContext(Object obj, ObjectStreamClass desc) { |
2122dfcf3677
7156963: Incorrect copyright header in java/io/SerialCallbackContext
coffeys
parents:
9734
diff
changeset
|
49 |
this.obj = obj; |
2122dfcf3677
7156963: Incorrect copyright header in java/io/SerialCallbackContext
coffeys
parents:
9734
diff
changeset
|
50 |
this.desc = desc; |
2122dfcf3677
7156963: Incorrect copyright header in java/io/SerialCallbackContext
coffeys
parents:
9734
diff
changeset
|
51 |
this.thread = Thread.currentThread(); |
2122dfcf3677
7156963: Incorrect copyright header in java/io/SerialCallbackContext
coffeys
parents:
9734
diff
changeset
|
52 |
} |
2122dfcf3677
7156963: Incorrect copyright header in java/io/SerialCallbackContext
coffeys
parents:
9734
diff
changeset
|
53 |
|
2122dfcf3677
7156963: Incorrect copyright header in java/io/SerialCallbackContext
coffeys
parents:
9734
diff
changeset
|
54 |
public Object getObj() throws NotActiveException { |
2122dfcf3677
7156963: Incorrect copyright header in java/io/SerialCallbackContext
coffeys
parents:
9734
diff
changeset
|
55 |
checkAndSetUsed(); |
2122dfcf3677
7156963: Incorrect copyright header in java/io/SerialCallbackContext
coffeys
parents:
9734
diff
changeset
|
56 |
return obj; |
2122dfcf3677
7156963: Incorrect copyright header in java/io/SerialCallbackContext
coffeys
parents:
9734
diff
changeset
|
57 |
} |
7030
90cf66131063
6559775: Race allows defaultReadObject to be invoked instead of readFields during deserialization
skoppar
parents:
diff
changeset
|
58 |
|
13020
2122dfcf3677
7156963: Incorrect copyright header in java/io/SerialCallbackContext
coffeys
parents:
9734
diff
changeset
|
59 |
public ObjectStreamClass getDesc() { |
2122dfcf3677
7156963: Incorrect copyright header in java/io/SerialCallbackContext
coffeys
parents:
9734
diff
changeset
|
60 |
return desc; |
2122dfcf3677
7156963: Incorrect copyright header in java/io/SerialCallbackContext
coffeys
parents:
9734
diff
changeset
|
61 |
} |
7030
90cf66131063
6559775: Race allows defaultReadObject to be invoked instead of readFields during deserialization
skoppar
parents:
diff
changeset
|
62 |
|
22936 | 63 |
public void checkAndSetUsed() throws NotActiveException { |
13020
2122dfcf3677
7156963: Incorrect copyright header in java/io/SerialCallbackContext
coffeys
parents:
9734
diff
changeset
|
64 |
if (thread != Thread.currentThread()) { |
2122dfcf3677
7156963: Incorrect copyright header in java/io/SerialCallbackContext
coffeys
parents:
9734
diff
changeset
|
65 |
throw new NotActiveException( |
2122dfcf3677
7156963: Incorrect copyright header in java/io/SerialCallbackContext
coffeys
parents:
9734
diff
changeset
|
66 |
"not in readObject invocation or fields already read"); |
2122dfcf3677
7156963: Incorrect copyright header in java/io/SerialCallbackContext
coffeys
parents:
9734
diff
changeset
|
67 |
} |
2122dfcf3677
7156963: Incorrect copyright header in java/io/SerialCallbackContext
coffeys
parents:
9734
diff
changeset
|
68 |
thread = null; |
2122dfcf3677
7156963: Incorrect copyright header in java/io/SerialCallbackContext
coffeys
parents:
9734
diff
changeset
|
69 |
} |
2122dfcf3677
7156963: Incorrect copyright header in java/io/SerialCallbackContext
coffeys
parents:
9734
diff
changeset
|
70 |
|
2122dfcf3677
7156963: Incorrect copyright header in java/io/SerialCallbackContext
coffeys
parents:
9734
diff
changeset
|
71 |
public void setUsed() { |
2122dfcf3677
7156963: Incorrect copyright header in java/io/SerialCallbackContext
coffeys
parents:
9734
diff
changeset
|
72 |
thread = null; |
2122dfcf3677
7156963: Incorrect copyright header in java/io/SerialCallbackContext
coffeys
parents:
9734
diff
changeset
|
73 |
} |
2122dfcf3677
7156963: Incorrect copyright header in java/io/SerialCallbackContext
coffeys
parents:
9734
diff
changeset
|
74 |
} |