From 821fa2478c102ec4d9c3398952bb54568022de65 Mon Sep 17 00:00:00 2001 From: markt Date: Wed, 12 May 2010 11:10:03 +0000 Subject: [PATCH] Fix remaining issue described in https://issues.apache.org/bugzilla/show_bug.cgi?id=49218 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 | 2 +- java/org/apache/naming/resources/FileDirContext.java | 4 +--- java/org/apache/naming/resources/LocalStrings.properties | 1 + java/org/apache/naming/resources/VirtualDirContext.java | 4 ++-- java/org/apache/naming/resources/WARDirContext.java | 13 +++++++++---- 5 files changed, 14 insertions(+), 10 deletions(-) diff --git a/java/org/apache/naming/resources/BaseDirContext.java b/java/org/apache/naming/resources/BaseDirContext.java index b388050e3..5e72fa669 100644 --- a/java/org/apache/naming/resources/BaseDirContext.java +++ b/java/org/apache/naming/resources/BaseDirContext.java @@ -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 doListBindings(String name) throws NamingException; diff --git a/java/org/apache/naming/resources/FileDirContext.java b/java/org/apache/naming/resources/FileDirContext.java index 412171c65..22cdfc89f 100644 --- a/java/org/apache/naming/resources/FileDirContext.java +++ b/java/org/apache/naming/resources/FileDirContext.java @@ -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); diff --git a/java/org/apache/naming/resources/LocalStrings.properties b/java/org/apache/naming/resources/LocalStrings.properties index a3c0d13cf..4e1a37d4c 100644 --- a/java/org/apache/naming/resources/LocalStrings.properties +++ b/java/org/apache/naming/resources/LocalStrings.properties @@ -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 diff --git a/java/org/apache/naming/resources/VirtualDirContext.java b/java/org/apache/naming/resources/VirtualDirContext.java index eeee2a5f5..6974c09ea 100644 --- a/java/org/apache/naming/resources/VirtualDirContext.java +++ b/java/org/apache/naming/resources/VirtualDirContext.java @@ -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); } /** diff --git a/java/org/apache/naming/resources/WARDirContext.java b/java/org/apache/naming/resources/WARDirContext.java index 54213fd65..e5b3d76f1 100644 --- a/java/org/apache/naming/resources/WARDirContext.java +++ b/java/org/apache/naming/resources/WARDirContext.java @@ -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; -- 2.11.0