Removing caching of file canonical path caching, and fixing NIO tests.

I checked in some regressions in the NIO test cases with the NIO patch;
this addresses those problems.
diff --git a/libcore/luni/src/main/java/java/io/File.java b/libcore/luni/src/main/java/java/io/File.java
index cde9fcc..521623d 100644
--- a/libcore/luni/src/main/java/java/io/File.java
+++ b/libcore/luni/src/main/java/java/io/File.java
@@ -25,7 +25,6 @@
 import java.util.ArrayList;
 import java.util.List;
 
-import org.apache.harmony.luni.internal.io.FileCanonPathCache;
 import org.apache.harmony.luni.util.DeleteOnExit;
 import org.apache.harmony.luni.util.Msg;
 import org.apache.harmony.luni.util.PriviAction;
@@ -497,11 +496,15 @@
     public String getCanonicalPath() throws IOException {
         byte[] result = properPath(false);
         String absPath = Util.toUTF8String(result);
-        String canonPath = FileCanonPathCache.get(absPath);
 
-        if (canonPath != null) {
-            return canonPath;
-        }
+        // BEGIN android-removed
+        //     caching the canonical path is completely bogus
+        // String canonPath = FileCanonPathCache.get(absPath);
+        // if (canonPath != null) {
+        //     return canonPath;
+        // }
+        // END android-removed
+
         if(separatorChar == '/') {
             // resolve the full path first
             result = resolveLink(result, result.length, false);
@@ -573,9 +576,13 @@
         newResult[newLength] = 0;
         newResult = getCanonImpl(newResult);
         newLength = newResult.length;
-        canonPath = Util.toUTF8String(newResult, 0, newLength);
-        FileCanonPathCache.put(absPath, canonPath);
-        return canonPath;
+
+        // BEGIN android-changed
+        //     caching the canonical path is completely bogus
+        return Util.toUTF8String(newResult, 0, newLength);
+        // FileCanonPathCache.put(absPath, canonPath);
+        // return canonPath;
+        // END android-changed
     }
 
     /*
diff --git a/libcore/luni/src/main/java/org/apache/harmony/luni/internal/io/FileCanonPathCache.java b/libcore/luni/src/main/java/org/apache/harmony/luni/internal/io/FileCanonPathCache.java
deleted file mode 100644
index c1ffef9..0000000
--- a/libcore/luni/src/main/java/org/apache/harmony/luni/internal/io/FileCanonPathCache.java
+++ /dev/null
@@ -1,136 +0,0 @@
-/*
- *  Licensed to the Apache Software Foundation (ASF) under one or more
- *  contributor license agreements.  See the NOTICE file distributed with
- *  this work for additional information regarding copyright ownership.
- *  The ASF licenses this file to You under the Apache License, Version 2.0
- *  (the "License"); you may not use this file except in compliance with
- *  the License.  You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- *  Unless required by applicable law or agreed to in writing, software
- *  distributed under the License is distributed on an "AS IS" BASIS,
- *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- *  See the License for the specific language governing permissions and
- *  limitations under the License.
- */
-
-package org.apache.harmony.luni.internal.io;
-
-import java.util.HashMap;
-import java.util.LinkedList;
-
-/**
- * A simple cache implementation for file's canonical path. The cache has fixed
- * size <code> CACHE_SIZE </code> and cached elements would be expired. If
- * <code>put<code> method is invoked when cache is full, the oldest element will be removed.
- *
- */
-public class FileCanonPathCache {
-
-    static private class CacheElement {
-        String canonicalPath;
-
-        long timestamp;
-
-        public CacheElement(String path) {
-            this.canonicalPath = path;
-            this.timestamp = System.currentTimeMillis();
-        }
-    }
-
-    /**
-     * Max elements could be hold in the cache.
-     */
-    public static final int CACHE_SIZE = 256;
-
-    private static HashMap<String, CacheElement> cache = new HashMap<String, CacheElement>(
-            CACHE_SIZE);
-
-    /**
-     * FIFO queue for tracking age of elements.
-     */
-    private static LinkedList<String> list = new LinkedList<String>();
-
-    private static Object lock = new Object();
-
-    /**
-     * Expired time.
-     */
-    private static long timeout = 600000;
-
-    /**
-     * Retrieve element from cache.
-     * 
-     * @param path
-     *            absolute path.
-     * @return canonical path of <code>path</code> if it's in cache.
-     * 
-     */
-    public static String get(String path) {
-        CacheElement element = null;
-        synchronized (lock) {
-            element = cache.get(path);
-        }
-
-        if (element == null) {
-            return null;
-        }
-
-        long time = System.currentTimeMillis();
-        if (time - element.timestamp > timeout) {
-            // remove all elements older than this one
-            synchronized (lock) {
-                if (cache.get(path) != null) {
-                    String oldest = null;
-                    do {
-                        oldest = list.removeFirst();
-                        cache.remove(path);
-                    } while (!path.equals(oldest));
-                }
-            }
-            return null;
-        }
-
-        return element.canonicalPath;
-    }
-
-    /**
-     * Put element to cache.
-     * 
-     * @param path
-     *            absolute path.
-     * @param canonicalPath
-     *            the canonical path of <code>path</code>.
-     */
-    public static void put(String path, String canonicalPath) {
-        CacheElement element = new CacheElement(canonicalPath);
-        synchronized (lock) {
-            if (cache.size() >= CACHE_SIZE) {
-                // cache is full
-                String oldest = list.removeFirst();
-                cache.remove(oldest);
-            }
-            cache.put(path, element);
-            list.addLast(path);
-        }
-    }
-
-    /**
-     * Remove all elements from cache.
-     */
-    public static void clear() {
-        synchronized (lock) {
-            cache.clear();
-            list.clear();
-        }
-    }
-
-    public static long getTimeout() {
-        return timeout;
-    }
-
-    public static void setTimeout(long timeout) {
-        FileCanonPathCache.timeout = timeout;
-    }
-}
diff --git a/libcore/luni/src/test/java/org/apache/harmony/luni/tests/java/io/AllTests.java b/libcore/luni/src/test/java/org/apache/harmony/luni/tests/java/io/AllTests.java
index 056b521..778e527 100644
--- a/libcore/luni/src/test/java/org/apache/harmony/luni/tests/java/io/AllTests.java
+++ b/libcore/luni/src/test/java/org/apache/harmony/luni/tests/java/io/AllTests.java
@@ -34,7 +34,6 @@
         TestSuite suite = tests.TestSuiteFactory.createTestSuite("Tests for java.io");
 
         suite.addTestSuite(BufferedReaderTest.class);
-        suite.addTestSuite(FileCanonPathCacheTest.class);
         suite.addTestSuite(FilePermissionTest.class);
         suite.addTestSuite(FileTest.class);
         suite.addTestSuite(InputStreamReaderTest.class);
diff --git a/libcore/luni/src/test/java/org/apache/harmony/luni/tests/java/io/FileCanonPathCacheTest.java b/libcore/luni/src/test/java/org/apache/harmony/luni/tests/java/io/FileCanonPathCacheTest.java
deleted file mode 100644
index f2ac7f3..0000000
--- a/libcore/luni/src/test/java/org/apache/harmony/luni/tests/java/io/FileCanonPathCacheTest.java
+++ /dev/null
@@ -1,120 +0,0 @@
-/*
- *  Licensed to the Apache Software Foundation (ASF) under one or more
- *  contributor license agreements.  See the NOTICE file distributed with
- *  this work for additional information regarding copyright ownership.
- *  The ASF licenses this file to You under the Apache License, Version 2.0
- *  (the "License"); you may not use this file except in compliance with
- *  the License.  You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- *  Unless required by applicable law or agreed to in writing, software
- *  distributed under the License is distributed on an "AS IS" BASIS,
- *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- *  See the License for the specific language governing permissions and
- *  limitations under the License.
- */
-
-package org.apache.harmony.luni.tests.java.io;
-
-import java.io.File;
-
-import org.apache.harmony.luni.internal.io.FileCanonPathCache;
-
-import junit.framework.TestCase;
-
-public class FileCanonPathCacheTest extends TestCase {
-
-    private static int DEFAULT_TIMEOUT = 600000;
-
-    @Override
-    public void setUp() throws Exception {
-        FileCanonPathCache.clear();
-        FileCanonPathCache.setTimeout(DEFAULT_TIMEOUT);
-    }
-
-    public void testGetSet() throws Exception {
-        File file1 = new File("test/hello~1");
-        assertNull(FileCanonPathCache.get(file1.getAbsolutePath()));
-        FileCanonPathCache.put(file1.getAbsolutePath(), file1
-                .getCanonicalPath());
-        assertEquals(file1.getCanonicalPath(), FileCanonPathCache.get(file1
-                .getAbsolutePath()));
-
-        File file2 = new File("test/world~1");
-        assertNull(FileCanonPathCache.get(file2.getAbsolutePath()));
-        FileCanonPathCache.put(file2.getAbsolutePath(), file2
-                .getCanonicalPath());
-        assertEquals(file2.getCanonicalPath(), FileCanonPathCache.get(file2
-                .getAbsolutePath()));
-
-        assertNull(FileCanonPathCache.get("notexist"));
-    }
-
-    public void testGetTimeout01() throws Exception {
-        FileCanonPathCache.setTimeout(10);
-
-        File file1 = new File("test/hello~1");
-        assertNull(FileCanonPathCache.get(file1.getAbsolutePath()));
-        FileCanonPathCache.put(file1.getAbsolutePath(), file1
-                .getCanonicalPath());
-        Thread.sleep(50);
-        assertNull(FileCanonPathCache.get(file1.getAbsolutePath()));
-    }
-
-    public void testGetTimeout02() throws Exception {
-        FileCanonPathCache.setTimeout(10);
-
-        File file1 = new File("test/hello~1");
-        assertNull(FileCanonPathCache.get(file1.getAbsolutePath()));
-        FileCanonPathCache.put(file1.getAbsolutePath(), file1
-                .getCanonicalPath());
-        File file2 = new File("test/hello~2");
-        assertNull(FileCanonPathCache.get(file2.getAbsolutePath()));
-        FileCanonPathCache.put(file2.getAbsolutePath(), file2
-                .getCanonicalPath());
-        File file3 = new File("test/hello~3");
-        assertNull(FileCanonPathCache.get(file3.getAbsolutePath()));
-        FileCanonPathCache.put(file3.getAbsolutePath(), file3
-                .getCanonicalPath());
-        File file4 = new File("test/hello~4");
-        assertNull(FileCanonPathCache.get(file4.getAbsolutePath()));
-        FileCanonPathCache.put(file4.getAbsolutePath(), file4
-                .getCanonicalPath());
-        File file5 = new File("test/hello~5");
-        assertNull(FileCanonPathCache.get(file5.getAbsolutePath()));
-        FileCanonPathCache.put(file5.getAbsolutePath(), file5
-                .getCanonicalPath());
-
-        Thread.sleep(50);
-
-        assertNull(FileCanonPathCache.get(file1.getAbsolutePath()));
-        assertNull(FileCanonPathCache.get(file2.getAbsolutePath()));
-        assertNull(FileCanonPathCache.get(file3.getAbsolutePath()));
-        assertNull(FileCanonPathCache.get(file4.getAbsolutePath()));
-        assertNull(FileCanonPathCache.get(file5.getAbsolutePath()));
-    }
-
-    public void testCacheFull() throws Exception {
-        int cacheSize = FileCanonPathCache.CACHE_SIZE;
-        File[] files = new File[cacheSize];
-        for (int i = 0; i < cacheSize; ++i) {
-            files[i] = new File("test/world" + i);
-            FileCanonPathCache.put(files[i].getAbsolutePath(), files[i]
-                    .getCanonicalPath());
-        }
-
-        for (int i = cacheSize; i < files.length; ++i) {
-            assertEquals(files[i - cacheSize].getCanonicalPath(),
-                    FileCanonPathCache.get(files[i - cacheSize]
-                            .getAbsolutePath()));
-            files[i] = new File("test/world" + i);
-            FileCanonPathCache.put(files[i].getAbsolutePath(), files[i]
-                    .getCanonicalPath());
-            assertEquals(files[i].getCanonicalPath(), FileCanonPathCache
-                    .get(files[i].getAbsolutePath()));
-            assertNull(FileCanonPathCache.get(files[i - cacheSize]
-                    .getAbsolutePath()));
-        }
-    }
-}
diff --git a/libcore/nio_char/src/test/java/org/apache/harmony/nio_char/tests/java/nio/charset/CharsetTest.java b/libcore/nio_char/src/test/java/org/apache/harmony/nio_char/tests/java/nio/charset/CharsetTest.java
index f8b0b7e..6c36ec2 100644
--- a/libcore/nio_char/src/test/java/org/apache/harmony/nio_char/tests/java/nio/charset/CharsetTest.java
+++ b/libcore/nio_char/src/test/java/org/apache/harmony/nio_char/tests/java/nio/charset/CharsetTest.java
@@ -16,24 +16,17 @@
 
 package org.apache.harmony.nio_char.tests.java.nio.charset;
 
-import dalvik.annotation.TestTargetClass;
-import dalvik.annotation.TestTargets;
-import dalvik.annotation.TestTargetNew;
 import dalvik.annotation.TestLevel;
+import dalvik.annotation.TestTargetClass;
+import dalvik.annotation.TestTargetNew;
+import junit.framework.TestCase;
 
-import java.nio.ByteBuffer;
-import java.nio.CharBuffer;
 import java.nio.charset.Charset;
-import java.nio.charset.CharsetDecoder;
-import java.nio.charset.CharsetEncoder;
-import java.nio.charset.CoderResult;
 import java.nio.charset.IllegalCharsetNameException;
 import java.util.HashSet;
 import java.util.Iterator;
 import java.util.Properties;
 import java.util.Set;
-
-import junit.framework.TestCase;
 @TestTargetClass(Charset.class)
 public class CharsetTest extends TestCase {
 
@@ -181,153 +174,4 @@
         Charset cs4 = Charset.forName("US-ASCII");
         assertSame(cs3, cs4);
     }
-    
-    /*
-     * test cached decoder
-     */
-    @TestTargetNew(
-        level = TestLevel.COMPLETE,
-        notes = "This test is quite useless for the rest it does, though.",
-        method = "Charset",
-        args = {java.lang.String.class, java.lang.String[].class}
-    )
-    public void test_DecodeLjava_nio_ByteBuffer() throws Exception{
-            MockCharsetForDecoder cs1 = new MockCharsetForDecoder("CachedCharset",null);
-            MockCharsetForDecoder cs2 = new MockCharsetForDecoder("CachedCharset",null);
-            ByteBuffer in = ByteBuffer.wrap(new byte[]{0x00});
-            cs1.decode(in);
-            in.flip();
-            cs2.decode(in);
-            in.flip();
-    }
-    /*
-     * Mock Charset for cached decoder test
-     */
-    static class MockCharsetForDecoder extends Charset{
-
-            public MockCharsetForDecoder(String canonicalName, String[] aliases){
-                    super(canonicalName, aliases);
-            }
-
-            public boolean contains(Charset charset) {
-                    return false;
-            }
-
-            public CharsetEncoder newEncoder() {
-                    return null;
-            }
-
-            public CharsetDecoder newDecoder() {
-                    return new MockCachedDecoder(this);
-            }
-
-
-    }
-    /*
-     * Mock decoder. Only one caller is permitted.
-     */
-    static class MockCachedDecoder extends CharsetDecoder {
-            static MockCachedDecoder caller = null;
-
-            public MockCachedDecoder(Charset cs) {
-                    super(cs, 1, 10);
-            }
-
-            /*
-             * Only one caller is permitted.
-             * If there's another caller, throw RuntimeException.
-             */
-            protected CoderResult decodeLoop(ByteBuffer in, CharBuffer out) {
-                    if(null == caller){
-                            caller = this;
-                    }else{
-                            if(caller != this){
-                                // Another instance
-                                fail("should use the same instance");
-                            }
-                    }
-                    return CoderResult.UNDERFLOW;
-            }
-    }
-
-    /*
-     * test cached encoder
-     */
-    @TestTargetNew(
-        level = TestLevel.PARTIAL,
-        notes = "Functional test.",
-        method = "encode",
-        args = {java.nio.CharBuffer.class}
-    )
-    public void test_EncodeLjava_nio_CharBuffer() throws Exception {
-            MockCharsetForEncoder cs1 = new MockCharsetForEncoder("CachedCharset", null);
-            MockCharsetForEncoder cs2 = new MockCharsetForEncoder("CachedCharset", null);
-            CharBuffer in = CharBuffer.wrap("A");
-            cs1.encode(in);
-            in.flip();
-            cs2.encode(in);
-    }
-
-    /*
-     * Mock Charset for cached encoder test
-     */
-    static class MockCharsetForEncoder extends Charset {
-
-            public MockCharsetForEncoder(String canonicalName, String[] aliases) {
-                    super(canonicalName, aliases);
-            }
-
-            public boolean contains(Charset charset) {
-                    return false;
-            }
-
-            public CharsetDecoder newDecoder() {
-                    return new MockDecoderForEncoder(this);
-            }
-
-            public CharsetEncoder newEncoder() {
-                    return new MockCachedEncoder(this);
-            }
-    }
-
-    /*
-     * Mock encoder. Only one caller is permitted.
-     */
-    static class MockCachedEncoder extends CharsetEncoder {
-            static MockCachedEncoder caller = null;
-
-            public MockCachedEncoder(Charset cs) {
-                    super(cs, 1, 10);
-            }
-
-            /*
-             * Only one caller is permitted.
-             */
-            protected CoderResult encodeLoop(CharBuffer in, ByteBuffer out) {
-                    if (null == caller) {
-                            caller = this;
-                    } else {
-                            if (caller != this) {
-                                    // Another instance
-                                    fail("should use the same instance");
-                            }
-                    }
-                    return CoderResult.UNDERFLOW;
-            }
-    }
-
-    /*
-     * Mock decoder for MockCachedEncoder.
-     */
-    static class MockDecoderForEncoder extends CharsetDecoder {
-            public MockDecoderForEncoder(Charset cs) {
-                    super(cs, 1, 10);
-            }
-
-            protected CoderResult decodeLoop(ByteBuffer in, CharBuffer out) {
-                    in.position(in.limit());
-                    return CoderResult.UNDERFLOW;
-            }
-    }
-
 }
diff --git a/libcore/nio_char/src/test/java/tests/api/java/nio/charset/CharsetDecoderTest.java b/libcore/nio_char/src/test/java/tests/api/java/nio/charset/CharsetDecoderTest.java
index 33bafd4..315d667 100644
--- a/libcore/nio_char/src/test/java/tests/api/java/nio/charset/CharsetDecoderTest.java
+++ b/libcore/nio_char/src/test/java/tests/api/java/nio/charset/CharsetDecoderTest.java
@@ -55,11 +55,12 @@
 
 
     protected void setUp() throws Exception {
-        super.setUp();
-
         cs = new CharsetEncoderTest.MockCharset("mock", new String[0]);
         unibytes = new byte[] { 32, 98, 117, 102, 102, 101, 114 };
         decoder = cs.newDecoder();
+
+        // for this test's weird superclass, super.setUp() needs to be run last
+        super.setUp();
     }