Merge "Update change annotations in Object(In|Out)putStream." am: 58b1654b67 am: 669a908df7
am: b9c861416c
Change-Id: I4c353a82ec3f0f93275e3a13e28718738c228977
diff --git a/ojluni/src/main/java/java/io/ObjectInputStream.java b/ojluni/src/main/java/java/io/ObjectInputStream.java
index 17001c5..f722df0 100644
--- a/ojluni/src/main/java/java/io/ObjectInputStream.java
+++ b/ojluni/src/main/java/java/io/ObjectInputStream.java
@@ -208,7 +208,6 @@
public class ObjectInputStream
extends InputStream implements ObjectInput, ObjectStreamConstants
{
-
/** handle value representing null */
private static final int NULL_HANDLE = -1;
@@ -2021,11 +2020,13 @@
throw new InternalError();
}
clear();
+ // BEGIN Android-changed: Fix SerializationStressTest#test_2_writeReplace.
IOException e = (IOException) readObject0(false);
- // BEGIN Android-changed
+ // If we want to continue reading from same stream after fatal exception, we
+ // need to clear internal data structures.
clear();
- // END Android-changed
return e;
+ // END Android-changed: Fix SerializationStressTest#test_2_writeReplace.
}
/**
@@ -2069,6 +2070,7 @@
* corresponding modifications to the above class.
*/
private static ClassLoader latestUserDefinedLoader() {
+ // Android-changed: Use VMStack on Android.
return VMStack.getClosestUserClassLoader();
}
diff --git a/ojluni/src/main/java/java/io/ObjectOutputStream.java b/ojluni/src/main/java/java/io/ObjectOutputStream.java
index 632f2d3..7c4f0ca 100644
--- a/ojluni/src/main/java/java/io/ObjectOutputStream.java
+++ b/ojluni/src/main/java/java/io/ObjectOutputStream.java
@@ -37,7 +37,6 @@
import java.util.concurrent.ConcurrentMap;
import static java.io.ObjectStreamClass.processQueue;
import java.io.SerialCallbackContext;
-
import sun.reflect.misc.ReflectUtil;
/**
@@ -211,7 +210,15 @@
* value of "sun.io.serialization.extendedDebugInfo" property,
* as true or false for extended information about exception's place
*/
+ // BEGIN Android-changed: Do not support extendedDebugInfo on Android.
+ /*
+ private static final boolean extendedDebugInfo =
+ java.security.AccessController.doPrivileged(
+ new sun.security.action.GetBooleanAction(
+ "sun.io.serialization.extendedDebugInfo")).booleanValue();
+ */
private static final boolean extendedDebugInfo = false;
+ // END Android-changed: Do not support extendedDebugInfo on Android.
/**
* Creates an ObjectOutputStream that writes to the specified OutputStream.
@@ -347,7 +354,7 @@
writeObject0(obj, false);
} catch (IOException ex) {
if (depth == 0) {
- // BEGIN Android-changed
+ // BEGIN Android-changed: Ignore secondary exceptions during writeObject().
// writeFatalException(ex);
try {
writeFatalException(ex);
@@ -357,7 +364,7 @@
// is no need to propagate the second exception or generate a third exception,
// both of which might obscure details of the root cause.
}
- // END Android-changed
+ // END Android-changed: Ignore secondary exceptions during writeObject().
}
throw ex;
}
@@ -378,12 +385,12 @@
* @since 1.2
*/
protected void writeObjectOverride(Object obj) throws IOException {
- // BEGIN Android-changed
+ // BEGIN Android-added: Let writeObjectOverride throw IOException if !enableOverride.
if (!enableOverride) {
// Subclasses must override.
throw new IOException();
}
- // END Android-changed
+ // END Android-added: Let writeObjectOverride throw IOException if !enableOverride.
}
/**
@@ -753,7 +760,7 @@
*/
public void close() throws IOException {
flush();
- // http://b/28159133
+ // Android-removed: Don't clear() during close(), keep the handle table. http://b/28159133
// clear();
bout.close();
}
@@ -1132,7 +1139,7 @@
} else if (!unshared && (h = handles.lookup(obj)) != -1) {
writeHandle(h);
return;
- // BEGIN Android-changed
+ // BEGIN Android-changed: Make Class and ObjectStreamClass replaceable.
/*
} else if (obj instanceof Class) {
writeClass((Class) obj, unshared);
@@ -1141,7 +1148,7 @@
writeClassDesc((ObjectStreamClass) obj, unshared);
return;
*/
- // END Android-changed
+ // END Android-changed: Make Class and ObjectStreamClass replaceable.
}
// check for replacement object
@@ -1149,7 +1156,7 @@
Class<?> cl = obj.getClass();
ObjectStreamClass desc;
- // BEGIN Android-changed
+ // BEGIN Android-changed: Make only one call to writeReplace.
/*
for (;;) {
// REMIND: skip this check for strings/arrays?
@@ -1177,7 +1184,7 @@
cl = repCl;
desc = ObjectStreamClass.lookup(cl, true);
}
- // END Android-changed
+ // END Android-changed: Make only one call to writeReplace.
if (enableReplace) {
Object rep = replaceObject(obj);
@@ -1197,7 +1204,7 @@
} else if (!unshared && (h = handles.lookup(obj)) != -1) {
writeHandle(h);
return;
-// BEGIN Android-changed
+// BEGIN Android-changed: Make Class and ObjectStreamClass replaceable.
/*
} else if (obj instanceof Class) {
writeClass((Class) obj, unshared);
@@ -1206,17 +1213,17 @@
writeClassDesc((ObjectStreamClass) obj, unshared);
return;
*/
-// END Android-changed
+// END Android-changed: Make Class and ObjectStreamClass replaceable.
}
}
// remaining cases
- // BEGIN Android-changed
+ // BEGIN Android-changed: Make Class and ObjectStreamClass replaceable.
if (obj instanceof Class) {
writeClass((Class) obj, unshared);
} else if (obj instanceof ObjectStreamClass) {
writeClassDesc((ObjectStreamClass) obj, unshared);
- // END Android-changed
+ // END Android-changed: Make Class and ObjectStreamClass replaceable.
} else if (obj instanceof String) {
writeString((String) obj, unshared);
} else if (cl.isArray()) {
@@ -1812,6 +1819,7 @@
/** loopback stream (for data writes that span data blocks) */
private final DataOutputStream dout;
+ // BEGIN Android-added: Warning if writing to a closed ObjectOutputStream.
/**
* Indicates that this stream was closed and that a warning must be logged once if an
* attempt is made to write to it and the underlying stream does not throw an exception.
@@ -1822,6 +1830,7 @@
* http://b/28159133
*/
private boolean warnOnceWhenWriting;
+ // END Android-added: Warning if writing to a closed ObjectOutputStream.
/**
* Creates new BlockDataOutputStream on top of given underlying stream.
@@ -1856,6 +1865,7 @@
return blkmode;
}
+ // BEGIN Android-added: Warning about writing to closed ObjectOutputStream
/**
* Warns if the stream has been closed.
*
@@ -1874,6 +1884,7 @@
warnOnceWhenWriting = false;
}
}
+ // END Android-added: Warning about writing to closed ObjectOutputStream
/* ----------------- generic output stream methods ----------------- */
/*
@@ -1905,6 +1916,7 @@
public void close() throws IOException {
flush();
out.close();
+ // Android-added: Warning about writing to closed ObjectOutputStream
warnOnceWhenWriting = true;
}
@@ -1920,6 +1932,7 @@
if (!(copy || blkmode)) { // write directly
drain();
out.write(b, off, len);
+ // Android-added: Warning about writing to closed ObjectOutputStream
warnIfClosed();
return;
}
@@ -1942,6 +1955,7 @@
len -= wlen;
}
}
+ // Android-added: Warning about writing to closed ObjectOutputStream
warnIfClosed();
}
@@ -1958,6 +1972,7 @@
}
out.write(buf, 0, pos);
pos = 0;
+ // Android-added: Warning about writing to closed ObjectOutputStream
warnIfClosed();
}
@@ -1976,6 +1991,7 @@
Bits.putInt(hbuf, 1, len);
out.write(hbuf, 0, 5);
}
+ // Android-added: Warning about writing to closed ObjectOutputStream
warnIfClosed();
}