Hello,

Apache Tomcat/5.5.26
jdk1.5.0_11 / jdk1.5.0_19
Windows XP / SunOS 5.10

Short description of the use case:
- User fills form with some wrong information
- tomcat sends (RMI call) to another server
- server throws ValidationException back to tomcat
- tomcat _sometimes_ wraps the ValidationException with
UndeclaredThrowableException

Installation:
Tomcat hosts several web applications (war), each of the wars include a
jar with the ValidationException class in the WEB-INF/lib directory. The
deployed jars are indentical. The jar cannot be put to shared or common
because of some internal reasons.

Analysis:
In the case where the ValidationException is wrapped by the
UndeclaredThrowableException, the WebappClassLoader instance of the
current thread and the instance of the WebappClassLoader of the caught
(and wrapped) ValidationException are different. As a result the
ValidationException that is caught is not the same as the one that is
expected and thus violates the interface =>
UndeclaredThrowableException.
In the following code the "instanceof ValidationException" returns
false:
        [...]
            key = saveSomething();
        }
        catch (ValidationException e)
        {
        [...]
        }
        catch( UndeclaredThrowableException e1 )
        {
            Throwable t = e1.getUndeclaredThrowable();
            
            if(t instanceof ValidationException)
            {
            [...]
            }
            else
            {
                log.info( "Not a ValidationException: ", t );
                log.info( "  thrown Exception class: " + t.getClass() +
": " + getUniqueID( t ) );
                log.info( "expected Exception class: " +
ValidationException.class + ": " + getUniqueID( new
ValidationException() ) );
                throw e1;
            }
        }

Hint:
getUniqueID also prints the ClassLoader information. In this case both
ValidationExceptions are loaded by different WebappClassLoader
instances.

Question:
It seems that during unmarshalling of the ValidationException it is not
predictable which ValidationException (identified by its ClassLoader) is
constructed. It seems that the WebApp may get a ValidationException that
doesn't fit to its own ClassLoader but to a ClassLoader of another
WebApp.
Is this a bug of the tomcat? I mean shouldn't the WebApp get the
ValidationException from the same ClassLoader that belongs to the WebApp
that invoked the RMI call?

Regards
Fares

Reply via email to