Bug 43470 - ClassCastException at org.apache.catalina.deploy.NamingResources
Summary: ClassCastException at org.apache.catalina.deploy.NamingResources
Status: RESOLVED FIXED
Alias: None
Product: Tomcat 6
Classification: Unclassified
Component: Catalina (show other bugs)
Version: 6.0.14
Hardware: Other other
: P2 normal (vote)
Target Milestone: default
Assignee: Tomcat Developers Mailing List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2007-09-24 19:41 UTC by Lucas Galfaso
Modified: 2008-05-01 12:18 UTC (History)
0 users



Attachments

Note You need to log in before you can comment on or make changes to this bug.
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