Merge "Test for forcing Gregorian as default Calendar"
diff --git a/harmony-tests/src/test/java/org/apache/harmony/tests/java/lang/ProcessManagerTest.java b/harmony-tests/src/test/java/org/apache/harmony/tests/java/lang/ProcessManagerTest.java
index f5d4163..477a8e2 100644
--- a/harmony-tests/src/test/java/org/apache/harmony/tests/java/lang/ProcessManagerTest.java
+++ b/harmony-tests/src/test/java/org/apache/harmony/tests/java/lang/ProcessManagerTest.java
@@ -99,7 +99,6 @@
}
thread.interrupt();
- //process.destroy();
try {
Thread.sleep(100);
} catch(InterruptedException ie) {
@@ -107,6 +106,9 @@
}
assertTrue(isThrown);
+ // Destroy process, otherwise it will run until 1000 seconds
+ // have elapsed but we don't need it again for this test.
+ process.destroy();
}
public void testPwd() throws IOException, InterruptedException {
diff --git a/harmony-tests/src/test/java/org/apache/harmony/tests/java/lang/ProcessTest.java b/harmony-tests/src/test/java/org/apache/harmony/tests/java/lang/ProcessTest.java
index cf6f89e..49444b4 100644
--- a/harmony-tests/src/test/java/org/apache/harmony/tests/java/lang/ProcessTest.java
+++ b/harmony-tests/src/test/java/org/apache/harmony/tests/java/lang/ProcessTest.java
@@ -131,6 +131,10 @@
process.exitValue();
fail();
} catch(IllegalThreadStateException expected) {
+ } finally {
+ // Destroy process, otherwise it will run until 3000 seconds
+ // have elapsed but we don't need it again for this test.
+ process.destroy();
}
}
diff --git a/ojluni/src/main/java/java/io/ObjectInputStream.java b/ojluni/src/main/java/java/io/ObjectInputStream.java
index f722df0..e06306d 100644
--- a/ojluni/src/main/java/java/io/ObjectInputStream.java
+++ b/ojluni/src/main/java/java/io/ObjectInputStream.java
@@ -239,12 +239,54 @@
new ReferenceQueue<>();
}
+ // Android-removed: ObjectInputFilter logic, to be reconsidered. http://b/110252929
+ /*
+ static {
+ /* Setup access so sun.misc can invoke package private functions. *
+ sun.misc.SharedSecrets.setJavaOISAccess(new JavaOISAccess() {
+ public void setObjectInputFilter(ObjectInputStream stream, ObjectInputFilter filter) {
+ stream.setInternalObjectInputFilter(filter);
+ }
+
+ public ObjectInputFilter getObjectInputFilter(ObjectInputStream stream) {
+ return stream.getInternalObjectInputFilter();
+ }
+ });
+ }
+
+ /*
+ * Separate class to defer initialization of logging until needed.
+ *
+ private static class Logging {
+
+ /*
+ * Logger for ObjectInputFilter results.
+ * Setup the filter logger if it is set to INFO or WARNING.
+ * (Assuming it will not change).
+ *
+ private static final PlatformLogger traceLogger;
+ private static final PlatformLogger infoLogger;
+ static {
+ PlatformLogger filterLog = PlatformLogger.getLogger("java.io.serialization");
+ infoLogger = (filterLog != null &&
+ filterLog.isLoggable(PlatformLogger.Level.INFO)) ? filterLog : null;
+ traceLogger = (filterLog != null &&
+ filterLog.isLoggable(PlatformLogger.Level.FINER)) ? filterLog : null;
+ }
+ }
+ */
+
/** filter stream for handling block data conversion */
private final BlockDataInputStream bin;
/** validation callback list */
private final ValidationList vlist;
/** recursion depth */
+ // Android-changed: ObjectInputFilter logic, to be reconsidered. http://b/110252929
+ // private long depth;
private int depth;
+ // Android-removed: ObjectInputFilter logic, to be reconsidered. http://b/110252929
+ // /** Total number of references to any type of object, class, enum, proxy, etc. */
+ // private long totalObjectRefs;
/** whether stream is closed */
private boolean closed;
@@ -270,6 +312,14 @@
*/
private SerialCallbackContext curContext;
+ // Android-removed: ObjectInputFilter logic, to be reconsidered. http://b/110252929
+ /**
+ * Filter of class descriptors and classes read from the stream;
+ * may be null.
+ *
+ private ObjectInputFilter serialFilter;
+ */
+
/**
* Creates an ObjectInputStream that reads from the specified InputStream.
* A serialization stream header is read from the stream and verified.
@@ -297,6 +347,8 @@
bin = new BlockDataInputStream(in);
handles = new HandleTable(10);
vlist = new ValidationList();
+ // Android-removed: ObjectInputFilter logic, to be reconsidered. http://b/110252929
+ // serialFilter = ObjectInputFilter.Config.getSerialFilter();
enableOverride = false;
readStreamHeader();
bin.setBlockDataMode(true);
@@ -327,6 +379,8 @@
bin = null;
handles = null;
vlist = null;
+ // Android-removed: ObjectInputFilter logic, to be reconsidered. http://b/110252929
+ // serialFilter = ObjectInputFilter.Config.getSerialFilter();
enableOverride = true;
}
@@ -334,7 +388,7 @@
* Read an object from the ObjectInputStream. The class of the object, the
* signature of the class, and the values of the non-transient and
* non-static fields of the class and all of its supertypes are read.
- * Default deserializing for a class can be overriden using the writeObject
+ * Default deserializing for a class can be overridden using the writeObject
* and readObject methods. Objects referenced by this object are read
* transitively so that a complete equivalent graph of objects is
* reconstructed by readObject.
@@ -1075,6 +1129,9 @@
return bin.readUTF();
}
+ // Android-removed: ObjectInputFilter logic, to be reconsidered. http://b/110252929
+ // Removed ObjectInputFilter related methods.
+
/**
* Provide access to the persistent fields read from the input stream.
*/
@@ -1324,6 +1381,8 @@
}
depth++;
+ // Android-removed: ObjectInputFilter logic, to be reconsidered. http://b/110252929
+ // totalObjectRefs++;
try {
switch (tc) {
case TC_NULL:
@@ -1400,6 +1459,18 @@
}
Object rep = resolveObject(obj);
if (rep != obj) {
+ // Android-removed: ObjectInputFilter logic, to be reconsidered. http://b/110252929
+ /*
+ // The type of the original object has been filtered but resolveObject
+ // may have replaced it; filter the replacement's type
+ if (rep != null) {
+ if (rep.getClass().isArray()) {
+ filterCheck(rep.getClass(), Array.getLength(rep));
+ } else {
+ filterCheck(rep.getClass(), -1);
+ }
+ }
+ */
handles.setObject(passHandle, rep);
}
return rep;
@@ -1470,6 +1541,8 @@
throw new InvalidObjectException(
"cannot read back reference to unshared object");
}
+ // Android-removed: ObjectInputFilter logic, to be reconsidered. http://b/110252929
+ // filterCheck(null, -1); // just a check for number of references, depth, no class
return obj;
}
@@ -1506,23 +1579,29 @@
throws IOException
{
byte tc = bin.peekByte();
+ ObjectStreamClass descriptor;
switch (tc) {
case TC_NULL:
- return (ObjectStreamClass) readNull();
-
+ descriptor = (ObjectStreamClass) readNull();
+ break;
case TC_REFERENCE:
- return (ObjectStreamClass) readHandle(unshared);
-
+ descriptor = (ObjectStreamClass) readHandle(unshared);
+ break;
case TC_PROXYCLASSDESC:
- return readProxyDesc(unshared);
-
+ descriptor = readProxyDesc(unshared);
+ break;
case TC_CLASSDESC:
- return readNonProxyDesc(unshared);
-
+ descriptor = readNonProxyDesc(unshared);
+ break;
default:
throw new StreamCorruptedException(
String.format("invalid type code: %02X", tc));
}
+ // Android-removed: ObjectInputFilter logic, to be reconsidered. http://b/110252929
+ // if (descriptor != null) {
+ // validateDescriptor(descriptor);
+ // }
+ return descriptor;
}
private boolean isCustomSubclass() {
@@ -1569,6 +1648,11 @@
ReflectUtil.checkProxyPackageAccess(
getClass().getClassLoader(),
cl.getInterfaces());
+ // Android-removed: ObjectInputFilter logic, to be reconsidered. http://b/110252929
+ // // Filter the interfaces
+ // for (Class<?> clazz : cl.getInterfaces()) {
+ // filterCheck(clazz, -1);
+ // }
}
} catch (ClassNotFoundException ex) {
resolveEx = ex;
@@ -1577,6 +1661,10 @@
desc.initProxy(cl, resolveEx, readClassDesc(false));
+ // Android-removed: ObjectInputFilter logic, to be reconsidered. http://b/110252929
+ // // Call filterCheck on the definition
+ // filterCheck(desc.forClass(), -1);
+
handles.finish(descHandle);
passHandle = descHandle;
return desc;
@@ -1624,8 +1712,13 @@
desc.initNonProxy(readDesc, cl, resolveEx, readClassDesc(false));
+ // Android-removed: ObjectInputFilter unsupported - removed filterCheck() call.
+ // // Call filterCheck on the definition
+ // filterCheck(desc.forClass(), -1);
+
handles.finish(descHandle);
passHandle = descHandle;
+
return desc;
}
@@ -1666,6 +1759,9 @@
ObjectStreamClass desc = readClassDesc(false);
int len = bin.readInt();
+ // Android-removed: ObjectInputFilter logic, to be reconsidered. http://b/110252929
+ // filterCheck(desc.forClass(), len);
+
Object array = null;
Class<?> cl, ccl = null;
if ((cl = desc.forClass()) != null) {
@@ -1814,6 +1910,17 @@
rep = cloneArray(rep);
}
if (rep != obj) {
+ // Android-removed: ObjectInputFilter logic, to be reconsidered. http://b/110252929
+ /*
+ // Filter the replacement object
+ if (rep != null) {
+ if (rep.getClass().isArray()) {
+ filterCheck(rep.getClass(), Array.getLength(rep));
+ } else {
+ filterCheck(rep.getClass(), -1);
+ }
+ }
+ */
handles.setObject(passHandle, obj = rep);
}
}
@@ -1892,6 +1999,10 @@
if (obj == null || handles.lookupException(passHandle) != null) {
defaultReadFields(null, slotDesc); // skip field values
} else if (slotDesc.hasReadObjectMethod()) {
+ // BEGIN Android-changed: ThreadDeath cannot cause corruption on Android.
+ // Android does not support Thread.stop() or Thread.stop(Throwable) so this
+ // does not need to protect against state corruption that can occur when a
+ // ThreadDeath Error is thrown in the middle of the finally block.
SerialCallbackContext oldContext = curContext;
if (oldContext != null)
oldContext.check();
@@ -1914,6 +2025,7 @@
if (oldContext!= null)
oldContext.check();
curContext = oldContext;
+ // END Android-changed: ThreadDeath cannot cause corruption on Android.
}
/*
@@ -1924,7 +2036,7 @@
defaultDataEnd = false;
} else {
defaultReadFields(obj, slotDesc);
- }
+ }
if (slotDesc.hasWriteObjectData()) {
skipCustomData();
@@ -1940,7 +2052,7 @@
}
}
}
- }
+ }
/**
* Skips over all block data and objects until TC_ENDBLOCKDATA is
@@ -1988,7 +2100,7 @@
if (primVals == null || primVals.length < primDataSize) {
primVals = new byte[primDataSize];
}
- bin.readFully(primVals, 0, primDataSize, false);
+ bin.readFully(primVals, 0, primDataSize, false);
if (obj != null) {
desc.setPrimFieldValues(obj, primVals);
}
@@ -2287,6 +2399,9 @@
}
}
+ // Android-removed: ObjectInputFilter logic, to be reconsidered. http://b/110252929
+ // Removed FilterValues class.
+
/**
* Input stream supporting single-byte peek operations.
*/
@@ -2296,6 +2411,8 @@
private final InputStream in;
/** peeked byte */
private int peekb = -1;
+ /** total bytes read from the stream */
+ private long totalBytesRead = 0;
/**
* Creates new PeekInputStream on top of given underlying stream.
@@ -2309,7 +2426,12 @@
* that it does not consume the read value.
*/
int peek() throws IOException {
- return (peekb >= 0) ? peekb : (peekb = in.read());
+ if (peekb >= 0) {
+ return peekb;
+ }
+ peekb = in.read();
+ totalBytesRead += peekb >= 0 ? 1 : 0;
+ return peekb;
}
public int read() throws IOException {
@@ -2318,21 +2440,27 @@
peekb = -1;
return v;
} else {
- return in.read();
+ int nbytes = in.read();
+ totalBytesRead += nbytes >= 0 ? 1 : 0;
+ return nbytes;
}
}
public int read(byte[] b, int off, int len) throws IOException {
+ int nbytes;
if (len == 0) {
return 0;
} else if (peekb < 0) {
- return in.read(b, off, len);
+ nbytes = in.read(b, off, len);
+ totalBytesRead += nbytes >= 0 ? nbytes : 0;
+ return nbytes;
} else {
b[off++] = (byte) peekb;
len--;
peekb = -1;
- int n = in.read(b, off, len);
- return (n >= 0) ? (n + 1) : 1;
+ nbytes = in.read(b, off, len);
+ totalBytesRead += nbytes >= 0 ? nbytes : 0;
+ return (nbytes >= 0) ? (nbytes + 1) : 1;
}
}
@@ -2357,7 +2485,9 @@
skipped++;
n--;
}
- return skipped + skip(n);
+ n = skipped + in.skip(n);
+ totalBytesRead += n;
+ return n;
}
public int available() throws IOException {
@@ -2367,6 +2497,10 @@
public void close() throws IOException {
in.close();
}
+
+ public long getBytesRead() {
+ return totalBytesRead;
+ }
}
/**
@@ -3222,6 +3356,14 @@
throw new UTFDataFormatException();
}
}
+
+ /**
+ * Returns the number of bytes read from the input stream.
+ * @return the number of bytes read from the input stream
+ */
+ long getBytesRead() {
+ return in.getBytesRead();
+ }
}
/**
@@ -3552,4 +3694,23 @@
}
}
+ // Android-removed: Logic related to ObjectStreamClassValidator, unused on Android
+ /*
+ private void validateDescriptor(ObjectStreamClass descriptor) {
+ ObjectStreamClassValidator validating = validator;
+ if (validating != null) {
+ validating.validateDescriptor(descriptor);
+ }
+ }
+
+ // controlled access to ObjectStreamClassValidator
+ private volatile ObjectStreamClassValidator validator;
+
+ private static void setValidator(ObjectInputStream ois, ObjectStreamClassValidator validator) {
+ ois.validator = validator;
+ }
+ static {
+ SharedSecrets.setJavaObjectInputStreamAccess(ObjectInputStream::setValidator);
+ }
+ */
}
diff --git a/ojluni/src/main/java/java/nio/charset/CharsetDecoder.java b/ojluni/src/main/java/java/nio/charset/CharsetDecoder.java
index 8e265d6..34065ee 100644
--- a/ojluni/src/main/java/java/nio/charset/CharsetDecoder.java
+++ b/ojluni/src/main/java/java/nio/charset/CharsetDecoder.java
@@ -87,9 +87,9 @@
* <a name="cae"></a>
*
* <p> How a decoding error is handled depends upon the action requested for
- * that type of error, which is described by an instance of the {@linkplain
+ * that type of error, which is described by an instance of the {@link
* CodingErrorAction} class. The possible error actions are to {@linkplain
- * CodingErrorAction#IGNORE ignore} the erroneous input, {@link
+ * CodingErrorAction#IGNORE ignore} the erroneous input, {@linkplain
* CodingErrorAction#REPORT report} the error to the invoker via
* the returned {@link CoderResult} object, or {@linkplain CodingErrorAction#REPLACE
* replace} the erroneous input with the current value of the
@@ -164,7 +164,7 @@
* Initializes a new decoder. The new decoder will have the given
* chars-per-byte and replacement values.
*
- * * @param cs
+ * @param cs
* The charset that created this decoder
*
* @param averageCharsPerByte
@@ -253,7 +253,12 @@
* which is never <tt>null</tt> and is never empty
*/
public final String replacement() {
+
return replacement;
+
+
+
+
}
/**
@@ -296,6 +301,7 @@
+
implReplaceWith(this.replacement);
return this;
}
@@ -452,7 +458,7 @@
/**
* Returns the maximum number of characters that will be produced for each
* byte of input. This value may be used to compute the worst-case size
- * of the output buffer required for a given input sequence. </p>
+ * of the output buffer required for a given input sequence.
*
* @return The maximum number of characters that will be produced per
* byte of input
@@ -978,6 +984,12 @@
+
+
+
+
+
+
private void throwIllegalStateException(int from, int to) {
throw new IllegalStateException("Current state = " + stateNames[from]
+ ", new state = " + stateNames[to]);
diff --git a/ojluni/src/main/java/java/nio/charset/IllegalCharsetNameException.java b/ojluni/src/main/java/java/nio/charset/IllegalCharsetNameException.java
index 38962af..9124282 100644
--- a/ojluni/src/main/java/java/nio/charset/IllegalCharsetNameException.java
+++ b/ojluni/src/main/java/java/nio/charset/IllegalCharsetNameException.java
@@ -46,7 +46,7 @@
private String charsetName;
/**
- * Constructs an instance of this class. </p>
+ * Constructs an instance of this class.
*
* @param charsetName
* The illegal charset name
@@ -57,7 +57,7 @@
}
/**
- * Retrieves the illegal charset name. </p>
+ * Retrieves the illegal charset name.
*
* @return The illegal charset name
*/
diff --git a/ojluni/src/main/java/java/nio/charset/UnsupportedCharsetException.java b/ojluni/src/main/java/java/nio/charset/UnsupportedCharsetException.java
index 6c04cb1..1774fc0 100644
--- a/ojluni/src/main/java/java/nio/charset/UnsupportedCharsetException.java
+++ b/ojluni/src/main/java/java/nio/charset/UnsupportedCharsetException.java
@@ -46,7 +46,7 @@
private String charsetName;
/**
- * Constructs an instance of this class. </p>
+ * Constructs an instance of this class.
*
* @param charsetName
* The name of the unsupported charset
@@ -57,7 +57,7 @@
}
/**
- * Retrieves the name of the unsupported charset. </p>
+ * Retrieves the name of the unsupported charset.
*
* @return The name of the unsupported charset
*/