Fix for HARMONY-6675: Reducing timeout value in CanonicalPatchCache to fix a file not found error in Hadoop common

1. make timeout of CanonicalPatchCache configurable via property
   'org.apache.harmony.file.canonical.path.cache.timeout'.
2. reduce default timeout value to 30 seconds.

git-svn-id: https://svn.apache.org/repos/asf/harmony/enhanced/java/trunk@1035930 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 da86d93..d165f90 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
@@ -55,9 +55,29 @@
     private static Object lock = new Object();
 
     /**
-     * Expired time.
+     * Expired time, 0 disable this cache.
      */
-    private static long timeout = 600000;
+    private static long timeout = 30000;
+
+    /**
+     * Whether to enable this cache.
+     */
+    private static boolean isEnable = true;
+
+    public static final String FILE_CANONICAL_PATH_CACHE_TIMEOUT = "org.apache.harmony.file.canonical.path.cache.timeout";
+
+    static {
+        String value = System.getProperty(FILE_CANONICAL_PATH_CACHE_TIMEOUT);
+        try {
+            timeout = Long.parseLong(value);
+        } catch (NumberFormatException e) {
+            // use default timeout value
+        }
+
+        if (timeout <= 0) {
+            isEnable = false;
+        }
+    }
 
     /**
      * Retrieve element from cache.
@@ -68,6 +88,10 @@
      * 
      */
     public static String get(String path) {
+        if (!isEnable) {
+            return null;
+        }
+
         CacheElement element = null;
         synchronized (lock) {
             element = cache.get(path);
@@ -104,6 +128,10 @@
      *            the canonical path of <code>path</code>.
      */
     public static void put(String path, String canonicalPath) {
+        if (!isEnable) {
+            return;
+        }
+
         CacheElement element = new CacheElement(canonicalPath);
         synchronized (lock) {
             if (cache.size() >= CACHE_SIZE) {
@@ -120,6 +148,10 @@
      * Remove all elements from cache.
      */
     public static void clear() {
+        if (!isEnable) {
+            return;
+        }
+
         synchronized (lock) {
             cache.clear();
             list.clear();
@@ -132,5 +164,9 @@
 
     public static void setTimeout(long timeout) {
         FileCanonPathCache.timeout = timeout;
+        if (timeout <= 0) {
+            clear();
+            isEnable = false;
+        }
     }
 }