Bug 48049

Summary: org.apache.naming.NamingContext's destroySubcontext() method doesn't invoke itself recursively, but invoke unbind() method
Product: Tomcat 5 Reporter: qingyang.xu <qingyang.xu>
Component: CatalinaAssignee: Tomcat Developers Mailing List <dev>
Status: RESOLVED FIXED    
Severity: normal    
Priority: P2    
Version: 5.5.28   
Target Milestone: ---   
Hardware: PC   
OS: Linux   

Description qingyang.xu 2009-10-25 07:24:55 UTC
Below is the original implementation of destroySubcontext(Name name) method:

public void destroySubcontext(Name name)
        throws NamingException {
        
        checkWritable();
        
        while ((!name.isEmpty()) && (name.get(0).length() == 0))
            name = name.getSuffix(1);
        if (name.isEmpty())
            throw new NamingException
                (sm.getString("namingContext.invalidName"));
        
        NamingEntry entry = (NamingEntry) bindings.get(name.get(0));
        
        if (entry == null) {
            throw new NameNotFoundException
                (sm.getString("namingContext.nameNotBound", name.get(0)));
        }
        
        if (name.size() > 1) {
            if (entry.type == NamingEntry.CONTEXT) {
                ((Context) entry.value).unbind(name.getSuffix(1));
            } else {
                throw new NamingException
                    (sm.getString("namingContext.contextExpected"));
            }
        } else {
            if (entry.type == NamingEntry.CONTEXT) {
                ((Context) entry.value).close();
                bindings.remove(name.get(0));
            } else {
                throw new NotContextException
                    (sm.getString("namingContext.contextExpected"));
            }
        }
        
    }


However, the method invokes 'unbind' method rather than invokes itself recursively. 

if (name.size() > 1) {
            if (entry.type == NamingEntry.CONTEXT) {
                ((Context) entry.value).unbind(name.getSuffix(1));
            } else {
                throw new NamingException
                    (sm.getString("namingContext.contextExpected"));
            }

should be: 

if (name.size() > 1) {
            if (entry.type == NamingEntry.CONTEXT) {
                ((Context) entry.value).destroySubcontext(name.getSuffix(1));
            } else {
                throw new NamingException
                    (sm.getString("namingContext.contextExpected"));
            }
Comment 1 Mark Thomas 2009-11-22 14:58:51 UTC
Thanks for the patch. It has been committed to trunk and proposed for 6.0.x and 5.5.x
Comment 2 Mark Thomas 2009-12-16 03:38:25 UTC
This has been fixed in 6.0.x and will be in 6.0.21 onwards.

Thanks again for the patch.
Comment 3 Konstantin Kolinko 2010-01-27 00:39:10 UTC
Fixed in 5.5, will be in 5.5.29 onwards. Thank you.