You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by bu...@apache.org on 2014/07/25 09:40:20 UTC

[Bug 56771] New: Avoid throwing NameNotFoundException in BaseDirContext#lookup()

https://issues.apache.org/bugzilla/show_bug.cgi?id=56771

            Bug ID: 56771
           Summary: Avoid throwing NameNotFoundException in
                    BaseDirContext#lookup()
           Product: Tomcat 7
           Version: trunk
          Hardware: All
                OS: All
            Status: NEW
          Severity: normal
          Priority: P2
         Component: Catalina
          Assignee: dev@tomcat.apache.org
          Reporter: xshao@ebay.com

Created attachment 31848
  --> https://issues.apache.org/bugzilla/attachment.cgi?id=31848&action=edit
The issue

NameNotFoundException is thrown when the resource can't be found in this
DirContext.

In the method BaseDirContext, it also goes through all the alternate or backup
DirContexts to lookup the resource one by one until the resource is found.
A NameNotFoundException is thrown in the alternate DirContext when the given
resource name isn't in this DirContext.

  public final Object lookup(String name) throws NamingException {
        // First check for aliases
        if (!aliases.isEmpty()) {
            AliasResult result = findAlias(name);
            if (result.dirContext != null) {
                return result.dirContext.lookup(result.aliasName);
            }
        }

        // Next do a standard lookup
        Object obj = doLookup(name);

        if (obj != null)
            return obj;

        // Check the alternate locations
        for (DirContext altDirContext : altDirContexts) {
            try {
                obj = altDirContext.lookup("/META-INF/resources" + name);
                if (obj != null)
                    return obj;
            } catch ( NamingException ex) {
                // ignore
            }
        }

        // Really not found
        throw new NameNotFoundException(
                sm.getString("resources.notFound", name));
    }


It takes much CPU time.   It could be optimized by checking result is null or
not.

Here is the optimized code,
    public final Object lookup(String name) throws NamingException {
        // First check for aliases
        Object obj = doLookupWithoutNFE(name);
        if (obj != null) {
            return obj;
        }

        // Really not found
        throw new NameNotFoundException(
                sm.getString("resources.notFound", name));
    }

    protected Object doLookupWithoutNFE(String name) throws NamingException {
        if (!aliases.isEmpty()) {
            AliasResult result = findAlias(name);
            if (result.dirContext != null) {
                return result.dirContext.lookup(result.aliasName);
            }
        }

        // Next do a standard lookup
        Object obj = doLookup(name);

        if (obj != null)
            return obj;

        // Check the alternate locations
        String resourceName = "/META-INF/resources" + name;
        for (DirContext altDirContext : altDirContexts) {
            if (altDirContext instanceof BaseDirContext) {
                obj =
((BaseDirContext)altDirContext).doLookupWithoutNFE(resourceName);
            }
            else {
                try {
                    obj = altDirContext.lookup(resourceName);
                } catch ( NamingException ex) {
                    // ignore
                }
            }
            if (obj != null) {
                return obj;
            }
        }

        //Return null instead
        return null;
    }

-- 
You are receiving this mail because:
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


[Bug 56771] Avoid throwing NameNotFoundException in BaseDirContext#lookup()

Posted by bu...@apache.org.
https://issues.apache.org/bugzilla/show_bug.cgi?id=56771

--- Comment #2 from Sheldon Shao <xs...@ebay.com> ---
Created attachment 31850
  --> https://issues.apache.org/bugzilla/attachment.cgi?id=31850&action=edit
JProfiler snapshot after optimized

-- 
You are receiving this mail because:
You are the assignee for the bug.

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


[Bug 56771] Avoid throwing NameNotFoundException in BaseDirContext#lookup()

Posted by bu...@apache.org.
https://issues.apache.org/bugzilla/show_bug.cgi?id=56771

--- Comment #1 from Sheldon Shao <xs...@ebay.com> ---
Created attachment 31849
  --> https://issues.apache.org/bugzilla/attachment.cgi?id=31849&action=edit
Patch for BaseDirContext

Patch for BaseDirContext

-- 
You are receiving this mail because:
You are the assignee for the bug.

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


[Bug 56771] Avoid throwing NameNotFoundException in BaseDirContext#lookup()

Posted by bu...@apache.org.
https://issues.apache.org/bugzilla/show_bug.cgi?id=56771

Violeta Georgieva <vi...@apache.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|---                         |FIXED

--- Comment #3 from Violeta Georgieva <vi...@apache.org> ---
Hi,

Thanks for the report and the patch.
This has been fixed in 7.0.x for 7.0.56 onwards.

Regards,
Violeta

-- 
You are receiving this mail because:
You are the assignee for the bug.

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org