aboutsummaryrefslogtreecommitdiff
path: root/src/share/classes/java/util/Vector.java
diff options
context:
space:
mode:
authormduigou <none@none>2011-02-14 10:38:51 -0800
committermduigou <none@none>2011-02-14 10:38:51 -0800
commit96559124a6b0d83fceeb8506d0b10af04ac170e6 (patch)
treeb93dea165c689e1fd1d54d7669244bb88e5eedd4 /src/share/classes/java/util/Vector.java
parent2c8f36f034f5ffece454448e1b22e7f13f12a656 (diff)
downloadjdk8u_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.java20
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();
}
/**