Merge change I9297389b

* changes:
  Udating luni to Harmony r823222.
diff --git a/luni/src/main/java/java/io/BufferedOutputStream.java b/luni/src/main/java/java/io/BufferedOutputStream.java
index 6d52dee..8b7c4f5 100644
--- a/luni/src/main/java/java/io/BufferedOutputStream.java
+++ b/luni/src/main/java/java/io/BufferedOutputStream.java
@@ -148,17 +148,16 @@
             out.write(buffer, offset, length);
             return;
         }
-
-        // BEGIN android-changed
-        // Exception priorities (in case of multiple errors) differ from
-        // RI, but are spec-compliant.
-        // used (offset | length) < 0 instead of (offset < 0) || (length < 0)
-        // to safe one operation
-        if ((offset | length) < 0 || offset > buffer.length - length) {
-            // K002f=Arguments out of bounds
-            throw new ArrayIndexOutOfBoundsException(Msg.getString("K002f")); //$NON-NLS-1$
+        
+        if (offset < 0 || offset > buffer.length - length) {
+            // K002e=Offset out of bounds \: {0}
+            throw new ArrayIndexOutOfBoundsException(Msg.getString("K002e", offset)); //$NON-NLS-1$
+        
         }
-        // END android-changed
+        if (length < 0) {
+            // K0031=Length out of bounds \: {0}
+            throw new ArrayIndexOutOfBoundsException(Msg.getString("K0031", length)); //$NON-NLS-1$
+        }
 
         // flush the internal buffer first if we have not enough space left
         if (length >= (buf.length - count)) {
diff --git a/luni/src/main/java/java/io/CharArrayReader.java b/luni/src/main/java/java/io/CharArrayReader.java
index d2757f6..6753faa 100644
--- a/luni/src/main/java/java/io/CharArrayReader.java
+++ b/luni/src/main/java/java/io/CharArrayReader.java
@@ -213,20 +213,16 @@
         // BEGIN android-note
         // changed array notation to be consistent with the rest of harmony
         // END android-note
-        // avoid int overflow
-        // BEGIN android-changed
-        // Exception priorities (in case of multiple errors) differ from
-        // RI, but are spec-compliant.
-        // made implicit null check explicit,
-        // removed redundant check, used (offset | len) < 0 instead of
-        // (offset < 0) || (len < 0) to safe one operation
-        if (buffer == null) {
-            throw new NullPointerException(Msg.getString("K0047")); //$NON-NLS-1$
+        if (offset < 0 || offset > buffer.length) {
+            // K002e=Offset out of bounds \: {0}
+            throw new ArrayIndexOutOfBoundsException(
+                    Msg.getString("K002e", offset)); //$NON-NLS-1$
         }
-        if ((offset | len) < 0 || len > buffer.length - offset) {
-            throw new ArrayIndexOutOfBoundsException(Msg.getString("K002f")); //$NON-NLS-1$
+        if (len < 0 || len > buffer.length - offset) {
+            // K0031=Length out of bounds \: {0}
+            throw new ArrayIndexOutOfBoundsException(
+                    Msg.getString("K0031", len)); //$NON-NLS-1$
         }
-        // END android-changed
         synchronized (lock) {
             if (isClosed()) {
                 throw new IOException(Msg.getString("K0060")); //$NON-NLS-1$
diff --git a/luni/src/main/java/java/io/DataOutputStream.java b/luni/src/main/java/java/io/DataOutputStream.java
index 18e04a5..4152173 100644
--- a/luni/src/main/java/java/io/DataOutputStream.java
+++ b/luni/src/main/java/java/io/DataOutputStream.java
@@ -280,6 +280,19 @@
         written += 8;
     }
 
+    int writeLongToBuffer(long val,
+                          byte[] buffer, int offset) throws IOException {
+        buffer[offset++] = (byte) (val >> 56);
+        buffer[offset++] = (byte) (val >> 48);
+        buffer[offset++] = (byte) (val >> 40);
+        buffer[offset++] = (byte) (val >> 32);
+        buffer[offset++] = (byte) (val >> 24);
+        buffer[offset++] = (byte) (val >> 16);
+        buffer[offset++] = (byte) (val >> 8);
+        buffer[offset++] = (byte) val;
+        return offset;
+    }
+
     /**
      * Writes the specified 16-bit short to the target stream. Only the lower
      * two bytes of the integer {@code val} are written, with the higher one
@@ -299,6 +312,13 @@
         written += 2;
     }
 
+    int writeShortToBuffer(int val,
+                           byte[] buffer, int offset) throws IOException {
+        buffer[offset++] = (byte) (val >> 8);
+        buffer[offset++] = (byte) val;
+        return offset;
+    }
+
     /**
      * Writes the specified encoded in {@link DataInput modified UTF-8} to this
      * stream.
@@ -317,8 +337,14 @@
         if (utfCount > 65535) {
             throw new UTFDataFormatException(Msg.getString("K0068")); //$NON-NLS-1$
         }
-        writeShort((int) utfCount);
-        writeUTFBytes(str, utfCount);
+        byte[] buffer = new byte[(int)utfCount + 2];
+        int offset = 0;
+        offset = writeShortToBuffer((int) utfCount, buffer, offset);
+        // BEGIN android-changed
+        // removed unused parameter count
+        offset = writeUTFBytesToBuffer(str, buffer, offset);
+        // BEGIN android-changed
+        write(buffer, 0, offset);
     }
 
     long countUTFBytes(String str) {
@@ -336,24 +362,25 @@
         return utfCount;
     }
 
-    void writeUTFBytes(String str, long count) throws IOException {
-        int size = (int) count;
+    int writeUTFBytesToBuffer(String str,
+            byte[] buffer, int offset) throws IOException {
+        // BEGIN android-note
+        // removed unused parameter count
+        // END android-note
         int length = str.length();
-        byte[] utfBytes = new byte[size];
-        int utfIndex = 0;
         for (int i = 0; i < length; i++) {
             int charValue = str.charAt(i);
             if (charValue > 0 && charValue <= 127) {
-                utfBytes[utfIndex++] = (byte) charValue;
+                buffer[offset++] = (byte) charValue;
             } else if (charValue <= 2047) {
-                utfBytes[utfIndex++] = (byte) (0xc0 | (0x1f & (charValue >> 6)));
-                utfBytes[utfIndex++] = (byte) (0x80 | (0x3f & charValue));
+                buffer[offset++] = (byte) (0xc0 | (0x1f & (charValue >> 6)));
+                buffer[offset++] = (byte) (0x80 | (0x3f & charValue));
             } else {
-                utfBytes[utfIndex++] = (byte) (0xe0 | (0x0f & (charValue >> 12)));
-                utfBytes[utfIndex++] = (byte) (0x80 | (0x3f & (charValue >> 6)));
-                utfBytes[utfIndex++] = (byte) (0x80 | (0x3f & charValue));
+                buffer[offset++] = (byte) (0xe0 | (0x0f & (charValue >> 12)));
+                buffer[offset++] = (byte) (0x80 | (0x3f & (charValue >> 6)));
+                buffer[offset++] = (byte) (0x80 | (0x3f & charValue));
              }
         }
-        write(utfBytes, 0, utfIndex);
+        return offset;
     }
 }
diff --git a/luni/src/main/java/java/io/EmulatedFieldsForDumping.java b/luni/src/main/java/java/io/EmulatedFieldsForDumping.java
index 16c7986..c3743dd 100644
--- a/luni/src/main/java/java/io/EmulatedFieldsForDumping.java
+++ b/luni/src/main/java/java/io/EmulatedFieldsForDumping.java
@@ -192,7 +192,6 @@
      */
     @Override
     @Deprecated
-    @SuppressWarnings("deprecation")
     public void write(ObjectOutput output) throws IOException {
         EmulatedFields.ObjectSlot[] slots = emulatedFields.slots();
         for (int i = 0; i < slots.length; i++) {
diff --git a/luni/src/main/java/java/io/File.java b/luni/src/main/java/java/io/File.java
index c802995..cde9fcc 100644
--- a/luni/src/main/java/java/io/File.java
+++ b/luni/src/main/java/java/io/File.java
@@ -761,9 +761,8 @@
      * Indicates if this file's pathname is absolute. Whether a pathname is
      * absolute is platform specific. On UNIX, absolute paths must start with
      * the character '/'; on Windows it is absolute if either it starts with
-     * '\', '/', '\\' (to represent a file server), or a letter followed by a
-     * colon.
-     *
+     * '\\' (to represent a file server), or a letter followed by a colon.
+     * 
      * @return {@code true} if this file's pathname is absolute, {@code false}
      *         otherwise.
      * @see #getPath
@@ -775,10 +774,6 @@
         // END android-changed
     }
 
-    // BEGIN android-removed
-    // private native boolean isAbsoluteImpl(byte[] filePath);
-    // END android-removed
-
     /**
      * Indicates if this file represents a <em>directory</em> on the
      * underlying file system.
@@ -1358,8 +1353,10 @@
         if (properPath != null) {
             return properPath;
         }
-        if(path.length() > 0 && path.charAt(0) == separatorChar) {
-            return properPath = Util.getBytes(path);
+
+        if (isAbsolute()) {
+            byte[] pathBytes = Util.getUTF8Bytes(path);
+            return properPath = pathBytes;
         }
         // Check security by getting user.dir when the path is not absolute
         String userdir;
@@ -1380,10 +1377,6 @@
     }
     // END android-changed
 
-    // BEGIN android-removed
-    // private static native byte[] properPathImpl(byte[] path);
-    // END android-removed
-
     /**
      * Renames this file to the name represented by the {@code dest} file. This
      * works for both normal files and directories.
diff --git a/luni/src/main/java/java/io/FileInputStream.java b/luni/src/main/java/java/io/FileInputStream.java
index c236888..077cd23 100644
--- a/luni/src/main/java/java/io/FileInputStream.java
+++ b/luni/src/main/java/java/io/FileInputStream.java
@@ -69,9 +69,14 @@
         super();
         SecurityManager security = System.getSecurityManager();
         if (security != null) {
+            // For compatibility, nulls are passed to the manager.
             String filePath = (null == file ? null : file.getPath());
             security.checkRead(filePath);
         }
+        if (file == null) {
+            // KA001=Argument must not be null
+            throw new NullPointerException(Msg.getString("KA001")); //$NON-NLS-1$
+        }
         fd = new FileDescriptor();
         fd.readOnly = true;
         fd.descriptor = fileSystem.open(file.properPath(true),
diff --git a/luni/src/main/java/java/io/FilterOutputStream.java b/luni/src/main/java/java/io/FilterOutputStream.java
index 66765f9..fa837ee 100644
--- a/luni/src/main/java/java/io/FilterOutputStream.java
+++ b/luni/src/main/java/java/io/FilterOutputStream.java
@@ -102,7 +102,7 @@
      *            the buffer to write.
      * @param offset
      *            the index of the first byte in {@code buffer} to write.
-     * @param count
+     * @param length
      *            the number of bytes in {@code buffer} to write.
      * @throws IndexOutOfBoundsException
      *             if {@code offset < 0} or {@code count < 0}, or if
@@ -112,25 +112,20 @@
      *             if an I/O error occurs while writing to this stream.
      */
     @Override
-    public void write(byte[] buffer, int offset, int count) throws IOException {
+    public void write(byte[] buffer, int offset, int length) throws IOException {
         // BEGIN android-note
         // changed array notation to be consistent with the rest of harmony
         // END android-note
-        // avoid int overflow, force null buffer check first
-        // BEGIN android-changed
-        // Exception priorities (in case of multiple errors) differ from
-        // RI, but are spec-compliant.
-        // removed redundant check, made implicit null check explicit,
-        // used (offset | count) < 0 instead of (offset < 0) || (count < 0)
-        // to safe one operation
-        if (buffer == null) {
-            throw new NullPointerException(Msg.getString("K0047")); //$NON-NLS-1$
+        // Force null buffer check first!
+        if (offset > buffer.length || offset < 0) {
+            // K002e=Offset out of bounds \: {0}
+            throw new ArrayIndexOutOfBoundsException(Msg.getString("K002e", offset)); //$NON-NLS-1$
         }
-        if ((offset | count) < 0 || count > buffer.length - offset) {
-            throw new ArrayIndexOutOfBoundsException(Msg.getString("K002f")); //$NON-NLS-1$
+        if (length < 0 || length > buffer.length - offset) {
+            // K0031=Length out of bounds \: {0}
+            throw new ArrayIndexOutOfBoundsException(Msg.getString("K0031", length)); //$NON-NLS-1$
         }
-        // END android-changed
-        for (int i = 0; i < count; i++) {
+        for (int i = 0; i < length; i++) {
             // Call write() instead of out.write() since subclasses could
             // override the write() method.
             write(buffer[offset + i]);
diff --git a/luni/src/main/java/java/io/InputStream.java b/luni/src/main/java/java/io/InputStream.java
index f20ce7d..33a5cfd 100644
--- a/luni/src/main/java/java/io/InputStream.java
+++ b/luni/src/main/java/java/io/InputStream.java
@@ -17,9 +17,7 @@
 
 package java.io;
 
-// BEGIN android-added
 import org.apache.harmony.luni.util.Msg;
-// END android-added
 
 /**
  * The base class for all input streams. An input stream is a means of reading
@@ -157,20 +155,15 @@
         // BEGIN android-note
         // changed array notation to be consistent with the rest of harmony
         // END android-note
-        // avoid int overflow, check null b
-        // BEGIN android-changed
-        // Exception priorities (in case of multiple errors) differ from
-        // RI, but are spec-compliant.
-        // removed redundant check, made implicit null check explicit,
-        // used (offset | length) < 0 instead of (offset < 0) || (length < 0)
-        // to safe one operation
-        if (b == null) {
-            throw new NullPointerException(Msg.getString("K0047")); //$NON-NLS-1$
+        // Force null check for b first!
+        if (offset > b.length || offset < 0) {
+            // K002e=Offset out of bounds \: {0}
+            throw new ArrayIndexOutOfBoundsException(Msg.getString("K002e", offset)); //$NON-NLS-1$
+        } 
+        if (length < 0 || length > b.length - offset) {
+            // K0031=Length out of bounds \: {0}
+            throw new ArrayIndexOutOfBoundsException(Msg.getString("K0031", length)); //$NON-NLS-1$
         }
-        if ((offset | length) < 0 || length > b.length - offset) {
-            throw new ArrayIndexOutOfBoundsException(Msg.getString("K002f")); //$NON-NLS-1$
-        }
-        // END android-changed
         for (int i = 0; i < length; i++) {
             int c;
             try {
@@ -224,11 +217,16 @@
         }
         long skipped = 0;
         int toRead = n < 4096 ? (int) n : 4096;
-        if (skipBuf == null || skipBuf.length < toRead) {
-            skipBuf = new byte[toRead];
+        // We are unsynchronized, so take a local copy of the skipBuf at some
+        // point in time.
+        byte[] localBuf = skipBuf;
+        if (localBuf == null || localBuf.length < toRead) {
+            // May be lazily written back to the static. No matter if it
+            // overwrites somebody else's store.
+            skipBuf = localBuf = new byte[toRead];
         }
         while (skipped < n) {
-            int read = read(skipBuf, 0, toRead);
+            int read = read(localBuf, 0, toRead);
             if (read == -1) {
                 return skipped;
             }
diff --git a/luni/src/main/java/java/io/LineNumberInputStream.java b/luni/src/main/java/java/io/LineNumberInputStream.java
index 1a40177..3df3a05 100644
--- a/luni/src/main/java/java/io/LineNumberInputStream.java
+++ b/luni/src/main/java/java/io/LineNumberInputStream.java
@@ -17,9 +17,7 @@
 
 package java.io;
 
-// BEGIN android-added
 import org.apache.harmony.luni.util.Msg;
-// END android-added
 
 /**
  * Wraps an existing {@link InputStream} and counts the line terminators
@@ -171,19 +169,15 @@
      */
     @Override
     public int read(byte[] buffer, int offset, int length) throws IOException {
-        // BEGIN android-changed
-        if (buffer == null) {
-            throw new NullPointerException(Msg.getString("K0047")); //$NON-NLS-1$
+        // Force buffer null check first!
+        if (offset > buffer.length || offset < 0) {
+            // K002e=Offset out of bounds \: {0}
+            throw new ArrayIndexOutOfBoundsException(Msg.getString("K002e", offset)); //$NON-NLS-1$
+        } 
+        if (length < 0 || length > buffer.length - offset) {
+            // K0031=Length out of bounds \: {0}
+            throw new ArrayIndexOutOfBoundsException(Msg.getString("K0031", length)); //$NON-NLS-1$
         }
-        // avoid int overflow
-        // Exception priorities (in case of multiple errors) differ from
-        // RI, but are spec-compliant.
-        // removed redundant check, used (offset | length) < 0
-        // instead of (offset < 0) || (length < 0) to safe one operation
-        if ((offset | length) < 0 || length > buffer.length - offset) {
-            throw new ArrayIndexOutOfBoundsException(Msg.getString("K002f")); //$NON-NLS-1$
-        }
-        // END android-changed
 
         for (int i = 0; i < length; i++) {
             int currentChar;
diff --git a/luni/src/main/java/java/io/NotSerializableException.java b/luni/src/main/java/java/io/NotSerializableException.java
index f6e93a7..d85586a 100644
--- a/luni/src/main/java/java/io/NotSerializableException.java
+++ b/luni/src/main/java/java/io/NotSerializableException.java
@@ -19,9 +19,9 @@
 
 /**
  * Signals that an object that is not serializable has been passed into the
- * {@code ObjectOutput.writeObject()} mthod. This can happen if the object does
- * not implement {@code Serializable} or {@code Externalizable}, or if it is
- * serializable but it overrides {@code writeObject(ObjectOutputStream)} and
+ * {@code ObjectOutput.writeObject()} method. This can happen if the object
+ * does not implement {@code Serializable} or {@code Externalizable}, or if it
+ * is serializable but it overrides {@code writeObject(ObjectOutputStream)} and
  * explicitly prevents serialization by throwing this type of exception.
  * 
  * @see ObjectOutput#writeObject(Object)
diff --git a/luni/src/main/java/java/io/ObjectInputStream.java b/luni/src/main/java/java/io/ObjectInputStream.java
index 6d24eb2..df6d9a2 100644
--- a/luni/src/main/java/java/io/ObjectInputStream.java
+++ b/luni/src/main/java/java/io/ObjectInputStream.java
@@ -701,19 +701,15 @@
      */
     @Override
     public int read(byte[] buffer, int offset, int length) throws IOException {
-        // BEGIN android-changed
-        if (buffer == null) {
-            throw new NullPointerException(Msg.getString("K0047")); //$NON-NLS-1$
+        // Force buffer null check first!
+        if (offset > buffer.length || offset < 0) {
+            // K002e=Offset out of bounds \: {0}
+            throw new ArrayIndexOutOfBoundsException(Msg.getString("K002e", offset)); //$NON-NLS-1$
         }
-        // avoid int overflow
-        // Exception priorities (in case of multiple errors) differ from
-        // RI, but are spec-compliant.
-        // removed redundant check, used (offset | length) < 0 instead of
-        // (offset < 0) || (length < 0) to safe one operation
-        if ((offset | length) < 0 || length > buffer.length - offset) {
-            throw new ArrayIndexOutOfBoundsException(Msg.getString("K002f")); //$NON-NLS-1$
+        if (length < 0 || length > buffer.length - offset) {
+            // K0031=Length out of bounds \: {0}
+            throw new ArrayIndexOutOfBoundsException(Msg.getString("K0031", length)); //$NON-NLS-1$
         }
-        // END android-changed
         if (length == 0) {
             return 0;
         }
diff --git a/luni/src/main/java/java/io/ObjectOutputStream.java b/luni/src/main/java/java/io/ObjectOutputStream.java
index e3c1471..7c85d4b 100644
--- a/luni/src/main/java/java/io/ObjectOutputStream.java
+++ b/luni/src/main/java/java/io/ObjectOutputStream.java
@@ -1617,14 +1617,19 @@
     private Integer writeNewString(String object, boolean unshared)
             throws IOException {
         long count = output.countUTFBytes(object);
+        byte[] buffer;
+        int offset = 0;
         if (count <= 0xffff) {
-            output.writeByte(TC_STRING);
-            output.writeShort((short) count);
+            buffer = new byte[(int)count+3];
+            buffer[offset++] = TC_STRING;
+            offset = output.writeShortToBuffer((short) count, buffer, offset);
         } else {
-            output.writeByte(TC_LONGSTRING);
-            output.writeLong(count);
+            buffer = new byte[(int)count+9];
+            buffer[offset++] = TC_LONGSTRING;
+            offset = output.writeLongToBuffer(count, buffer, offset);
         }
-        output.writeUTFBytes(object, count);
+        offset = output.writeUTFBytesToBuffer(object, buffer, offset);
+        output.write(buffer, 0, offset);
 
         Integer handle = nextHandle();
 
diff --git a/luni/src/main/java/java/io/PrintStream.java b/luni/src/main/java/java/io/PrintStream.java
index 29d460e..8b6464b 100644
--- a/luni/src/main/java/java/io/PrintStream.java
+++ b/luni/src/main/java/java/io/PrintStream.java
@@ -658,7 +658,7 @@
      *            the buffer to be written.
      * @param offset
      *            the index of the first byte in {@code buffer} to write.
-     * @param count
+     * @param length
      *            the number of bytes in {@code buffer} to write.
      * @throws IndexOutOfBoundsException
      *             if {@code offset < 0} or {@code count < 0}, or if {@code
@@ -666,27 +666,23 @@
      * @see #flush()
      */
     @Override
-    public void write(byte[] buffer, int offset, int count) {
-        // BEGIN android-changed
-        if (buffer == null) {
-            throw new NullPointerException(Msg.getString("K0047")); //$NON-NLS-1$
+    public void write(byte[] buffer, int offset, int length) {
+        // Force buffer null check first!
+        if (offset > buffer.length || offset < 0) {
+            // K002e=Offset out of bounds \: {0}
+            throw new ArrayIndexOutOfBoundsException(Msg.getString("K002e", offset)); //$NON-NLS-1$
         }
-        // avoid int overflow
-        // Exception priorities (in case of multiple errors) differ from
-        // RI, but are spec-compliant.
-        // removed redundant check, used (offset | count) < 0
-        // instead of (offset < 0) || (count < 0) to safe one operation
-        if ((offset | count) < 0 || count > buffer.length - offset) {
-            throw new ArrayIndexOutOfBoundsException(Msg.getString("K002f")); //$NON-NLS-1$
+        if (length < 0 || length > buffer.length - offset) {
+            // K0031=Length out of bounds \: {0}
+            throw new ArrayIndexOutOfBoundsException(Msg.getString("K0031", length)); //$NON-NLS-1$
         }
-        // END android-changed
         synchronized (this) {
             if (out == null) {
                 setError();
                 return;
             }
             try {
-                out.write(buffer, offset, count);
+                out.write(buffer, offset, length);
                 if (autoflush) {
                     flush();
                 }
diff --git a/luni/src/main/java/java/io/PushbackInputStream.java b/luni/src/main/java/java/io/PushbackInputStream.java
index 4600fa2..932a896 100644
--- a/luni/src/main/java/java/io/PushbackInputStream.java
+++ b/luni/src/main/java/java/io/PushbackInputStream.java
@@ -177,21 +177,18 @@
     @Override
     public int read(byte[] buffer, int offset, int length) throws IOException {
         if (buf == null) {
-            throw new IOException();
+            // K0059=Stream is closed
+            throw new IOException(Msg.getString("K0059")); //$NON-NLS-1$
         }
-        // BEGIN android-changed
-        if (buffer == null) {
-            throw new NullPointerException(Msg.getString("K0047")); //$NON-NLS-1$
+        // Force buffer null check first!
+        if (offset > buffer.length || offset < 0) {
+            // K002e=Offset out of bounds \: {0}
+            throw new ArrayIndexOutOfBoundsException(Msg.getString("K002e", offset)); //$NON-NLS-1$
         }
-        // avoid int overflow
-        // Exception priorities (in case of multiple errors) differ from
-        // RI, but are spec-compliant.
-        // removed redundant check, used (offset | length) < 0
-        // instead of (offset < 0) || (length < 0) to safe one operation
-        if ((offset | length) < 0 || length > buffer.length - offset) {
-            throw new ArrayIndexOutOfBoundsException(Msg.getString("K002f")); //$NON-NLS-1$
+        if (length < 0 || length > buffer.length - offset) {
+            // K0031=Length out of bounds \: {0}
+            throw new ArrayIndexOutOfBoundsException(Msg.getString("K0031", length)); //$NON-NLS-1$
         }
-        // END android-changed
 
         int copiedBytes = 0, copyLength = 0, newOffset = offset;
         // Are there pushback bytes available?
@@ -296,27 +293,22 @@
     public void unread(byte[] buffer, int offset, int length)
             throws IOException {
         if (length > pos) {
-            // Pushback buffer full
+            // K007e=Pushback buffer full
             throw new IOException(Msg.getString("K007e")); //$NON-NLS-1$
         }
-        // avoid int overflow
-        // BEGIN android-changed
-        // Exception priorities (in case of multiple errors) differ from
-        // RI, but are spec-compliant.
-        // removed redundant check, made implicit null check explicit
-        // used (offset | length) < 0 instead of (offset < 0) || (length < 0)
-        // to safe one operation
-        if (buffer == null) {
-            throw new NullPointerException(Msg.getString("K0047")); //$NON-NLS-1$
+        if (offset > buffer.length || offset < 0) {
+            // K002e=Offset out of bounds \: {0}
+            throw new ArrayIndexOutOfBoundsException(Msg.getString("K002e", offset)); //$NON-NLS-1$
         }
-        if ((offset | length) < 0 || length > buffer.length - offset) {
-            throw new ArrayIndexOutOfBoundsException(Msg.getString("K002f")); //$NON-NLS-1$
+        if (length < 0 || length > buffer.length - offset) {
+            // K0031=Length out of bounds \: {0}
+            throw new ArrayIndexOutOfBoundsException(Msg.getString("K0031", length)); //$NON-NLS-1$
         }
-        // END android-changed
-
         if (buf == null) {
-            throw new IOException();
+            // K0059=Stream is closed
+            throw new IOException(Msg.getString("K0059")); //$NON-NLS-1$
         }
+
         System.arraycopy(buffer, offset, buf, pos - length, length);
         pos = pos - length;
     }
diff --git a/luni/src/main/java/java/io/PushbackReader.java b/luni/src/main/java/java/io/PushbackReader.java
index 606ecb4..016cd2f 100644
--- a/luni/src/main/java/java/io/PushbackReader.java
+++ b/luni/src/main/java/java/io/PushbackReader.java
@@ -298,7 +298,7 @@
      *            reader.
      * @param offset
      *            the index of the first byte in {@code buffer} to push back.
-     * @param count
+     * @param length
      *            the number of bytes to push back.
      * @throws IndexOutOfBoundsException
      *             if {@code offset < 0} or {@code count < 0}, or if
@@ -311,29 +311,27 @@
      * @throws NullPointerException
      *             if {@code buffer} is {@code null}.
      */
-    public void unread(char[] buffer, int offset, int count) throws IOException {
+    public void unread(char[] buffer, int offset, int length) throws IOException {
         synchronized (lock) {
             if (buf == null) {
+                // K0059=Stream is closed
                 throw new IOException(Msg.getString("K0059")); //$NON-NLS-1$
             }
-            if (count > pos) {
-                // Pushback buffer full
+            if (length > pos) {
+                // K007e=Pushback buffer full
                 throw new IOException(Msg.getString("K007e")); //$NON-NLS-1$
             }
-            // BEGIN android-changed
-            if (buffer == null) {
-                throw new NullPointerException(Msg.getString("K0047")); //$NON-NLS-1$
+            // Force buffer null check first!
+            if (offset > buffer.length - length || offset < 0) {
+                // K002e=Offset out of bounds \: {0}
+                throw new ArrayIndexOutOfBoundsException(Msg.getString("K002e", offset)); //$NON-NLS-1$
             }
-            // avoid int overflow
-            // Exception priorities (in case of multiple errors) differ from
-            // RI, but are spec-compliant.
-            // used (offset | count) < 0 instead of (offset < 0) || (count < 0)
-            // to safe one operation
-            if ((offset | count) < 0 || offset > buffer.length - count) {
-                throw new ArrayIndexOutOfBoundsException(Msg.getString("K002f")); //$NON-NLS-1$
+            if (length < 0) {
+                // K0031=Length out of bounds \: {0}
+                throw new ArrayIndexOutOfBoundsException(Msg.getString("K0031", length)); //$NON-NLS-1$
             }
-            // END android-changed
-            for (int i = offset + count - 1; i >= offset; i--) {
+
+            for (int i = offset + length - 1; i >= offset; i--) {
                 unread(buffer[i]);
             }
         }
diff --git a/luni/src/main/java/java/io/StringBufferInputStream.java b/luni/src/main/java/java/io/StringBufferInputStream.java
index cc4ab81..037cc60 100644
--- a/luni/src/main/java/java/io/StringBufferInputStream.java
+++ b/luni/src/main/java/java/io/StringBufferInputStream.java
@@ -115,18 +115,19 @@
             return -1;
         }
         if (b == null) {
+            // K0047=buffer is null
             throw new NullPointerException(Msg.getString("K0047")); //$NON-NLS-1$
         }
         // avoid int overflow
-        // BEGIN android-changed
-        // Exception priorities (in case of multiple errors) differ from
-        // RI, but are spec-compliant.
-        // removed redundant check, used (offset | length) < 0
-        // instead of (offset < 0) || (length < 0) to safe one operation
-        if ((offset | length) < 0 || length > b.length - offset) {
-            throw new ArrayIndexOutOfBoundsException(Msg.getString("K002f")); //$NON-NLS-1$
+        if (offset < 0 || offset > b.length) {
+            // K002e=Offset out of bounds \: {0}
+            throw new ArrayIndexOutOfBoundsException(Msg.getString("K002e", offset)); //$NON-NLS-1$
         }
-        // END android-changed
+        if (length < 0 || length > b.length - offset) {
+            // K0031=Length out of bounds \: {0}
+            throw new ArrayIndexOutOfBoundsException(Msg.getString("K0031", length)); //$NON-NLS-1$
+        }
+
         if (length == 0) {
             return 0;
         }
diff --git a/luni/src/main/java/java/io/StringReader.java b/luni/src/main/java/java/io/StringReader.java
index 0a9e9bb..9f8671a 100644
--- a/luni/src/main/java/java/io/StringReader.java
+++ b/luni/src/main/java/java/io/StringReader.java
@@ -155,23 +155,19 @@
         // BEGIN android-note
         // changed array notation to be consistent with the rest of harmony
         // END android-note
-        // BEGIN android-changed
-        // Exception priorities (in case of multiple errors) differ from
-        // RI, but are spec-compliant.
-        // removed redundant check, added null check, used (offset | len) < 0
-        // instead of (offset < 0) || (len < 0) to safe one operation
-        if (buf == null) {
-            throw new NullPointerException(Msg.getString("K0047")); //$NON-NLS-1$
-        }
         synchronized (lock) {
-            // avoid int overflow
-            if ((offset | len) < 0 || len > buf.length - offset) {
-                throw new ArrayIndexOutOfBoundsException(Msg.getString("K002f")); //$NON-NLS-1$
-            }
-            // END android-changed
             if (isClosed()) {
+                // K0083=StringReader is closed.
                 throw new IOException(Msg.getString("K0083")); //$NON-NLS-1$
             }
+            if (offset < 0 || offset > buf.length) {
+                // K002e=Offset out of bounds \: {0}
+                throw new ArrayIndexOutOfBoundsException(Msg.getString("K002e", offset)); //$NON-NLS-1$
+            }
+            if (len < 0 || len > buf.length - offset) {
+                // K0031=Length out of bounds \: {0}
+                throw new ArrayIndexOutOfBoundsException(Msg.getString("K0031", len)); //$NON-NLS-1$
+            }
             if (len == 0) {
                 return 0;
             }
diff --git a/luni/src/main/java/java/lang/AbstractStringBuilder.java b/luni/src/main/java/java/lang/AbstractStringBuilder.java
index c481e11..869c694 100644
--- a/luni/src/main/java/java/lang/AbstractStringBuilder.java
+++ b/luni/src/main/java/java/lang/AbstractStringBuilder.java
@@ -120,21 +120,23 @@
         count = newSize;
     }
 
-    final void append0(char chars[], int start, int length) {
-        if (chars == null) {
-            throw new NullPointerException();
+    final void append0(char[] chars, int offset, int length) {
+        // Force null check of chars first!
+        if (offset > chars.length || offset < 0) {
+            // K002e=Offset out of bounds \: {0}
+            throw new ArrayIndexOutOfBoundsException(Msg.getString("K002e", offset)); //$NON-NLS-1$
         }
-        // start + length could overflow, start/length maybe MaxInt
-        if (start >= 0 && 0 <= length && length <= chars.length - start) {
-            int newSize = count + length;
-            if (newSize > value.length) {
-                enlargeBuffer(newSize);
-            }
-            System.arraycopy(chars, start, value, count, length);
-            count = newSize;
-        } else {
-            throw new ArrayIndexOutOfBoundsException();
+        if (length < 0 || chars.length - offset < length) {
+            // K0031=Length out of bounds \: {0}
+            throw new ArrayIndexOutOfBoundsException(Msg.getString("K0031", length)); //$NON-NLS-1$
         }
+
+        int newSize = count + length;
+        if (newSize > value.length) {
+            enlargeBuffer(newSize);
+        }
+        System.arraycopy(chars, offset, value, count, length);
+        count = newSize;
     }
 
     final void append0(char ch) {
diff --git a/luni/src/main/java/java/lang/ArrayIndexOutOfBoundsException.java b/luni/src/main/java/java/lang/ArrayIndexOutOfBoundsException.java
index d43a7e6..6bb67fc 100644
--- a/luni/src/main/java/java/lang/ArrayIndexOutOfBoundsException.java
+++ b/luni/src/main/java/java/lang/ArrayIndexOutOfBoundsException.java
@@ -44,6 +44,7 @@
      *            the invalid index.
      */
     public ArrayIndexOutOfBoundsException(int index) {
+        // K0052=Array index out of range\: {0}
         super(Msg.getString("K0052", index)); //$NON-NLS-1$
     }
 
diff --git a/luni/src/main/java/java/lang/Enum.java b/luni/src/main/java/java/lang/Enum.java
index 395c825..e2ee32a 100644
--- a/luni/src/main/java/java/lang/Enum.java
+++ b/luni/src/main/java/java/lang/Enum.java
@@ -25,7 +25,7 @@
 
 /**
  * The superclass of all enumerated types. Actual enumeration types inherit from
- * this class, but extending this class does not make a class an enumration
+ * this class, but extending this class does not make a class an enumeration
  * type, since the compiler needs to generate special information for it.
  */
 public abstract class Enum<E extends Enum<E>> implements Serializable,
diff --git a/luni/src/main/java/java/lang/Integer.java b/luni/src/main/java/java/lang/Integer.java
index 570120b..5dcf217 100644
--- a/luni/src/main/java/java/lang/Integer.java
+++ b/luni/src/main/java/java/lang/Integer.java
@@ -526,7 +526,7 @@
             int quot = positive_value;
             do {
                 int res = quot / 10;
-                int digit_value = quot - (res * 10);
+                int digit_value = quot - ((res << 3) + (res << 1));
                 digit_value += '0';
                 buffer[last_digit++] = (char) digit_value;
                 quot = res;
diff --git a/luni/src/main/java/java/lang/Math.java b/luni/src/main/java/java/lang/Math.java
index d06e6e4..f7b49b2 100644
--- a/luni/src/main/java/java/lang/Math.java
+++ b/luni/src/main/java/java/lang/Math.java
@@ -246,9 +246,7 @@
      *            the value whose closest integer value has to be computed.
      * @return the ceiling of the argument.
      */
-    // BEGIN android-changed
     public static native double ceil(double d);
-    // END android-changed
 
     /**
      * Returns the closest double approximation of the cosine of the argument.
@@ -348,9 +346,7 @@
      *            the value whose closest integer value has to be computed.
      * @return the floor of the argument.
      */
-    // BEGIN android-changed
     public static native double floor(double d);
-    // END android-changed
 
     /**
      * Returns {@code sqrt(}<i>{@code x}</i><sup>{@code 2}</sup>{@code +} <i>
@@ -731,9 +727,7 @@
      *            the value to be rounded.
      * @return the closest integer to the argument (as a double).
      */
-    // BEGIN android-changed
     public static native double rint(double d);
-    // END android-changed
 
     /**
      * Returns the result of rounding the argument to an integer. The result is
diff --git a/luni/src/main/java/java/lang/SecurityManager.java b/luni/src/main/java/java/lang/SecurityManager.java
index 9125850..8a04e92 100644
--- a/luni/src/main/java/java/lang/SecurityManager.java
+++ b/luni/src/main/java/java/lang/SecurityManager.java
@@ -414,9 +414,8 @@
                 .getSecurityProperty(property));
         if (list != null) {
             int plen = pkg.length();
-            StringTokenizer tokenizer = new StringTokenizer(list, ", "); //$NON-NLS-1$
-            while (tokenizer.hasMoreTokens()) {
-                String token = tokenizer.nextToken();
+            String[] tokens = list.split(", *"); //$NON-NLS-1$
+            for (String token : tokens) {
                 int tlen = token.length();
                 if (plen > tlen
                         && pkg.startsWith(token)
diff --git a/luni/src/main/java/java/net/DatagramSocketImpl.java b/luni/src/main/java/java/net/DatagramSocketImpl.java
index db3b9ec..12b2079 100644
--- a/luni/src/main/java/java/net/DatagramSocketImpl.java
+++ b/luni/src/main/java/java/net/DatagramSocketImpl.java
@@ -104,17 +104,6 @@
     }
 
     /**
-     * Gets the value for the specified socket option.
-     * 
-     * @param optID
-     *            the ID of the socket option to be retrieved.
-     * @return the requested option value.
-     * @throws SocketException
-     *                if an error occurs while accessing the option.
-     */
-    public abstract Object getOption(int optID) throws SocketException;
-
-    /**
      * Gets the time-to-live (TTL) for multicast packets sent on this socket.
      * 
      * @return the time-to-live option as a byte value.
@@ -232,19 +221,6 @@
     protected abstract void send(DatagramPacket pack) throws IOException;
 
     /**
-     * Sets the value for the specified socket option.
-     * 
-     * @param optID
-     *            the ID of the socket option to be set.
-     * @param val
-     *            the value of the option.
-     * @throws SocketException
-     *                if an error occurs while setting the option.
-     */
-    public abstract void setOption(int optID, Object val)
-            throws SocketException;
-
-    /**
      * Sets the time-to-live (TTL) option for multicast packets sent on this
      * socket.
      * 
diff --git a/luni/src/main/java/java/net/InetAddress.java b/luni/src/main/java/java/net/InetAddress.java
index 33c25f3..c844d54 100644
--- a/luni/src/main/java/java/net/InetAddress.java
+++ b/luni/src/main/java/java/net/InetAddress.java
@@ -1320,6 +1320,10 @@
         family = fields.get("family", 2); //$NON-NLS-1$
     }
 
+    /*
+     * The spec requires that if we encounter a generic InetAddress in
+     * serialized form then we should interpret it as an Inet4 address.
+     */
     private Object readResolve() throws ObjectStreamException {
         return new Inet4Address(ipaddress, hostName);
     }
diff --git a/luni/src/main/java/java/net/JarURLConnection.java b/luni/src/main/java/java/net/JarURLConnection.java
index da39d9c..f41ef64 100644
--- a/luni/src/main/java/java/net/JarURLConnection.java
+++ b/luni/src/main/java/java/net/JarURLConnection.java
@@ -69,7 +69,7 @@
         if ((sepIdx = file.indexOf("!/")) < 0) { //$NON-NLS-1$
             throw new MalformedURLException();
         }
-        fileURL = new URL(url.getFile().substring(0,sepIdx)); //$NON-NLS-1$
+        fileURL = new URL(url.getFile().substring(0,sepIdx));
         sepIdx += 2;
         if (file.length() == sepIdx) {
             return;
diff --git a/luni/src/main/java/java/net/NetworkInterface.java b/luni/src/main/java/java/net/NetworkInterface.java
index 091eb9f..f921b07 100644
--- a/luni/src/main/java/java/net/NetworkInterface.java
+++ b/luni/src/main/java/java/net/NetworkInterface.java
@@ -334,67 +334,66 @@
      *            the object to compare with this instance.
      * @return {@code true} if the specified object is equal to this {@code
      *         NetworkInterface}, {@code false} otherwise.
-     * @see #hashCode
+     * @see #hashCode()
      */
     @Override
     public boolean equals(Object obj) {
-        // just return true if it is the exact same object
+        // Return true if it is the exact same object.
         if (obj == this) {
             return true;
         }
 
-        if (obj instanceof NetworkInterface) {
-            /*
-             * make sure that some simple checks pass. If the name is not the
-             * same then we are sure it is not the same one. We don't check the
-             * hashcode as it is generated from the name which we check
-             */
-            NetworkInterface netif = (NetworkInterface) obj;
-
-            if (netif.getIndex() != interfaceIndex) {
-                return false;
-            }
-
-            if (!(name.equals("")) && (!netif.getName().equals(name))) { //$NON-NLS-1$
-                return false;
-            }
-
-            if ((name.equals("")) && (!netif.getName().equals(displayName))) { //$NON-NLS-1$
-                return false;
-            }
-
-            // now check that the internet addresses are the same
-            Enumeration<InetAddress> netifAddresses = netif.getInetAddresses();
-            Enumeration<InetAddress> localifAddresses = getInetAddresses();
-            if ((netifAddresses == null) && (localifAddresses != null)) {
-                return false;
-            }
-
-            if ((netifAddresses == null) && (localifAddresses == null)) {
-                // neither have any addresses so they are the same
-                return true;
-            }
-
-            if (netifAddresses != null) {
-                while (netifAddresses.hasMoreElements()
-                        && localifAddresses.hasMoreElements()) {
-                    if (!(localifAddresses.nextElement()).equals(netifAddresses
-                            .nextElement())) {
-                        return false;
-                    }
-                }
-                /*
-                 * now make sure that they had the same number of internet
-                 * addresses, if not they are not the same interface
-                 */
-                if (netifAddresses.hasMoreElements()
-                        || localifAddresses.hasMoreElements()) {
-                    return false;
-                }
-            }
-            return true;
+        // Ensure it is the right type.
+        if (!(obj instanceof NetworkInterface)) {
+            return false;
         }
-        return false;
+
+        /*
+         * Make sure that some simple checks pass. If the name is not the same
+         * then we are sure it is not the same one. We don't check the hashcode
+         * as it is generated from the name which we check
+         */
+        NetworkInterface netif = (NetworkInterface) obj;
+
+        if (netif.getIndex() != interfaceIndex) {
+            return false;
+        }
+
+        if (!(name.equals("")) && (!netif.getName().equals(name))) { //$NON-NLS-1$
+            return false;
+        }
+
+        if ((name.equals("")) && (!netif.getName().equals(displayName))) { //$NON-NLS-1$
+            return false;
+        }
+
+        // Now check that the collection of internet addresses are equal.
+        Enumeration<InetAddress> netifAddresses = netif.getInetAddresses();
+        Enumeration<InetAddress> localifAddresses = getInetAddresses();
+
+        // Check for both null (same), or one null (not same).
+        if (netifAddresses == null) {
+            return localifAddresses == null;
+        }
+        if (localifAddresses == null) {
+            return false;
+        }
+
+        // Both are not null, check InetAddress elements.
+        while (netifAddresses.hasMoreElements()
+                && localifAddresses.hasMoreElements()) {
+            if (!(localifAddresses.nextElement()).equals(
+                    netifAddresses.nextElement())) {
+                return false;
+            }
+        }
+
+        /*
+         * Now make sure that they had the same number of addresses, if not they
+         * are not the same interface.
+         */
+        return !netifAddresses.hasMoreElements()
+                && !localifAddresses.hasMoreElements();
     }
 
     /**
diff --git a/luni/src/main/java/java/net/SocketAddress.java b/luni/src/main/java/java/net/SocketAddress.java
index 32a4c36..e84ebfd 100644
--- a/luni/src/main/java/java/net/SocketAddress.java
+++ b/luni/src/main/java/java/net/SocketAddress.java
@@ -26,6 +26,8 @@
  */
 public abstract class SocketAddress implements Serializable {
 
+    private static final long serialVersionUID = 5215720748342549866L;
+
     /**
      * Creates a new {@code SocketAddress} instance.
      */
diff --git a/luni/src/main/java/java/net/URL.java b/luni/src/main/java/java/net/URL.java
index 9b0fdc4..b9e657d 100644
--- a/luni/src/main/java/java/net/URL.java
+++ b/luni/src/main/java/java/net/URL.java
@@ -889,15 +889,15 @@
     protected void set(String protocol, String host, int port,
             String authority, String userInfo, String path, String query,
             String ref) {
-        String file = path;
+        String filePart = path;
         if (query != null && !query.equals("")) { //$NON-NLS-1$
-            if (file != null) {
-                file = file + "?" + query; //$NON-NLS-1$
+            if (filePart != null) {
+                filePart = filePart + "?" + query; //$NON-NLS-1$
             } else {
-                file = "?" + query; //$NON-NLS-1$
+                filePart = "?" + query; //$NON-NLS-1$
             }
         }
-        set(protocol, host, port, file, ref);
+        set(protocol, host, port, filePart, ref);
         this.authority = authority;
         this.userInfo = userInfo;
         this.path = path;
diff --git a/luni/src/main/java/java/net/URLClassLoader.java b/luni/src/main/java/java/net/URLClassLoader.java
index 6dfa385..61841e6 100644
--- a/luni/src/main/java/java/net/URLClassLoader.java
+++ b/luni/src/main/java/java/net/URLClassLoader.java
@@ -1167,7 +1167,7 @@
      */
     private ArrayList<URL> getInternalURLs(URL root, String classpath) {
         // Class-path attribute is composed of space-separated values.
-        StringTokenizer tokenizer = new java.util.StringTokenizer(classpath);
+        StringTokenizer tokenizer = new StringTokenizer(classpath);
         ArrayList<URL> addedURLs = new ArrayList<URL>();
         String file = root.getFile();
         int jarIndex = file.lastIndexOf("!/") - 1; //$NON-NLS-1$
@@ -1177,9 +1177,6 @@
                     System.getProperty("file.separator"), jarIndex) + 1; //$NON-NLS-1$
         }
         file = file.substring(0, index);
-        String protocol = root.getProtocol();
-        String host = root.getHost();
-        int port = root.getPort();
         while (tokenizer.hasMoreElements()) {
             String element = tokenizer.nextToken();
             if (!element.equals("")) { //$NON-NLS-1$
diff --git a/luni/src/main/java/java/util/Arrays.java b/luni/src/main/java/java/util/Arrays.java
index 4fc1e85..ba03251 100644
--- a/luni/src/main/java/java/util/Arrays.java
+++ b/luni/src/main/java/java/util/Arrays.java
@@ -20,6 +20,8 @@
 import java.io.Serializable;
 import java.lang.reflect.Array;
 
+import org.apache.harmony.luni.util.Msg;
+
 /**
  * {@code Arrays} contains static methods which operate on arrays.
  *
@@ -492,14 +494,7 @@
      *                if {@code start < 0} or {@code end > array.length}.
      */
     public static void fill(byte[] array, int start, int end, byte value) {
-        // Check for null first
-        int length = array.length;
-        if (start > end) {
-            throw new IllegalArgumentException();
-        }
-        if (start < 0 || end > length) {
-            throw new ArrayIndexOutOfBoundsException();
-        }
+        checkBounds(array.length, start, end);
         for (int i = start; i < end; i++) {
             array[i] = value;
         }
@@ -536,14 +531,7 @@
      *                if {@code start < 0} or {@code end > array.length}.
      */
     public static void fill(short[] array, int start, int end, short value) {
-        // Check for null first
-        int length = array.length;
-        if (start > end) {
-            throw new IllegalArgumentException();
-        }
-        if (start < 0 || end > length) {
-            throw new ArrayIndexOutOfBoundsException();
-        }
+        checkBounds(array.length, start, end);
         for (int i = start; i < end; i++) {
             array[i] = value;
         }
@@ -580,14 +568,7 @@
      *                if {@code start < 0} or {@code end > array.length}.
      */
     public static void fill(char[] array, int start, int end, char value) {
-        // Check for null first
-        int length = array.length;
-        if (start > end) {
-            throw new IllegalArgumentException();
-        }
-        if (start < 0 || end > length) {
-            throw new ArrayIndexOutOfBoundsException();
-        }
+        checkBounds(array.length, start, end);
         for (int i = start; i < end; i++) {
             array[i] = value;
         }
@@ -624,14 +605,7 @@
      *                if {@code start < 0} or {@code end > array.length}.
      */
     public static void fill(int[] array, int start, int end, int value) {
-        // Check for null first
-        int length = array.length;
-        if (start > end) {
-            throw new IllegalArgumentException();
-        }
-        if (start < 0 || end > length) {
-            throw new ArrayIndexOutOfBoundsException();
-        }
+        checkBounds(array.length, start, end);
         for (int i = start; i < end; i++) {
             array[i] = value;
         }
@@ -668,14 +642,7 @@
      *                if {@code start < 0} or {@code end > array.length}.
      */
     public static void fill(long[] array, int start, int end, long value) {
-        // Check for null first
-        int length = array.length;
-        if (start > end) {
-            throw new IllegalArgumentException();
-        }
-        if (start < 0 || end > length) {
-            throw new ArrayIndexOutOfBoundsException();
-        }
+        checkBounds(array.length, start, end);
         for (int i = start; i < end; i++) {
             array[i] = value;
         }
@@ -712,14 +679,7 @@
      *                if {@code start < 0} or {@code end > array.length}.
      */
     public static void fill(float[] array, int start, int end, float value) {
-        // Check for null first
-        int length = array.length;
-        if (start > end) {
-            throw new IllegalArgumentException();
-        }
-        if (start < 0 || end > length) {
-            throw new ArrayIndexOutOfBoundsException();
-        }
+        checkBounds(array.length, start, end);
         for (int i = start; i < end; i++) {
             array[i] = value;
         }
@@ -756,14 +716,7 @@
      *                if {@code start < 0} or {@code end > array.length}.
      */
     public static void fill(double[] array, int start, int end, double value) {
-        // Check for null first
-        int length = array.length;
-        if (start > end) {
-            throw new IllegalArgumentException();
-        }
-        if (start < 0 || end > length) {
-            throw new ArrayIndexOutOfBoundsException();
-        }
+        checkBounds(array.length, start, end);
         for (int i = start; i < end; i++) {
             array[i] = value;
         }
@@ -800,14 +753,7 @@
      *                if {@code start < 0} or {@code end > array.length}.
      */
     public static void fill(boolean[] array, int start, int end, boolean value) {
-        // Check for null first
-        int length = array.length;
-        if (start > end) {
-            throw new IllegalArgumentException();
-        }
-        if (start < 0 || end > length) {
-            throw new ArrayIndexOutOfBoundsException();
-        }
+        checkBounds(array.length, start, end);
         for (int i = start; i < end; i++) {
             array[i] = value;
         }
@@ -844,14 +790,7 @@
      *                if {@code start < 0} or {@code end > array.length}.
      */
     public static void fill(Object[] array, int start, int end, Object value) {
-        // Check for null first
-        int length = array.length;
-        if (start > end) {
-            throw new IllegalArgumentException();
-        }
-        if (start < 0 || end > length) {
-            throw new ArrayIndexOutOfBoundsException();
-        }
+        checkBounds(array.length, start, end);
         for (int i = start; i < end; i++) {
             array[i] = value;
         }
@@ -1690,11 +1629,17 @@
 
     private static void checkBounds(int arrLength, int start, int end) {
         if (start > end) {
-            throw new IllegalArgumentException("start(" + start //$NON-NLS-1$
-                    + ") > end(" + end + ")"); //$NON-NLS-1$ //$NON-NLS-2$
+            // K0033=Start index ({0}) is greater than end index ({1})
+            throw new IllegalArgumentException(Msg.getString("K0033", //$NON-NLS-1$
+                    Integer.valueOf(start), Integer.valueOf(end)));
         }
-        if (start < 0 || end > arrLength) {
-            throw new ArrayIndexOutOfBoundsException();
+        if (start < 0) {
+            // K0052=Array index out of range\: {0}
+            throw new ArrayIndexOutOfBoundsException(Msg.getString("K0052", start)); //$NON-NLS-1$
+        }
+        if (end > arrLength) {
+            // K0052=Array index out of range\: {0}
+            throw new ArrayIndexOutOfBoundsException(Msg.getString("K0052", end)); //$NON-NLS-1$
         }
     }
 
diff --git a/luni/src/main/java/java/util/Collection.java b/luni/src/main/java/java/util/Collection.java
index 6447e39..1b5cff5 100644
--- a/luni/src/main/java/java/util/Collection.java
+++ b/luni/src/main/java/java/util/Collection.java
@@ -24,7 +24,7 @@
  * of {@code Collection}s.
  *
  * All direct or indirect implementations of {@code Collection} should implement at
- * least two constuctors. One with no parameters which creates an empty
+ * least two constructors. One with no parameters which creates an empty
  * collection and one with a parameter of type {@code Collection}. This second
  * constructor can be used to create a collection of different type as the
  * initial collection but with the same elements. Implementations of {@code Collection}
@@ -138,7 +138,7 @@
 
     /**
      * Tests whether this {@code Collection} contains all objects contained in the
-     * specified {@code Collection}. If an elemenet {@code elem} is contained several
+     * specified {@code Collection}. If an element {@code elem} is contained several
      * times in the specified {@code Collection}, the method returns {@code true} even
      * if {@code elem} is contained only once in this {@code Collection}.
      *
diff --git a/luni/src/main/java/java/util/Collections.java b/luni/src/main/java/java/util/Collections.java
index 767d98b..77cafea 100644
--- a/luni/src/main/java/java/util/Collections.java
+++ b/luni/src/main/java/java/util/Collections.java
@@ -23,6 +23,7 @@
 import java.lang.reflect.Array;
 
 import org.apache.harmony.luni.internal.nls.Messages;
+import org.apache.harmony.luni.util.Msg;
 
 /**
  * {@code Collections} contains static methods which operate on
@@ -1590,7 +1591,8 @@
     public static <T> void copy(List<? super T> destination,
             List<? extends T> source) {
         if (destination.size() < source.size()) {
-            throw new ArrayIndexOutOfBoundsException();
+            // K0032=Source size {0} does not fit into destination
+            throw new ArrayIndexOutOfBoundsException(Msg.getString("K0032", source.size())); //$NON-NLS-1$
         }
         Iterator<? extends T> srcIt = source.iterator();
         ListIterator<? super T> destIt = destination.listIterator();
@@ -1598,7 +1600,8 @@
             try {
                 destIt.next();
             } catch (NoSuchElementException e) {
-                throw new ArrayIndexOutOfBoundsException();
+                // K0032=Source size {0} does not fit into destination
+                throw new ArrayIndexOutOfBoundsException(Msg.getString("K0032", source.size())); //$NON-NLS-1$
             }
             destIt.set(srcIt.next());
         }
@@ -1841,36 +1844,30 @@
      * @throws UnsupportedOperationException
      *             when replacing an element in the list is not supported.
      */
-    @SuppressWarnings("unchecked")
     public static void shuffle(List<?> list, Random random) {
-        if (!(list instanceof RandomAccess)) {
-            Object[] array = list.toArray();
+        @SuppressWarnings("unchecked") // we won't put foreign objects in
+        final List<Object> objectList = (List<Object>) list;
+
+        if (list instanceof RandomAccess) {
+            for (int i = objectList.size() - 1; i > 0; i--) {
+                int index = random.nextInt(i + 1);
+                objectList.set(index, objectList.set(i, objectList.get(index)));
+            }
+        } else {
+            Object[] array = objectList.toArray();
             for (int i = array.length - 1; i > 0; i--) {
                 int index = random.nextInt(i + 1);
-                if (index < 0) {
-                    index = -index;
-                }
                 Object temp = array[i];
                 array[i] = array[index];
                 array[index] = temp;
             }
 
             int i = 0;
-            ListIterator<Object> it = (ListIterator<Object>) list
-                    .listIterator();
+            ListIterator<Object> it = objectList.listIterator();
             while (it.hasNext()) {
                 it.next();
                 it.set(array[i++]);
             }
-        } else {
-            List<Object> rawList = (List<Object>) list;
-            for (int i = rawList.size() - 1; i > 0; i--) {
-                int index = random.nextInt(i + 1);
-                if (index < 0) {
-                    index = -index;
-                }
-                rawList.set(index, rawList.set(i, rawList.get(index)));
-            }
         }
     }
 
diff --git a/luni/src/main/java/java/util/Formatter.java b/luni/src/main/java/java/util/Formatter.java
index 3d8b94e..912a15e 100644
--- a/luni/src/main/java/java/util/Formatter.java
+++ b/luni/src/main/java/java/util/Formatter.java
@@ -2115,18 +2115,15 @@
 
             } else {
                 l = b.movePointRight(4).longValue();
-                b.movePointLeft(4);
                 if (d >= Math.pow(10, -4) && d < 1) {
                     requireScientificRepresentation = false;
                     precision += 4 - String.valueOf(l).length();
                     l = b.movePointRight(precision + 1).longValue();
-                    b.movePointLeft(precision + 1);
                     if (String.valueOf(l).length() <= formatToken
                             .getPrecision()) {
                         precision++;
                     }
                     l = b.movePointRight(precision).longValue();
-                    b.movePointLeft(precision);
                     if (l >= Math.pow(10, precision - 4)) {
                         formatToken.setPrecision(precision);
                     }
diff --git a/luni/src/main/java/java/util/GregorianCalendar.java b/luni/src/main/java/java/util/GregorianCalendar.java
index d8cd556..7339151 100644
--- a/luni/src/main/java/java/util/GregorianCalendar.java
+++ b/luni/src/main/java/java/util/GregorianCalendar.java
@@ -533,7 +533,6 @@
         fields[MINUTE] = (millis % 60);
         millis /= 60;
         fields[HOUR_OF_DAY] = (millis % 24);
-        millis /= 24;
         fields[AM_PM] = fields[HOUR_OF_DAY] > 11 ? 1 : 0;
         fields[HOUR] = fields[HOUR_OF_DAY] % 12;
 
diff --git a/luni/src/main/java/java/util/Locale.java b/luni/src/main/java/java/util/Locale.java
index b1a1821..3d724d0 100644
--- a/luni/src/main/java/java/util/Locale.java
+++ b/luni/src/main/java/java/util/Locale.java
@@ -48,7 +48,9 @@
 
     private static final long serialVersionUID = 9149081749638150636L;
 
+    // BEGIN android-added
     private static volatile Locale[] availableLocales;
+    // END android-added
 
     // Initialize a default which is used during static
     // initialization of the default for the platform.
@@ -304,93 +306,6 @@
         return false;
     }
 
-    // BEGIN android-removed
-    // static Locale[] find(String prefix) {
-    //     int last = prefix.lastIndexOf('/');
-    //     final String thePackage = prefix.substring(0, last + 1);
-    //     int length = prefix.length();
-    //     final String classPrefix = prefix.substring(last + 1, length);
-    //     Set<String> result = new HashSet<String>();
-    //     StringTokenizer paths = new StringTokenizer(System.getProperty(
-    //             "org.apache.harmony.boot.class.path", ""), System.getProperty( //$NON-NLS-1$ //$NON-NLS-2$
-    //             "path.separator", ";")); //$NON-NLS-1$//$NON-NLS-2$
-    //     while (paths.hasMoreTokens()) {
-    //         String nextToken = paths.nextToken();
-    //         File directory = new File(nextToken);
-    //         if (directory.exists()) {
-    //             if (directory.isDirectory()) {
-    //                 String path;
-    //                 try {
-    //                     path = directory.getCanonicalPath();
-    //                 } catch (IOException e) {
-    //                     continue;
-    //                 }
-    //                 File newDir;
-    //                 if (path.charAt(path.length() - 1) == File.separatorChar) {
-    //                     newDir = new File(path + thePackage);
-    //                 } else {
-    //                     newDir = new File(path + File.separatorChar
-    //                             + thePackage);
-    //                 }
-    //                 if (newDir.isDirectory()) {
-    //                     String[] list = newDir.list();
-    //                     for (int i = 0; i < list.length; i++) {
-    //                         String name = list[i];
-    //                         if (name.startsWith(classPrefix)
-    //                                 && name.endsWith(".class")) { //$NON-NLS-1$
-    //                             result
-    //                                     .add(name.substring(0,
-    //                                             name.length() - 6));
-    //                         }
-    //                     }
-    //                 }
-    //
-    //             } else {
-    //                 // Handle ZIP/JAR files.
-    //                 try {
-    //                     ZipFile zip = new ZipFile(directory);
-    //                     Enumeration<? extends ZipEntry> entries = zip.entries();
-    //                     while (entries.hasMoreElements()) {
-    //                         ZipEntry e = entries.nextElement();
-    //                         String name = e.getName();
-    //                         if (name.startsWith(prefix)
-    //                                 && name.endsWith(".class")) {//$NON-NLS-1$
-    //                             result.add(name.substring(last + 1, name
-    //                                     .length() - 6));
-    //                         }
-    //                     }
-    //                     zip.close();
-    //                 } catch (IOException e) {
-    //                     // Empty
-    //                 }
-    //             }
-    //         }
-    //     }
-    //     Locale[] locales = new Locale[result.size()];
-    //     int i = 0;
-    //     for (String name : result) {
-    //         int index = name.indexOf('_');
-    //         int nextIndex = name.indexOf('_', index + 1);
-    //         if (nextIndex == -1) {
-    //             locales[i++] = new Locale(name.substring(index + 1, name
-    //                     .length()), ""); //$NON-NLS-1$
-    //         } else {
-    //             String language = name.substring(index + 1, nextIndex);
-    //             String variant;
-    //             if ((index = name.indexOf('_', nextIndex + 1)) == -1) {
-    //                 variant = ""; //$NON-NLS-1$
-    //                 index = name.length();
-    //             } else {
-    //                 variant = name.substring(index + 1, name.length());
-    //             }
-    //             String country = name.substring(nextIndex + 1, index);
-    //             locales[i++] = new Locale(language, country, variant);
-    //         }
-    //     }
-    //     return locales;
-    // }
-    // END android-removed
-
     // BEGIN android-added
     static Locale[] find() {
         String[] locales = Resources.getAvailableLocales();
diff --git a/luni/src/main/java/java/util/Scanner.java b/luni/src/main/java/java/util/Scanner.java
index dd5c024..f1ca423 100644
--- a/luni/src/main/java/java/util/Scanner.java
+++ b/luni/src/main/java/java/util/Scanner.java
@@ -1039,7 +1039,7 @@
      * Returns the next token if it matches the specified pattern. The token
      * will be both prefixed and postfixed by the delimiter that is currently
      * being used (or a string that matches the delimiter pattern). This method will block
-     * if input is being read. Calling this methos is equivalent to
+     * if input is being read. Calling this method is equivalent to
      * {@code next(Pattern.compile(pattern))}.
      *
      * @param pattern
@@ -1638,7 +1638,7 @@
      * Returns a string representation of this {@code Scanner}. The information
      * returned may be helpful for debugging. The format of the string is unspecified.
      *
-     * @return a string represendation of this {@code Scanner}.
+     * @return a string representation of this {@code Scanner}.
      */
     @Override
     public String toString() {
diff --git a/luni/src/main/java/java/util/UnknownFormatFlagsException.java b/luni/src/main/java/java/util/UnknownFormatFlagsException.java
index 2a1b075..66d9076 100644
--- a/luni/src/main/java/java/util/UnknownFormatFlagsException.java
+++ b/luni/src/main/java/java/util/UnknownFormatFlagsException.java
@@ -60,6 +60,7 @@
      */
     @Override
     public String getMessage() {
-        return Msg.getString("K034a", flags);
+        // K034a=The flags are {0}
+        return Msg.getString("K034a", flags); //$NON-NLS-1$
     }
 }
diff --git a/luni/src/main/java/org/apache/harmony/luni/internal/io/FileCanonPathCache.java b/luni/src/main/java/org/apache/harmony/luni/internal/io/FileCanonPathCache.java
index e3ea7b5..c1ffef9 100644
--- a/luni/src/main/java/org/apache/harmony/luni/internal/io/FileCanonPathCache.java
+++ b/luni/src/main/java/org/apache/harmony/luni/internal/io/FileCanonPathCache.java
@@ -40,7 +40,7 @@
     }
 
     /**
-     * Max elemnts could be hold in the cache.
+     * Max elements could be hold in the cache.
      */
     public static final int CACHE_SIZE = 256;
 
diff --git a/luni/src/main/java/org/apache/harmony/luni/internal/net/www/protocol/http/Handler.java b/luni/src/main/java/org/apache/harmony/luni/internal/net/www/protocol/http/Handler.java
index 25d1e69..94719fe 100644
--- a/luni/src/main/java/org/apache/harmony/luni/internal/net/www/protocol/http/Handler.java
+++ b/luni/src/main/java/org/apache/harmony/luni/internal/net/www/protocol/http/Handler.java
@@ -44,7 +44,7 @@
      */
     @Override
     protected URLConnection openConnection(URL u) throws IOException {
-        return new HttpURLConnection(u, getDefaultPort());
+        return new HttpURLConnectionImpl(u, getDefaultPort());
     }
 
     /**
@@ -72,7 +72,7 @@
         if (null == u || null == proxy) {
             throw new IllegalArgumentException(Msg.getString("K034b")); //$NON-NLS-1$
         }
-        return new HttpURLConnection(u, getDefaultPort(), proxy);
+        return new HttpURLConnectionImpl(u, getDefaultPort(), proxy);
     }
 
     /**
diff --git a/luni/src/main/java/org/apache/harmony/luni/internal/net/www/protocol/http/HttpURLConnection.java b/luni/src/main/java/org/apache/harmony/luni/internal/net/www/protocol/http/HttpURLConnectionImpl.java
similarity index 97%
rename from luni/src/main/java/org/apache/harmony/luni/internal/net/www/protocol/http/HttpURLConnection.java
rename to luni/src/main/java/org/apache/harmony/luni/internal/net/www/protocol/http/HttpURLConnectionImpl.java
index 2dea92b..1ba7d8c 100644
--- a/luni/src/main/java/org/apache/harmony/luni/internal/net/www/protocol/http/HttpURLConnection.java
+++ b/luni/src/main/java/org/apache/harmony/luni/internal/net/www/protocol/http/HttpURLConnectionImpl.java
@@ -25,6 +25,7 @@
 import java.net.Authenticator;
 import java.net.CacheRequest;
 import java.net.CacheResponse;
+import java.net.HttpURLConnection;
 import java.net.InetAddress;
 import java.net.InetSocketAddress;
 import java.net.PasswordAuthentication;
@@ -58,7 +59,7 @@
  * such as connecting, sending request and getting the content from the remote
  * server.
  */
-public class HttpURLConnection extends java.net.HttpURLConnection {
+public class HttpURLConnectionImpl extends HttpURLConnection {
     private static final String POST = "POST"; //$NON-NLS-1$
 
     private static final String GET = "GET"; //$NON-NLS-1$
@@ -280,13 +281,14 @@
 
         @Override
         public int read(byte[] buf, int offset, int length) throws IOException {
-            if (buf == null) {
-                throw new NullPointerException();
+            // Force buf null check first, and avoid int overflow
+            if (offset < 0 || offset > buf.length) {
+                // K002e=Offset out of bounds \: {0}
+                throw new ArrayIndexOutOfBoundsException(Msg.getString("K002e", offset)); //$NON-NLS-1$
             }
-            // avoid int overflow
-            if (offset < 0 || length < 0 || offset > buf.length
-                    || buf.length - offset < length) {
-                throw new ArrayIndexOutOfBoundsException();
+            if (length < 0 || buf.length - offset < length) {
+                // K0031=Length out of bounds \: {0}
+                throw new ArrayIndexOutOfBoundsException(Msg.getString("K0031", length)); //$NON-NLS-1$
             }
             if (bytesRemaining <= 0) {
                 disconnect(false);
@@ -421,13 +423,14 @@
 
         @Override
         public int read(byte[] buf, int offset, int length) throws IOException {
-            if (buf == null) {
-                throw new NullPointerException();
+            // Force buf null check first, and avoid int overflow
+            if (offset > buf.length || offset < 0) {
+                // K002e=Offset out of bounds \: {0}
+                throw new ArrayIndexOutOfBoundsException(Msg.getString("K002e", offset)); //$NON-NLS-1$
             }
-            // avoid int overflow
-            if (offset < 0 || length < 0 || offset > buf.length
-                    || buf.length - offset < length) {
-                throw new ArrayIndexOutOfBoundsException();
+            if (length < 0 || buf.length - offset < length) {
+                // K0031=Length out of bounds \: {0}
+                throw new ArrayIndexOutOfBoundsException(Msg.getString("K0031", length)); //$NON-NLS-1$
             }
             if (bytesRemaining <= 0) {
                 readChunkSize();
@@ -690,7 +693,7 @@
      * @param url
      *            URL The URL this connection is connecting
      */
-    protected HttpURLConnection(URL url) {
+    protected HttpURLConnectionImpl(URL url) {
         this(url, 80);
     }
 
@@ -702,7 +705,7 @@
      * @param port
      *            int The default connection port
      */
-    protected HttpURLConnection(URL url, int port) {
+    protected HttpURLConnectionImpl(URL url, int port) {
         super(url);
         defaultPort = port;
         reqHeader = (Header) defaultReqHeader.clone();
@@ -730,7 +733,7 @@
      * @param proxy
      *            Proxy The proxy which is used to make the connection
      */
-    protected HttpURLConnection(URL url, int port, Proxy proxy) {
+    protected HttpURLConnectionImpl(URL url, int port, Proxy proxy) {
         this(url, port);
         this.proxy = proxy;
     }
diff --git a/luni/src/main/java/org/apache/harmony/luni/internal/net/www/protocol/https/Handler.java b/luni/src/main/java/org/apache/harmony/luni/internal/net/www/protocol/https/Handler.java
index ef68a71..c6bf994 100644
--- a/luni/src/main/java/org/apache/harmony/luni/internal/net/www/protocol/https/Handler.java
+++ b/luni/src/main/java/org/apache/harmony/luni/internal/net/www/protocol/https/Handler.java
@@ -32,7 +32,7 @@
 
     @Override
     protected URLConnection openConnection(URL url) throws IOException {
-        return new HttpsURLConnection(url, getDefaultPort());
+        return new HttpsURLConnectionImpl(url, getDefaultPort());
     }
 
     @Override
@@ -42,7 +42,7 @@
             // K034b=url and proxy can not be null
             throw new IllegalArgumentException(Msg.getString("K034b")); //$NON-NLS-1$
         }
-        return new HttpsURLConnection(url, getDefaultPort(), proxy);
+        return new HttpsURLConnectionImpl(url, getDefaultPort(), proxy);
     }
 
     @Override
diff --git a/luni/src/main/java/org/apache/harmony/luni/internal/net/www/protocol/https/HttpsURLConnection.java b/luni/src/main/java/org/apache/harmony/luni/internal/net/www/protocol/https/HttpsURLConnectionImpl.java
similarity index 96%
rename from luni/src/main/java/org/apache/harmony/luni/internal/net/www/protocol/https/HttpsURLConnection.java
rename to luni/src/main/java/org/apache/harmony/luni/internal/net/www/protocol/https/HttpsURLConnectionImpl.java
index 4d0aff7..2ad5b13 100644
--- a/luni/src/main/java/org/apache/harmony/luni/internal/net/www/protocol/https/HttpsURLConnection.java
+++ b/luni/src/main/java/org/apache/harmony/luni/internal/net/www/protocol/https/HttpsURLConnectionImpl.java
@@ -28,16 +28,17 @@
 import java.util.List;
 import java.util.Map;
 
+import javax.net.ssl.HttpsURLConnection;
 import javax.net.ssl.SSLPeerUnverifiedException;
 import javax.net.ssl.SSLSocket;
 
-import org.apache.harmony.luni.internal.net.www.protocol.http.HttpURLConnection;
+import org.apache.harmony.luni.internal.net.www.protocol.http.HttpURLConnectionImpl;
 import org.apache.harmony.luni.internal.nls.Messages;
 
 /**
  * HttpsURLConnection implementation.
  */
-public class HttpsURLConnection extends javax.net.ssl.HttpsURLConnection {
+public class HttpsURLConnectionImpl extends HttpsURLConnection {
 
     // Https engine to be wrapped
     private final HttpsEngine httpsEngine;
@@ -45,12 +46,12 @@
     // SSLSocket to be used for connection
     private SSLSocket sslSocket;
 
-    protected HttpsURLConnection(URL url, int port) {
+    protected HttpsURLConnectionImpl(URL url, int port) {
         super(url);
         httpsEngine = new HttpsEngine(url, port);
     }
 
-    protected HttpsURLConnection(URL url, int port, Proxy proxy) {
+    protected HttpsURLConnectionImpl(URL url, int port, Proxy proxy) {
         super(url);
         httpsEngine = new HttpsEngine(url, port, proxy);
     }
@@ -345,7 +346,7 @@
     /**
      * HttpsEngine
      */
-    private class HttpsEngine extends HttpURLConnection {
+    private class HttpsEngine extends HttpURLConnectionImpl {
 
         // In case of using proxy this field indicates
         // if it is a SSL Tunnel establishing stage
@@ -364,7 +365,7 @@
             if (connected) {
                 return;
             }
-            if (usingProxy() && !makingSSLTunnel) {
+            if (super.usingProxy() && !makingSSLTunnel) {
                 // SSL Tunnel through the proxy was not established yet, do so
                 makingSSLTunnel = true;
                 // first - make the connection
@@ -402,7 +403,7 @@
 
         @Override
         protected String requestString() {
-            if (usingProxy()) {
+            if (super.usingProxy()) {
                 if (makingSSLTunnel) {
                     // we are making the SSL Tunneling, return remotehost:port
                     int port = url.getPort();
diff --git a/luni/src/main/java/org/apache/harmony/luni/internal/net/www/protocol/jar/Handler.java b/luni/src/main/java/org/apache/harmony/luni/internal/net/www/protocol/jar/Handler.java
index 4db9910..b31cb39 100644
--- a/luni/src/main/java/org/apache/harmony/luni/internal/net/www/protocol/jar/Handler.java
+++ b/luni/src/main/java/org/apache/harmony/luni/internal/net/www/protocol/jar/Handler.java
@@ -42,7 +42,7 @@
      */
     @Override
     protected URLConnection openConnection(URL u) throws IOException {
-        return new JarURLConnection(u);
+        return new JarURLConnectionImpl(u);
     }
 
     /**
diff --git a/luni/src/main/java/org/apache/harmony/luni/internal/net/www/protocol/jar/JarURLConnection.java b/luni/src/main/java/org/apache/harmony/luni/internal/net/www/protocol/jar/JarURLConnectionImpl.java
similarity index 70%
rename from luni/src/main/java/org/apache/harmony/luni/internal/net/www/protocol/jar/JarURLConnection.java
rename to luni/src/main/java/org/apache/harmony/luni/internal/net/www/protocol/jar/JarURLConnectionImpl.java
index 34e7d07..493b768 100644
--- a/luni/src/main/java/org/apache/harmony/luni/internal/net/www/protocol/jar/JarURLConnection.java
+++ b/luni/src/main/java/org/apache/harmony/luni/internal/net/www/protocol/jar/JarURLConnectionImpl.java
@@ -25,6 +25,7 @@
 import java.io.InputStream;
 import java.net.ContentHandler;
 import java.net.ContentHandlerFactory;
+import java.net.JarURLConnection;
 import java.net.MalformedURLException;
 import java.net.URL;
 import java.security.AccessController;
@@ -42,13 +43,13 @@
 import org.apache.harmony.luni.util.Util;
 
 /**
- * This subclass extends <code>URLConnection</code>.
+ * This subclass extends {@code URLConnection}.
  * <p>
  *
  * This class is responsible for connecting and retrieving resources from a Jar
- * file which can be anywhere that can be refered to by an URL.
+ * file which can be anywhere that can be referred to by an URL.
  */
-public class JarURLConnection extends java.net.JarURLConnection {
+public class JarURLConnectionImpl extends JarURLConnection {
 
     static HashMap<URL, JarFile> jarCache = new HashMap<URL, JarFile>();
 
@@ -62,14 +63,16 @@
 
     private boolean closed;
 
-
     /**
      * @param url
      *            the URL of the JAR
      * @throws MalformedURLException
      *             if the URL is malformed
+     * @throws IOException
+     *             if there is a problem opening the connection.
      */
-    public JarURLConnection(java.net.URL url) throws MalformedURLException, IOException {
+    public JarURLConnectionImpl(URL url) throws MalformedURLException,
+            IOException {
         super(url);
         jarFileURL = getJarFileURL();
         jarFileURLConnection = jarFileURL.openConnection();
@@ -88,8 +91,8 @@
     }
 
     /**
-     * Returns the Jar file refered by this <code>URLConnection</code>
-     *
+     * Returns the Jar file referred by this {@code URLConnection}.
+     * 
      * @return the JAR file referenced by this connection
      *
      * @throws IOException
@@ -103,30 +106,30 @@
     }
 
     /**
-     * Returns the Jar file refered by this <code>URLConnection</code>
-     *
+     * Returns the Jar file referred by this {@code URLConnection}
+     * 
      * @throws IOException
      *             if an IO error occurs while connecting to the resource.
      */
     private void findJarFile() throws IOException {
         JarFile jar = null;
         if (getUseCaches()) {
-            synchronized(jarCache){
+            synchronized (jarCache) {
                 jarFile = jarCache.get(jarFileURL);
             }
             if (jarFile == null) {
                 jar = openJarFile();
-                synchronized(jarCache){
+                synchronized (jarCache) {
                     jarFile = jarCache.get(jarFileURL);
-                    if (jarFile == null){
+                    if (jarFile == null) {
                         jarCache.put(jarFileURL, jar);
                         jarFile = jar;
-                    }else{
+                    } else {
                         jar.close();
                     }
                 }
             }
-        }else{
+        } else {
             jarFile = openJarFile();
         }
 
@@ -135,38 +138,42 @@
         }
     }
 
+    @SuppressWarnings("nls")
     JarFile openJarFile() throws IOException {
         JarFile jar = null;
-        if (jarFileURL.getProtocol().equals("file")) { //$NON-NLS-1$
+        if (jarFileURL.getProtocol().equals("file")) {
             jar = new JarFile(new File(Util.decode(jarFileURL.getFile(), false,
                     "UTF-8")), true, ZipFile.OPEN_READ);
         } else {
             final InputStream is = jarFileURL.openConnection().getInputStream();
             try {
                 jar = AccessController
-                    .doPrivileged(new PrivilegedAction<JarFile>() {
-                        public JarFile run() {
-                            try {
-                                File tempJar = File.createTempFile("hyjar_", //$NON-NLS-1$
-                                        ".tmp", null); //$NON-NLS-1$
-                                tempJar.deleteOnExit();
-                                FileOutputStream fos = new FileOutputStream(
-                                        tempJar);
-                                byte[] buf = new byte[4096];
-                                int nbytes = 0;
-                                while ((nbytes = is.read(buf)) > -1) {
-                                    fos.write(buf, 0, nbytes);
+                        .doPrivileged(new PrivilegedAction<JarFile>() {
+                            public JarFile run() {
+                                try {
+                                    File tempJar = File.createTempFile(
+                                            "hyjar_", ".tmp", null);
+                                    tempJar.deleteOnExit();
+                                    FileOutputStream fos = new FileOutputStream(
+                                            tempJar);
+                                    byte[] buf = new byte[4096];
+                                    int nbytes = 0;
+                                    while ((nbytes = is.read(buf)) > -1) {
+                                        fos.write(buf, 0, nbytes);
+                                    }
+                                    fos.close();
+                                    return new JarFile(tempJar, true,
+                                            ZipFile.OPEN_READ
+                                                    | ZipFile.OPEN_DELETE);
+                                } catch (IOException e) {
+                                    return null;
                                 }
-                                fos.close();
-                                return new JarFile(tempJar,
-                                        true, ZipFile.OPEN_READ | ZipFile.OPEN_DELETE);
-                            } catch (IOException e) {
-                                return null;
                             }
-                        }
-                    });
+                        });
             } finally {
-                if (is != null) is.close();
+                if (is != null) {
+                    is.close();
+                }
             }
         }
 
@@ -174,11 +181,11 @@
     }
 
     /**
-     * Returns the JarEntry of the entry referenced by this
-     * <code>URLConnection</code>.
-     *
-     * @return java.util.jar.JarEntry the JarEntry referenced
-     *
+     * Returns the JarEntry of the entry referenced by this {@code
+     * URLConnection}.
+     * 
+     * @return the JarEntry referenced
+     * 
      * @throws IOException
      *             if an IO error occurs while getting the entry
      */
@@ -190,8 +197,8 @@
     }
 
     /**
-     * Look up the JarEntry of the entry referenced by this
-     * <code>URLConnection</code>.
+     * Look up the JarEntry of the entry referenced by this {@code
+     * URLConnection}.
      */
     private void findJarEntry() throws IOException {
         if (getEntryName() == null) {
@@ -213,15 +220,16 @@
      */
     @Override
     public InputStream getInputStream() throws IOException {
-
         if (closed) {
-            throw new IllegalStateException(Msg.getString("KA027"));
+            // KA027=Inputstream of the JarURLConnection has been closed
+            throw new IllegalStateException(Msg.getString("KA027")); //$NON-NLS-1$
         }
         connect();
         if (jarInput != null) {
             return jarInput;
         }
         if (jarEntry == null) {
+            // K00fc=Jar entry not specified
             throw new IOException(Msg.getString("K00fc")); //$NON-NLS-1$
         }
         return jarInput = new JarURLConnectionInputStream(jarFile
@@ -229,11 +237,11 @@
     }
 
     /**
-     * Returns the content type of the resource.
-     * For jar file itself "x-java/jar" should be returned,
-     * for jar entries the content type of the entry should be returned.
-     * Returns non-null results ("content/unknown" for unknown types).
-     *
+     * Returns the content type of the resource. For jar file itself
+     * "x-java/jar" should be returned, for jar entries the content type of the
+     * entry should be returned. Returns non-null results ("content/unknown" for
+     * unknown types).
+     * 
      * @return the content type
      */
     @Override
@@ -241,31 +249,30 @@
         if (url.getFile().endsWith("!/")) { //$NON-NLS-1$
             // the type for jar file itself is always "x-java/jar"
             return "x-java/jar"; //$NON-NLS-1$
-        } else {
-            String cType = null;
-            String entryName = getEntryName();
-
-            if (entryName != null) {
-                // if there is an Jar Entry, get the content type from the name
-                cType = guessContentTypeFromName(entryName);
-            } else {
-                try {
-                    connect();
-                    cType = jarFileURLConnection.getContentType();
-                } catch (IOException ioe) {
-                    // Ignore
-                }
-            }
-            if (cType == null) {
-                cType = "content/unknown"; //$NON-NLS-1$
-            }
-            return cType;
         }
+        String cType = null;
+        String entryName = getEntryName();
+
+        if (entryName != null) {
+            // if there is an Jar Entry, get the content type from the name
+            cType = guessContentTypeFromName(entryName);
+        } else {
+            try {
+                connect();
+                cType = jarFileURLConnection.getContentType();
+            } catch (IOException ioe) {
+                // Ignore
+            }
+        }
+        if (cType == null) {
+            cType = "content/unknown"; //$NON-NLS-1$
+        }
+        return cType;
     }
 
     /**
      * Returns the content length of the resource. Test cases reveal that if the
-     * URL is refering to a Jar file, this method returns a content-length
+     * URL is referring to a Jar file, this method answers a content-length
      * returned by URLConnection. For jar entry it should return it's size.
      * Otherwise, it will return -1.
      *
@@ -277,26 +284,25 @@
             connect();
             if (jarEntry == null) {
                 return jarFileURLConnection.getContentLength();
-            } else {
-                return (int) getJarEntry().getSize();
             }
+            return (int) getJarEntry().getSize();
         } catch (IOException e) {
-            //Ignored
+            // Ignored
         }
         return -1;
     }
 
     /**
-     * Returns the object pointed by this <code>URL</code>. If this
-     * URLConnection is pointing to a Jar File (no Jar Entry), this method will
-     * return a <code>JarFile</code> If there is a Jar Entry, it will return
-     * the object corresponding to the Jar entry content type.
-     *
+     * Returns the object pointed by this {@code URL}. If this URLConnection is
+     * pointing to a Jar File (no Jar Entry), this method will return a {@code
+     * JarFile} If there is a Jar Entry, it will return the object corresponding
+     * to the Jar entry content type.
+     * 
      * @return a non-null object
      *
      * @throws IOException
-     *             if an IO error occured
-     *
+     *             if an IO error occurred
+     * 
      * @see ContentHandler
      * @see ContentHandlerFactory
      * @see java.io.IOException
@@ -354,9 +360,9 @@
      */
     public static void closeCachedFiles() {
         Set<Map.Entry<URL, JarFile>> s = jarCache.entrySet();
-        synchronized(jarCache){
+        synchronized (jarCache) {
             Iterator<Map.Entry<URL, JarFile>> i = s.iterator();
-            while(i.hasNext()){
+            while (i.hasNext()) {
                 try {
                     ZipFile zip = i.next().getValue();
                     if (zip != null) {
@@ -366,7 +372,7 @@
                     // Ignored
                 }
             }
-       }
+        }
     }
 
     private class JarURLConnectionInputStream extends FilterInputStream {
diff --git a/luni/src/main/java/org/apache/harmony/luni/net/PlainDatagramSocketImpl.java b/luni/src/main/java/org/apache/harmony/luni/net/PlainDatagramSocketImpl.java
index ac0c877..7ae9de6 100644
--- a/luni/src/main/java/org/apache/harmony/luni/net/PlainDatagramSocketImpl.java
+++ b/luni/src/main/java/org/apache/harmony/luni/net/PlainDatagramSocketImpl.java
@@ -154,7 +154,6 @@
         close();
     }
 
-    @Override
     public Object getOption(int optID) throws SocketException {
         if (optID == SocketOptions.SO_TIMEOUT) {
             return Integer.valueOf(receiveTimeout);
@@ -285,7 +284,6 @@
      * @throws SocketException thrown if the option value is unsupported or
      *         invalid
      */
-    @Override
     public void setOption(int optID, Object val) throws SocketException {
         /*
          * for datagram sockets on some platforms we have to set both the
diff --git a/luni/src/main/java/org/apache/harmony/luni/net/SocketInputStream.java b/luni/src/main/java/org/apache/harmony/luni/net/SocketInputStream.java
index 4b0b4b4..d19206d 100644
--- a/luni/src/main/java/org/apache/harmony/luni/net/SocketInputStream.java
+++ b/luni/src/main/java/org/apache/harmony/luni/net/SocketInputStream.java
@@ -78,7 +78,8 @@
         }
 
         if (0 > offset || offset >= buffer.length) {
-            throw new ArrayIndexOutOfBoundsException(Msg.getString("K002e"));//$NON-NLS-1$
+            // K002e=Offset out of bounds \: {0}
+            throw new ArrayIndexOutOfBoundsException(Msg.getString("K002e", offset));//$NON-NLS-1$
         }
         if (0 > count || offset + count > buffer.length) {
             throw new ArrayIndexOutOfBoundsException(Msg.getString("K002f"));//$NON-NLS-1$
diff --git a/luni/src/main/java/org/apache/harmony/luni/platform/INetworkSystem.java b/luni/src/main/java/org/apache/harmony/luni/platform/INetworkSystem.java
index fb47f0d..3577451 100644
--- a/luni/src/main/java/org/apache/harmony/luni/platform/INetworkSystem.java
+++ b/luni/src/main/java/org/apache/harmony/luni/platform/INetworkSystem.java
@@ -66,6 +66,11 @@
     public int writeDirect(FileDescriptor fd, int address, int offset, int count)
             throws IOException;
 
+    // BEGIN android-removed
+    // public int writev(FileDescriptor fd, Object[] buffers, int[] offsets,
+    //         int[] counts, int length) throws IOException;
+    // END android-removed
+
     public void setNonBlocking(FileDescriptor aFD, boolean block)
             throws IOException;
 
diff --git a/luni/src/main/java/org/apache/harmony/luni/platform/OSMemory.java b/luni/src/main/java/org/apache/harmony/luni/platform/OSMemory.java
index 0061d2a..8d06b1c 100644
--- a/luni/src/main/java/org/apache/harmony/luni/platform/OSMemory.java
+++ b/luni/src/main/java/org/apache/harmony/luni/platform/OSMemory.java
@@ -73,29 +73,33 @@
         return singleton;
     }
 
-    /**
-     * This class is not designed to be publicly instantiated.
-     *
-     * @see #getOSMemory()
+    /*
+     * Native method to determine whether the underlying platform is little
+     * endian.
+     * 
+     * @return <code>true</code> if the platform is little endian or
+     * <code>false</code> if it is big endian.
      */
-    private OSMemory() {
-        super();
-    }
-
-    /**
-     * Returns whether the byte order of this machine is little endian or not..
-     *
-	 * @return <code>false</code> for Big Endian, and
-	 *         <code>true</code. for Little Endian.
-     */
-    // BEGIN android-changed
-    /*public*/
     private static native boolean isLittleEndianImpl();
-    // END android-changed
 
-    public boolean isLittleEndian() {
-        return isLittleEndianImpl();
-    }
+	/**
+	 * This class is not designed to be publicly instantiated.
+	 * 
+	 * @see #getOSMemory()
+	 */
+	private OSMemory() {
+		super();
+	}
+
+    /**
+     * Returns whether the byte order of this machine is little endian or not.
+     * 
+     * @return <code>false</code> for Big Endian, and
+     *         <code>true</code> for Little Endian.
+     */
+	public boolean isLittleEndian() {
+		return NATIVE_ORDER == Endianness.LITTLE_ENDIAN;
+	}
 
 	/**
 	 * Returns the natural byte order for this machine.
@@ -128,16 +132,8 @@
      * @return the address of the start of the memory block.
 	 * @throws OutOfMemoryError
 	 *             if the request cannot be satisfied.
-     */
-    // BEGIN android-changed
-    // public long malloc(long length) throws OutOfMemoryError
-    // {
-    //     OSResourcesMonitor.ensurePhysicalMemoryCapacity();
-    //     return mallocNative(length);
-    // }
-    // private native long mallocNative(long length) throws OutOfMemoryError;
+	 */
     public native int malloc(int length) throws OutOfMemoryError;
-    // END android-changed
 
     /**
      * Deallocates space for a memory block that was previously allocated by a
@@ -620,10 +616,8 @@
 
     public int mmap(int fileDescriptor, long alignment, long size,
             int mapMode) throws IOException {
+        // No need to check mmapImpl return as it throws IOException in error cases
         int address = mmapImpl(fileDescriptor, alignment, size, mapMode);
-        if (address == -1) {
-            throw new IOException();
-        }
         return address;
     }
 
diff --git a/luni/src/main/java/org/apache/harmony/luni/platform/OSNetworkSystem.java b/luni/src/main/java/org/apache/harmony/luni/platform/OSNetworkSystem.java
index bd6a6097..a3eae58 100644
--- a/luni/src/main/java/org/apache/harmony/luni/platform/OSNetworkSystem.java
+++ b/luni/src/main/java/org/apache/harmony/luni/platform/OSNetworkSystem.java
@@ -829,4 +829,28 @@
 
     static native int writeSocketDirectImpl(FileDescriptor fd, int address, int offset, int count)
             throws IOException;
+
+    // BEGIN android-removed
+    // /**
+    //  * Write given buffers to a socket. The given buffers is a Object array, the
+    //  * element of array must be direct buffer or a byte array to be written.
+    //  *
+    //  * @param fd
+    //  *            the socket on which to write the bytes
+    //  * @param buffers
+    //  *            the element of array must be direct buffer or a byte array to
+    //  *            be written
+    //  * @param offsets
+    //  *            the index of the first byte to be write
+    //  * @param counts
+    //  *            the maximum number of bytes to be written
+    //  * @param length
+    //  *            the size of buffer array
+    //  * @return the actual number of bytes written
+    //  * @throws IOException
+    //  *             if there is an underlying socket problem
+    //  */
+    // public native int writev(FileDescriptor fd, Object[] buffers,
+    //         int[] offsets, int[] counts, int length) throws IOException;
+    // END android-removed
 }
diff --git a/luni/src/main/java/org/apache/harmony/luni/platform/PlatformAddress.java b/luni/src/main/java/org/apache/harmony/luni/platform/PlatformAddress.java
index 43702b2..0149cac 100644
--- a/luni/src/main/java/org/apache/harmony/luni/platform/PlatformAddress.java
+++ b/luni/src/main/java/org/apache/harmony/luni/platform/PlatformAddress.java
@@ -21,14 +21,17 @@
 
 package org.apache.harmony.luni.platform;
 
-
 /**
  * The platform address class is an unsafe virtualization of an OS memory block.
- * 
  */
 public class PlatformAddress implements ICommonDataTypes, Comparable {
 
     /**
+     * This final field defines the sentinel for an unknown address value.
+     */
+    static final int UNKNOWN = -1;
+
+    /**
      * This final field defines the size of an address on this platform.
      */
     static final int SIZEOF = Platform.getMemorySystem().getPointerSize();
@@ -38,12 +41,17 @@
      */
     public static final PlatformAddress NULL = new PlatformAddress(0, 0);
 
+    /**
+     * INVALID is the canonical address with an invalid value
+     * (i.e. a non-address).
+     */
+    public static final PlatformAddress INVALID =
+            new PlatformAddress(UNKNOWN, UNKNOWN);
+
     public static final IMemorySpy memorySpy = new RuntimeMemorySpy();
 
     static final IMemorySystem osMemory = Platform.getMemorySystem();
 
-    static final long UNKNOWN = -1;
-
     final int osaddr;
     
     final long size;
@@ -65,7 +73,7 @@
         memorySpy.autoFree(this);
     }
     
-    public PlatformAddress duplicate(){
+    public PlatformAddress duplicate() {
         return PlatformAddressFactory.on(osaddr, size);
     }
 
@@ -264,7 +272,7 @@
         return "PlatformAddress[" + osaddr + "]"; //$NON-NLS-1$ //$NON-NLS-2$
     }
     
-    public final long getSize(){
+    public final long getSize() {
         return size;
     }
 
diff --git a/luni/src/main/java/org/apache/harmony/luni/platform/PlatformAddressFactory.java b/luni/src/main/java/org/apache/harmony/luni/platform/PlatformAddressFactory.java
index 9ac8064..3590604 100644
--- a/luni/src/main/java/org/apache/harmony/luni/platform/PlatformAddressFactory.java
+++ b/luni/src/main/java/org/apache/harmony/luni/platform/PlatformAddressFactory.java
@@ -103,7 +103,12 @@
         return addr;
     }
     
-    public static PlatformAddress allocMap(int fd, long start, long size, int mode) throws IOException{
+    public static PlatformAddress allocMap(int fd, long start, long size, int mode) throws IOException {
+        if (size == 0) {
+            // if size is 0, call to mmap has incorrect behaviour on 
+            // unix and windows, so return empty address
+            return mapOn(0, 0);
+        }
         int osAddress = PlatformAddress.osMemory.mmap(fd, start, size, mode);
         PlatformAddress newMemory = mapOn(osAddress, size);
         PlatformAddress.memorySpy.alloc(newMemory);
diff --git a/luni/src/main/java/org/apache/harmony/luni/util/ExternalMessages.properties b/luni/src/main/java/org/apache/harmony/luni/util/ExternalMessages.properties
index 280a8f5..b6cbcef 100644
--- a/luni/src/main/java/org/apache/harmony/luni/util/ExternalMessages.properties
+++ b/luni/src/main/java/org/apache/harmony/luni/util/ExternalMessages.properties
@@ -38,7 +38,7 @@
 K0020=Unknown format
 K002b=Unknown pattern character - '{0}'
 K002c=Access denied {0}
-K002e=Offset out of bounds
+K002e=Offset out of bounds \: {0}
 K002f=Arguments out of bounds
 K0032=Address null or destination port out of range
 K0033=Unknown socket type
@@ -326,3 +326,6 @@
 KA028=Cannot set protocol version when stream in use
 KA029=Can't find resource for bundle {0}, key {1}
 KA030=Write end dead
+K0031=Length out of bounds \: {0}
+K0032=Source size {0} does not fit into destination
+K0033=Start index ({0}) is greater than end index ({1})
diff --git a/luni/src/main/native/cbigint.c b/luni/src/main/native/cbigint.c
index d327940..92b2992 100644
--- a/luni/src/main/native/cbigint.c
+++ b/luni/src/main/native/cbigint.c
@@ -253,6 +253,34 @@
     }
 }
 
+#ifndef HY_LITTLE_ENDIAN
+void simpleMultiplyAddHighPrecisionBigEndianFix(U_64 *arg1, IDATA length, U_64 arg2, U_32 *result) {
+	/* Assumes result can hold the product and arg2 only holds 32 bits
+	   of information */
+	U_64 product;
+	IDATA index, resultIndex;
+
+	index = resultIndex = 0;
+	product = 0;
+
+	do {
+		product = HIGH_IN_U64(product) + result[halfAt(resultIndex)] + arg2 * LOW_U32_FROM_PTR(arg1 + index);
+		result[halfAt(resultIndex)] = LOW_U32_FROM_VAR(product);
+		++resultIndex;
+		product = HIGH_IN_U64(product) + result[halfAt(resultIndex)] + arg2 * HIGH_U32_FROM_PTR(arg1 + index);
+		result[halfAt(resultIndex)] = LOW_U32_FROM_VAR(product);
+		++resultIndex;
+	} while (++index < length);
+
+	result[halfAt(resultIndex)] += HIGH_U32_FROM_VAR(product);
+	if (result[halfAt(resultIndex)] < HIGH_U32_FROM_VAR(product)) {
+		/* must be careful with ++ operator and macro expansion */
+		++resultIndex;
+		while (++result[halfAt(resultIndex)] == 0) ++resultIndex;
+	}
+}
+#endif
+
 void
 multiplyHighPrecision (U_64 * arg1, IDATA length1, U_64 * arg2, IDATA length2,
                        U_64 * result, IDATA length)
@@ -281,10 +309,11 @@
     {
       simpleMultiplyAddHighPrecision (arg1, length1, LOW_IN_U64 (arg2[count]),
                                       resultIn32 + (++index));
-      simpleMultiplyAddHighPrecision (arg1, length1,
-                                      HIGH_IN_U64 (arg2[count]),
-                                      resultIn32 + (++index));
-
+#ifdef HY_LITTLE_ENDIAN
+      simpleMultiplyAddHighPrecision(arg1, length1, HIGH_IN_U64(arg2[count]), resultIn32 + (++index));
+#else
+      simpleMultiplyAddHighPrecisionBigEndianFix(arg1, length1, HIGH_IN_U64(arg2[count]), resultIn32 + (++index));
+#endif
     }
 }
 
diff --git a/luni/src/main/native/fltconst.h b/luni/src/main/native/fltconst.h
index 03a97cd..940d5fc 100644
--- a/luni/src/main/native/fltconst.h
+++ b/luni/src/main/native/fltconst.h
@@ -140,16 +140,23 @@
 #define SET_PINF_SNGL_PTR(fltptr)  *U32P((fltptr)) = SINGLE_EXPONENT_MASK
 #define SET_NINF_SNGL_PTR(fltptr)  *U32P((fltptr)) = (SINGLE_EXPONENT_MASK | SINGLE_SIGN_MASK)
 
-/* on some platforms (HP720) we cannot reference an unaligned float.  Build them by hand, one U_32 at a time. */
-#if defined(ATOMIC_FLOAT_ACCESS)
-#define PTR_DOUBLE_STORE(dstPtr, aDoublePtr) HIGH_U32_FROM_DBL_PTR(dstPtr) = HIGH_U32_FROM_DBL_PTR(aDoublePtr); LOW_U32_FROM_DBL_PTR(dstPtr) = LOW_U32_FROM_DBL_PTR(aDoublePtr)
-#define PTR_DOUBLE_VALUE(dstPtr, aDoublePtr) HIGH_U32_FROM_DBL_PTR(aDoublePtr) = HIGH_U32_FROM_DBL_PTR(dstPtr); LOW_U32_FROM_DBL_PTR(aDoublePtr) = LOW_U32_FROM_DBL_PTR(dstPtr)
+#if defined(HY_WORD64)
+ #define PTR_DOUBLE_VALUE(dstPtr, aDoublePtr) ((U64U32DBL *)(aDoublePtr))->u64val = ((U64U32DBL *)(dstPtr))->u64val
+ #define PTR_DOUBLE_STORE(dstPtr, aDoublePtr) ((U64U32DBL *)(dstPtr))->u64val = ((U64U32DBL *)(aDoublePtr))->u64val
+ #define STORE_LONG(dstPtr, hi, lo) ((U64U32DBL *)(dstPtr))->u64val = (((U_64)(hi)) << 32) | (lo)
 #else
-#define PTR_DOUBLE_STORE(dstPtr, aDoublePtr) (*(dstPtr) = *(aDoublePtr))
-#define PTR_DOUBLE_VALUE(dstPtr, aDoublePtr) (*(aDoublePtr) = *(dstPtr))
-#endif
+ /* on some platforms (HP720) we cannot reference an unaligned float.  Build them by hand, one U_32 at a time. */
+ #if defined(ATOMIC_FLOAT_ACCESS)
+ #define PTR_DOUBLE_STORE(dstPtr, aDoublePtr) HIGH_U32_FROM_DBL_PTR(dstPtr) = HIGH_U32_FROM_DBL_PTR(aDoublePtr); LOW_U32_FROM_DBL_PTR(dstPtr) = LOW_U32_FROM_DBL_PTR(aDoublePtr)
+ #define PTR_DOUBLE_VALUE(dstPtr, aDoublePtr) HIGH_U32_FROM_DBL_PTR(aDoublePtr) = HIGH_U32_FROM_DBL_PTR(dstPtr); LOW_U32_FROM_DBL_PTR(aDoublePtr) = LOW_U32_FROM_DBL_PTR(dstPtr)
+ #else
+ #define PTR_DOUBLE_STORE(dstPtr, aDoublePtr) (*(dstPtr) = *(aDoublePtr))
+ #define PTR_DOUBLE_VALUE(dstPtr, aDoublePtr) (*(aDoublePtr) = *(dstPtr))
+ #endif
 
-#define STORE_LONG(dstPtr, hi, lo) HIGH_U32_FROM_LONG64_PTR(dstPtr) = (hi); LOW_U32_FROM_LONG64_PTR(dstPtr) = (lo)
+ #define STORE_LONG(dstPtr, hi, lo) HIGH_U32_FROM_LONG64_PTR(dstPtr) = (hi); LOW_U32_FROM_LONG64_PTR(dstPtr) = (lo)
+#endif /* HY_WORD64 */
+
 #define PTR_SINGLE_VALUE(dstPtr, aSinglePtr) (*U32P(aSinglePtr) = *U32P(dstPtr))
 #define PTR_SINGLE_STORE(dstPtr, aSinglePtr) *((U_32 *)(dstPtr)) = (*U32P(aSinglePtr))
 
diff --git a/luni/src/main/native/org_apache_harmony_luni_util_fltparse.c b/luni/src/main/native/org_apache_harmony_luni_util_fltparse.c
index e92b776..ebbd6de 100644
--- a/luni/src/main/native/org_apache_harmony_luni_util_fltparse.c
+++ b/luni/src/main/native/org_apache_harmony_luni_util_fltparse.c
@@ -240,7 +240,7 @@
     }
   else if (e >= 0 && e < 39)
     {
-      result = (jfloat) (toDoubleHighPrecision (f, length) * pow (10.0, e));
+      result = (jfloat) (toDoubleHighPrecision (f, length) * pow (10.0, (double) e));
     }
   else if (e >= 39)
     {
@@ -260,7 +260,7 @@
       int dexp;
       U_32 fmant, fovfl;
       U_64 dmant;
-      dresult = toDoubleHighPrecision (f, length) / pow (10.0, -e);
+      dresult = toDoubleHighPrecision (f, length) / pow (10.0, (double) -e);
       if (IS_DENORMAL_DBL (dresult))
         {
           FLOAT_TO_INTBITS (result) = 0;
diff --git a/luni/src/test/java/tests/api/java/util/CollectionsTest.java b/luni/src/test/java/tests/api/java/util/CollectionsTest.java
index 2b1b47e..7fc60d8 100644
--- a/luni/src/test/java/tests/api/java/util/CollectionsTest.java
+++ b/luni/src/test/java/tests/api/java/util/CollectionsTest.java
@@ -41,6 +41,7 @@
 import java.util.SortedSet;
 import java.util.TreeMap;
 import java.util.TreeSet;
+import java.util.Arrays;
 
 import org.apache.harmony.luni.internal.nls.Messages;
 
@@ -807,18 +808,19 @@
         LinkedList ll2 = new LinkedList();
         ll2.addAll(ll);
         testShuffle(ll2, "Random Access", false);
+    }
 
-        Mock_ArrayList mal = new Mock_ArrayList();
-        
-        mal.add("First");
-        mal.add("Second");
-        
-        try {
-            Collections.shuffle(mal);
-            fail("UnsupportedOperationException expected");
-        } catch (UnsupportedOperationException e) {
-            //expected
-        }
+    public void testShuffleRandomAccessWithSeededRandom() {
+        List<String> list = Arrays.asList("A", "B", "C", "D", "E", "F", "G");
+        Collections.shuffle(list, new Random(0));
+        assertEquals(Arrays.asList("B", "A", "D", "C", "G", "E", "F"), list);
+    }
+
+    public void testShuffleWithSeededRandom() {
+        List<String> list = new LinkedList<String>(Arrays.asList(
+                "A", "B", "C", "D", "E", "F", "G"));
+        Collections.shuffle(list, new Random(0));
+        assertEquals(Arrays.asList("B", "A", "D", "C", "G", "E", "F"), list);
     }
 
     private void testShuffle(List list, String type, boolean random) {
@@ -837,15 +839,15 @@
                 sorted = false;
             }
         }
-        assertTrue("Shuffling sorted " + type
-                + " list resulted in sorted list (should be unlikely)", !sorted);
+        assertFalse("Shuffling sorted " + type
+                + " list resulted in sorted list (should be unlikely)", sorted);
         for (int counter = 0; counter < 20; counter++) {
             index = 30031 * counter % (size + 1); // 30031 is a large prime
             if (list.get(index) != ll.get(index))
                 allMatch = false;
         }
-        assertTrue("Too many element positions match in shuffled " + type
-                + " list", !allMatch);
+        assertFalse("Too many element positions match in shuffled " + type
+                + " list", allMatch);
     }
 
     /**