Bug 43470

Summary: ClassCastException at org.apache.catalina.deploy.NamingResources
Product: Tomcat 6 Reporter: Lucas Galfaso <lgalfaso>
Component: CatalinaAssignee: Tomcat Developers Mailing List <dev>
Status: RESOLVED FIXED    
Severity: normal    
Priority: P2    
Version: 6.0.14   
Target Milestone: default   
Hardware: Other   
OS: other   

Description Lucas Galfaso 2007-09-24 19:41:40 UTC
NamingResources reads

    public void removeLocalEjb(String name) {

        entries.remove(name);

        ContextLocalEjb localEjb = null;
        synchronized (localEjbs) {
            localEjb = (ContextLocalEjb) ejbs.remove(name);
        }
        if (localEjb != null) {
            support.firePropertyChange("localEjb", localEjb, null);
            localEjb.setNamingResources(null);
        }

    }

if should be 

    public void removeLocalEjb(String name) {

        entries.remove(name);

        ContextLocalEjb localEjb = null;
        synchronized (localEjbs) {
            localEjb = (ContextLocalEjb) localEjbs.remove(name); // The error
was in this line
        }
        if (localEjb != null) {
            support.firePropertyChange("localEjb", localEjb, null);
            localEjb.setNamingResources(null);
        }

    }

Regards,
  lg
Comment 1 Lucas Galfaso 2007-09-24 20:02:04 UTC
There are some more bug at this same class
It reads

    public void addResourceEnvRef(ContextResourceEnvRef resource) {

        if (entries.containsKey(resource.getName())) {
            return;
        } else {
            entries.put(resource.getName(), resource.getType());
        }

        synchronized (localEjbs) { // This is wrong
            resource.setNamingResources(this);
            resourceEnvRefs.put(resource.getName(), resource);
        }
        support.firePropertyChange("resourceEnvRef", null, resource);

    }

Corrected version

    public void addResourceEnvRef(ContextResourceEnvRef resource) {

        if (entries.containsKey(resource.getName())) {
            return;
        } else {
            entries.put(resource.getName(), resource.getType());
        }

        synchronized (resource) { // This is correct
            resource.setNamingResources(this);
            resourceEnvRefs.put(resource.getName(), resource);
        }
        support.firePropertyChange("resourceEnvRef", null, resource);

    }



and

    public void removeResourceEnvRef(String name) {

        entries.remove(name);

        String type = null;
        synchronized (resourceEnvRefs) {
            type = (String) resourceEnvRefs.remove(name);
        }
        if (type != null) {
            support.firePropertyChange("resourceEnvRef",
                                       name + ":" + type, null);
        }

    }


Should be

    public void removeResourceEnvRef(String name) {

        entries.remove(name);

        ContextResourceEnvRef resourceEventRef = null;
        synchronized (resourceEnvRefs) {
            resourceEventRef = (ContextResourceEnvRef) resourceEnvRefs.remove(name);
        }
        if (resourceEventRef != null) {
            support.firePropertyChange("resourceEnvRef",
                                       name + ":" + resourceEventRef.getType(),
null);
        }

    }


Regards,
  lg
Comment 2 Mark Thomas 2007-09-24 20:47:44 UTC
Thanks for all your patches. Could you provide them in diff -u format as they
are easier to read and apply that way. Cheers.
Comment 3 Mark Thomas 2008-04-25 11:17:47 UTC
Thanks for the patch. I had to make a few tweaks. See http://svn.apache.org/viewvc?rev=651675&view=rev

It has been committed to trunk and proposed for 6.0.x
Comment 4 Mark Thomas 2008-05-01 12:18:57 UTC
This patch has been committed to 6.0.x and will be included in 6.0.17