Hello,

I want to bring this question again. 

Why do we change NamingEntry type from REFERENCE to ENTRY? I think that each 
lookup must return a new instance. But in this case, it returns the same bound 
object instance.

Let's says that we have a Servlet

MyServlet{

........
private @Resource(name="MyResource") myResource;
.......

public blabla(){
   new InitialContext().lookup("myResource");
}
}

myResource has injected by the container before @PostConstruct is called. After 
that I would like to get a new resource object in blabla() method. It returns 
the same injected resource instance instead of creating a new resource.

I think that it must return a different instance from "myResource". JNDI tree 
of 
the Servlet contains "MyResource/ResourceRef" binding. Therefore each lookup to 
"MyResource" must return a "ResourceRef". Becuase it is a reference, context 
must call NamingManager.getObjectInstance again to create a new instance.

If this is a bug, I will open an issue.

Thanks;

--Gurkan


----- Original Message ----
From: Gurkan Erdogdu <gurkanerdo...@yahoo.com>
To: dev@tomcat.apache.org
Sent: Tue, September 21, 2010 6:30:43 PM
Subject: NamingContext Possible Bug

Hello folks,

In NamingContext implementation, if "lookup()" is a Reference, current 
implementation caches the result of the NamingManager # getObjectInstance via 
following statements and changes the type of the entry. In the following 
lookups, same object is returned. I would like to write ObjectFactory that 
returns new instance for each time lookup is called on its reference. But with 
the current implementation, it is not possible to write such an object factory 
because of aferomentioned sitaution. I think that entry must be stay as 
Reference instead of changing entry type.

WDYT?

NamingContext class:

protected Object lookup(Name name, boolean resolveLinks)
        throws NamingException {
.....
            } else if (entry.type == NamingEntry.REFERENCE) {
                try {
                    Object obj = NamingManager.getObjectInstance
                        (entry.value, name, this, env);
                    if (obj != null) {
                        entry.value = obj;                            
                        entry.type = NamingEntry.ENTRY;  ---> CHANGES type of 
the naming entry
                    }
                    return obj; 
                } catch (NamingException e) {
                    throw e;
                } catch (Exception e) {
                    log.warn(sm.getString
                             ("namingContext.failResolvingReference"), e);
                    throw new NamingException(e.getMessage());
                }
            } 

...........
}




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



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

Reply via email to