Fix https://issues.apache.org/bugzilla/show_bug.cgi?id=49600
authormarkt <markt@13f79535-47bb-0310-9956-ffa450edef68>
Wed, 21 Jul 2010 20:30:53 +0000 (20:30 +0000)
committermarkt <markt@13f79535-47bb-0310-9956-ffa450edef68>
Wed, 21 Jul 2010 20:30:53 +0000 (20:30 +0000)
Return a consistent exception for 'Not Found' resources.

git-svn-id: https://svn.apache.org/repos/asf/tomcat/trunk@966404 13f79535-47bb-0310-9956-ffa450edef68

java/org/apache/naming/resources/BaseDirContext.java
java/org/apache/naming/resources/FileDirContext.java
java/org/apache/naming/resources/ProxyDirContext.java
java/org/apache/naming/resources/WARDirContext.java
webapps/docs/changelog.xml

index e8fe554..cb7901b 100644 (file)
@@ -36,6 +36,7 @@ import javax.naming.Binding;
 import javax.naming.Context;
 import javax.naming.Name;
 import javax.naming.NameClassPair;
+import javax.naming.NameNotFoundException;
 import javax.naming.NameParser;
 import javax.naming.NamingEnumeration;
 import javax.naming.NamingException;
@@ -475,7 +476,8 @@ public abstract class BaseDirContext implements DirContext {
         }
         
         // Really not found
-        throw new NamingException(sm.getString("resources.notFound", name));
+        throw new NameNotFoundException(
+                sm.getString("resources.notFound", name));
     }
 
     /**
@@ -702,7 +704,8 @@ public abstract class BaseDirContext implements DirContext {
         }
 
         // Really not found
-        throw new NamingException(sm.getString("resources.notFound", name));
+        throw new NameNotFoundException(
+                sm.getString("resources.notFound", name));
     }
 
 
@@ -1058,7 +1061,8 @@ public abstract class BaseDirContext implements DirContext {
         }
         
         // Really not found
-        throw new NamingException(sm.getString("resources.notFound", name));
+        throw new NameNotFoundException(
+                sm.getString("resources.notFound", name));
     }
 
     /**
index 22cdfc8..d5e09e4 100644 (file)
@@ -31,6 +31,7 @@ import java.util.Hashtable;
 import javax.naming.Binding;
 import javax.naming.NameAlreadyBoundException;
 import javax.naming.NameClassPair;
+import javax.naming.NameNotFoundException;
 import javax.naming.NamingEnumeration;
 import javax.naming.NamingException;
 import javax.naming.OperationNotSupportedException;
@@ -237,8 +238,8 @@ public class FileDirContext extends BaseDirContext {
         File file = file(name);
 
         if (file == null)
-            throw new NamingException
-                (sm.getString("resources.notFound", name));
+            throw new NameNotFoundException(
+                    sm.getString("resources.notFound", name));
 
         if (!file.delete())
             throw new NamingException
@@ -265,7 +266,7 @@ public class FileDirContext extends BaseDirContext {
         File file = file(oldName);
 
         if (file == null)
-            throw new NamingException
+            throw new NameNotFoundException
                 (sm.getString("resources.notFound", oldName));
 
         File newFile = new File(base, newName);
@@ -295,7 +296,7 @@ public class FileDirContext extends BaseDirContext {
         File file = file(name);
 
         if (file == null)
-            throw new NamingException
+            throw new NameNotFoundException
                 (sm.getString("resources.notFound", name));
 
         return new NamingContextEnumeration(list(file).iterator());
index 88bf40d..3c9339f 100644 (file)
@@ -56,6 +56,13 @@ public class ProxyDirContext implements DirContext {
     public static final String HOST = "host";
 
 
+    /**
+     * Immutable name not found exception.
+     */
+    protected static final NameNotFoundException NOT_FOUND_EXCEPTION =
+        new ImmutableNameNotFoundException();
+
+
     // ----------------------------------------------------------- Constructors
 
 
@@ -134,7 +141,8 @@ public class ProxyDirContext implements DirContext {
     /**
      * The string manager for this package.
      */
-    protected static final StringManager sm = StringManager.getManager(Constants.Package);
+    protected static final StringManager sm =
+        StringManager.getManager(Constants.Package);
 
 
     /**
@@ -187,13 +195,6 @@ public class ProxyDirContext implements DirContext {
 
 
     /**
-     * Immutable name not found exception.
-     */
-    protected NameNotFoundException notFoundException =
-        new ImmutableNameNotFoundException();
-
-
-    /**
      * Non cacheable resources.
      */
     protected String[] nonCacheable = { "/WEB-INF/lib/", "/WEB-INF/classes/" };
@@ -263,7 +264,7 @@ public class ProxyDirContext implements DirContext {
         CacheEntry entry = cacheLookup(name.toString());
         if (entry != null) {
             if (!entry.exists) {
-                throw notFoundException;
+                throw NOT_FOUND_EXCEPTION;
             }
             if (entry.resource != null) {
                 // Check content caching.
@@ -292,7 +293,7 @@ public class ProxyDirContext implements DirContext {
         CacheEntry entry = cacheLookup(name);
         if (entry != null) {
             if (!entry.exists) {
-                throw notFoundException;
+                throw NOT_FOUND_EXCEPTION;
             }
             if (entry.resource != null) {
                 return entry.resource;
@@ -813,7 +814,7 @@ public class ProxyDirContext implements DirContext {
         CacheEntry entry = cacheLookup(name.toString());
         if (entry != null) {
             if (!entry.exists) {
-                throw notFoundException;
+                throw NOT_FOUND_EXCEPTION;
             }
             return entry.attributes;
         }
@@ -837,7 +838,7 @@ public class ProxyDirContext implements DirContext {
         CacheEntry entry = cacheLookup(name);
         if (entry != null) {
             if (!entry.exists) {
-                throw notFoundException;
+                throw NOT_FOUND_EXCEPTION;
             }
             return entry.attributes;
         }
index e5b3d76..850fa1c 100644 (file)
@@ -35,6 +35,7 @@ import javax.naming.CompositeName;
 import javax.naming.InvalidNameException;
 import javax.naming.Name;
 import javax.naming.NameClassPair;
+import javax.naming.NameNotFoundException;
 import javax.naming.NamingEnumeration;
 import javax.naming.NamingException;
 import javax.naming.OperationNotSupportedException;
@@ -296,7 +297,7 @@ public class WARDirContext extends BaseDirContext {
             return new NamingContextEnumeration(list(entries).iterator());
         Entry entry = treeLookup(name);
         if (entry == null)
-            throw new NamingException
+            throw new NameNotFoundException
                 (sm.getString("resources.notFound", name));
         return new NamingContextEnumeration(list(entry).iterator());
     }
index fdbaefe..b98753a 100644 (file)
         default timeout configurable using the <code>asyncTimeout</code>
         attribute on the connector. (pero/markt)
       </fix>
+      <fix>
+        <bug>49600</bug>: Make exceptions returned by the
+        <code>ProxyDirContext</code> consistent for resources that weren't found
+        by checking the <code>DirContext</code> or the cache. Test case based on
+        a patch provided by Marc Guillemot. (markt)
+      </fix>
     </changelog>
   </subsection>
   <subsection name="Jasper">