Fix remaining issue described in https://issues.apache.org/bugzilla/show_bug.cgi...
authormarkt <markt@13f79535-47bb-0310-9956-ffa450edef68>
Wed, 12 May 2010 11:10:03 +0000 (11:10 +0000)
committermarkt <markt@13f79535-47bb-0310-9956-ffa450edef68>
Wed, 12 May 2010 11:10:03 +0000 (11:10 +0000)
doLookup should return null if the resource cannot be found and should not throw an exception
Fixes a potential infinite loop in VirtualDirContext

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

java/org/apache/naming/resources/BaseDirContext.java
java/org/apache/naming/resources/FileDirContext.java
java/org/apache/naming/resources/LocalStrings.properties
java/org/apache/naming/resources/VirtualDirContext.java
java/org/apache/naming/resources/WARDirContext.java

index b388050..5e72fa6 100644 (file)
@@ -1501,7 +1501,7 @@ public abstract class BaseDirContext implements DirContext {
     protected abstract Attributes doGetAttributes(String name, String[] attrIds)
         throws NamingException;
 
-    protected abstract Object doLookup(String name) throws NamingException;
+    protected abstract Object doLookup(String name);
 
     protected abstract NamingEnumeration<Binding> doListBindings(String name)
         throws NamingException;
index 412171c..22cdfc8 100644 (file)
@@ -193,11 +193,9 @@ public class FileDirContext extends BaseDirContext {
      *
      * @param name the name of the object to look up
      * @return the object bound to name
-     * @exception NamingException if a naming exception is encountered
      */
     @Override
-    protected Object doLookup(String name)
-        throws NamingException {
+    protected Object doLookup(String name) {
         Object result = null;
         File file = file(name);
 
index a3c0d13..4e1a37d 100644 (file)
@@ -33,6 +33,7 @@ resources.invalidAliasMapping=The alias mapping ''{0}'' is not valid
 resources.invalidAliasNotAllowed=The alias location ''{0}'' is not allowed
 resources.invalidAliasNotExist=The alias location ''{0}'' does not exist
 resources.invalidAliasFile=The alias location ''{0}'' points to a file that is not a WAR file
+resources.invalidName=The name [{0}] is not valid
 standardResources.alreadyStarted=Resources has already been started
 standardResources.directory=File base {0} is not a directory
 standardResources.exists=File base {0} does not exist
index eeee2a5..6974c09 100644 (file)
@@ -159,7 +159,7 @@ public class VirtualDirContext extends FileDirContext {
     }
 
     @Override
-    protected Object doLookup(String name) throws NamingException {
+    protected Object doLookup(String name) {
 
         // handle "virtual" tlds
         if (name.startsWith("/WEB-INF/") && name.endsWith(".tld")) {
@@ -178,7 +178,7 @@ public class VirtualDirContext extends FileDirContext {
             }
         }
 
-        return super.lookup(name);
+        return super.doLookup(name);
     }
 
     /**
index 54213fd..e5b3d76 100644 (file)
@@ -32,6 +32,7 @@ import java.util.zip.ZipFile;
 
 import javax.naming.Binding;
 import javax.naming.CompositeName;
+import javax.naming.InvalidNameException;
 import javax.naming.Name;
 import javax.naming.NameClassPair;
 import javax.naming.NamingEnumeration;
@@ -190,13 +191,17 @@ public class WARDirContext extends BaseDirContext {
      * 
      * @param strName the name of the object to look up
      * @return the object bound to name
-     * @exception NamingException if a naming exception is encountered
      */
     @Override
-    protected Object doLookup(String strName)
-        throws NamingException {
+    protected Object doLookup(String strName) {
 
-        Name name = new CompositeName(strName);
+        Name name;
+        try {
+            name = new CompositeName(strName);
+        } catch (InvalidNameException e) {
+            log.info(sm.getString("resources.invalidName", strName), e);
+            return null;
+        }
 
         if (name.isEmpty())
             return this;