From fabce6752ba37a14d6116e26af4b09ef9e4aa589 Mon Sep 17 00:00:00 2001 From: markt Date: Wed, 21 Jul 2010 20:30:53 +0000 Subject: [PATCH] Fix https://issues.apache.org/bugzilla/show_bug.cgi?id=49600 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 --- .../apache/naming/resources/BaseDirContext.java | 10 ++++++--- .../apache/naming/resources/FileDirContext.java | 9 ++++---- .../apache/naming/resources/ProxyDirContext.java | 25 +++++++++++----------- .../org/apache/naming/resources/WARDirContext.java | 3 ++- webapps/docs/changelog.xml | 6 ++++++ 5 files changed, 33 insertions(+), 20 deletions(-) diff --git a/java/org/apache/naming/resources/BaseDirContext.java b/java/org/apache/naming/resources/BaseDirContext.java index e8fe554d1..cb7901b0f 100644 --- a/java/org/apache/naming/resources/BaseDirContext.java +++ b/java/org/apache/naming/resources/BaseDirContext.java @@ -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)); } /** diff --git a/java/org/apache/naming/resources/FileDirContext.java b/java/org/apache/naming/resources/FileDirContext.java index 22cdfc89f..d5e09e4de 100644 --- a/java/org/apache/naming/resources/FileDirContext.java +++ b/java/org/apache/naming/resources/FileDirContext.java @@ -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()); diff --git a/java/org/apache/naming/resources/ProxyDirContext.java b/java/org/apache/naming/resources/ProxyDirContext.java index 88bf40da6..3c9339fe2 100644 --- a/java/org/apache/naming/resources/ProxyDirContext.java +++ b/java/org/apache/naming/resources/ProxyDirContext.java @@ -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; } diff --git a/java/org/apache/naming/resources/WARDirContext.java b/java/org/apache/naming/resources/WARDirContext.java index e5b3d76f1..850fa1c3b 100644 --- a/java/org/apache/naming/resources/WARDirContext.java +++ b/java/org/apache/naming/resources/WARDirContext.java @@ -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()); } diff --git a/webapps/docs/changelog.xml b/webapps/docs/changelog.xml index fdbaefea0..b98753ad6 100644 --- a/webapps/docs/changelog.xml +++ b/webapps/docs/changelog.xml @@ -178,6 +178,12 @@ default timeout configurable using the asyncTimeout attribute on the connector. (pero/markt) + + 49600: Make exceptions returned by the + ProxyDirContext consistent for resources that weren't found + by checking the DirContext or the cache. Test case based on + a patch provided by Marc Guillemot. (markt) + -- 2.11.0