tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Christopher Schultz <>
Subject Re: instanceof drives me nuts!
Date Fri, 31 Oct 2003 15:06:12 GMT

>>As I didn't build the project, I am not so familiar with it and I
>>couldn't avoid to put some of the classes in several places (server, common,
>>shared, WEB-INF of my apps....).
> Don't do this, as it can lead to unpredictable classloading errors.
> Keep everything you can in WEB-INF/lib, the rest in common/lib, but no
> jar should be in both places.  And you probably don't need to put
> anything at all of yours in the server classloader directories.

I couldn't agree more. If possible, try and change the configuration so 
that you have fewer application dependencies in the server/lib and 
common/lib directories.

> If the doSomething is not executed, how do you know if clause evaluates
> to true?  From the debugger I suppose?
> You can also try the other way around,
> callback.getClass().isAssignableFrom(ApplicationCallback.class), to see
> what would happen.
>>Has anybody experienced this kind of weird behaviour?
> Strange.  I think I've had that happen once or twice, but I can't recall
> the solution ;(  

Don't forget that (object instanceof MyClass) only works when:

- The object actually inherits from MyClass
- object.getClass() was loaded by the same classloader as MyClass

Remember that the same class can be loaded twice by different class 
loaders. The instances they create are not assignable (d'oh)!

This is why ClassLoading issues are so hairy.


To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message