My interface is only in the 2 context specific locations: Application A context a: /WEB-INF/lib/interface.jar Application B context b: /WEB-INF/lib/interface.jar
It is not in the Tomcat common or shared lib folders; I've verified this just in case I had a brain cramp. > I've seen this with Oracle jdbc objects. If you have classes12.jar in > your > WEB-INF/lib directory, and a copy in common/lib (for the Tomcat > Datasource) > then you will have TWO oracle.jdbc.XX classes loaded, one in the common > classloader and on in your web app's classloader and although they are > both > oracle.jdbc.XX, they are not the SAME class object (instance). > > So, be certain your interface X is not in two visible places. Or if it > is, > you cannot cast objects from one classloader to the other. > > Tim > > -----Original Message----- > From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] > Sent: Thursday, April 06, 2006 10:10 AM > To: users@tomcat.apache.org > Subject: crossContext breaking class hierarchy? > > Hello, > > I am experiencing a problem with Tomcat and class hierarchies. In > particular when an object (which implements interface X) is shared among > serveral contexts I am unable to cast the object back into interface X. > > Here is the setup (for simplicity I'll illustrate this with 2 contexts): > > * Interface "ClassInterface" is distributed across all applications in a > .jar. > > Application A in context a > -------------------------- > - Implements ClassInterface and adds an instance of the class in it's > context: > > ClassInterface i = new ClassInterfaceImplementation(); > getServletContext().setAttribute("some.key", i); > > Application B in context b > -------------------------- > - Tries to cast the object in the context back into a ClassInterface but > fails with a classCastException: ClassInterfaceImplementation > > ServletContext context = (ServletContext) > getServletContext.getContext("/a"); > ClassInterface i = (ClassInterface) context.getAttribute("some.key"); > -- EXCEPTION IS THROWN -- > java.lang.ClassCastException: ClassInterfaceImplementation > > > Has anybody experienced this before? Does setting an attribute in the > context mess things up with the class hierarchy? > > Thanks. > > --------------------------------------------------------------------- > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > > > > --------------------------------------------------------------------- > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > > --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]