diff options
author | mduigou <none@none> | 2011-02-14 10:38:51 -0800 |
---|---|---|
committer | mduigou <none@none> | 2011-02-14 10:38:51 -0800 |
commit | 96559124a6b0d83fceeb8506d0b10af04ac170e6 (patch) | |
tree | b93dea165c689e1fd1d54d7669244bb88e5eedd4 /src/share/classes/java/util/Vector.java | |
parent | 2c8f36f034f5ffece454448e1b22e7f13f12a656 (diff) | |
download | jdk8u_jdk-96559124a6b0d83fceeb8506d0b10af04ac170e6.tar.gz |
6934356: Vector.writeObject() serialization may deadlock
Summary: No longer synchronize on self while writing other objects.
Reviewed-by: alanb, forax, mduigou, peterjones
Contributed-by: Neil Richards <neil.richards@ngmr.net>
Diffstat (limited to 'src/share/classes/java/util/Vector.java')
-rw-r--r-- | src/share/classes/java/util/Vector.java | 20 |
1 files changed, 14 insertions, 6 deletions
diff --git a/src/share/classes/java/util/Vector.java b/src/share/classes/java/util/Vector.java index 1ce0abf86f..11c0c60a48 100644 --- a/src/share/classes/java/util/Vector.java +++ b/src/share/classes/java/util/Vector.java @@ -1050,13 +1050,21 @@ public class Vector<E> /** * Save the state of the {@code Vector} instance to a stream (that - * is, serialize it). This method is present merely for synchronization. - * It just calls the default writeObject method. + * is, serialize it). + * This method performs synchronization to ensure the consistency + * of the serialized data. */ - private synchronized void writeObject(java.io.ObjectOutputStream s) - throws java.io.IOException - { - s.defaultWriteObject(); + private void writeObject(java.io.ObjectOutputStream s) + throws java.io.IOException { + final java.io.ObjectOutputStream.PutField fields = s.putFields(); + final Object[] data; + synchronized (this) { + fields.put("capacityIncrement", capacityIncrement); + fields.put("elementCount", elementCount); + data = elementData.clone(); + } + fields.put("elementData", data); + s.writeFields(); } /** |