Improve patch for HARMONY-6675 at r1035930: remove field 'isEnable' and mark more fileds as 'final'.

git-svn-id: https://svn.apache.org/repos/asf/harmony/enhanced/java/trunk@1038506 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/classlib/modules/luni/src/main/java/org/apache/harmony/luni/internal/io/FileCanonPathCache.java b/classlib/modules/luni/src/main/java/org/apache/harmony/luni/internal/io/FileCanonPathCache.java
index d165f90..ba12b1a 100644
--- a/classlib/modules/luni/src/main/java/org/apache/harmony/luni/internal/io/FileCanonPathCache.java
+++ b/classlib/modules/luni/src/main/java/org/apache/harmony/luni/internal/io/FileCanonPathCache.java
@@ -29,9 +29,9 @@
 public class FileCanonPathCache {
 
     static private class CacheElement {
-        String canonicalPath;
+        final String canonicalPath;
 
-        long timestamp;
+        final long timestamp;
 
         public CacheElement(String path) {
             this.canonicalPath = path;
@@ -44,25 +44,20 @@
      */
     public static final int CACHE_SIZE = 256;
 
-    private static HashMap<String, CacheElement> cache = new HashMap<String, CacheElement>(
+    private static final 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 final LinkedList<String> list = new LinkedList<String>();
 
-    private static Object lock = new Object();
+    private static final Object lock = new Object();
 
     /**
      * Expired time, 0 disable this cache.
      */
-    private static long timeout = 30000;
-
-    /**
-     * Whether to enable this cache.
-     */
-    private static boolean isEnable = true;
+    private static volatile long timeout = 30000;
 
     public static final String FILE_CANONICAL_PATH_CACHE_TIMEOUT = "org.apache.harmony.file.canonical.path.cache.timeout";
 
@@ -74,8 +69,8 @@
             // use default timeout value
         }
 
-        if (timeout <= 0) {
-            isEnable = false;
+        if (timeout < 0) {
+            timeout = 0;
         }
     }
 
@@ -88,7 +83,8 @@
      * 
      */
     public static String get(String path) {
-        if (!isEnable) {
+        long localTimeout = timeout;
+        if (localTimeout == 0) {
             return null;
         }
 
@@ -102,7 +98,7 @@
         }
 
         long time = System.currentTimeMillis();
-        if (time - element.timestamp > timeout) {
+        if (time - element.timestamp > localTimeout) {
             // remove all elements older than this one
             synchronized (lock) {
                 if (cache.get(path) != null) {
@@ -128,7 +124,7 @@
      *            the canonical path of <code>path</code>.
      */
     public static void put(String path, String canonicalPath) {
-        if (!isEnable) {
+        if (timeout == 0) {
             return;
         }
 
@@ -148,7 +144,7 @@
      * Remove all elements from cache.
      */
     public static void clear() {
-        if (!isEnable) {
+        if (timeout == 0) {
             return;
         }
 
@@ -163,10 +159,12 @@
     }
 
     public static void setTimeout(long timeout) {
-        FileCanonPathCache.timeout = timeout;
-        if (timeout <= 0) {
-            clear();
-            isEnable = false;
+        synchronized (lock) {
+            if (timeout <= 0) {
+                timeout = 0;
+                clear();
+            }
+            FileCanonPathCache.timeout = timeout;
         }
     }
 }