Author: kkolinko Date: Mon Nov 14 01:10:51 2011 New Revision: 1201568 URL: http://svn.apache.org/viewvc?rev=1201568&view=rev Log: Improve processing of errors that are wrapped into InvocationTargetException. Rethrow errors that must be rethrown.
Modified: tomcat/trunk/java/org/apache/catalina/core/ApplicationContextFacade.java tomcat/trunk/java/org/apache/tomcat/util/IntrospectionUtils.java tomcat/trunk/java/org/apache/tomcat/util/digester/Digester.java tomcat/trunk/test/org/apache/catalina/tribes/demos/IntrospectionUtils.java Modified: tomcat/trunk/java/org/apache/catalina/core/ApplicationContextFacade.java URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/core/ApplicationContextFacade.java?rev=1201568&r1=1201567&r2=1201568&view=diff ============================================================================== --- tomcat/trunk/java/org/apache/catalina/core/ApplicationContextFacade.java (original) +++ tomcat/trunk/java/org/apache/catalina/core/ApplicationContextFacade.java Mon Nov 14 01:10:51 2011 @@ -191,6 +191,7 @@ public class ApplicationContextFacade im return (URL) invokeMethod(context, "getResource", new Object[]{path}); } catch(Throwable t) { + ExceptionUtils.handleThrowable(t); if (t instanceof MalformedURLException){ throw (MalformedURLException)t; } @@ -765,6 +766,7 @@ public class ApplicationContextFacade im try{ return invokeMethod(context, methodName, params); }catch(Throwable t){ + ExceptionUtils.handleThrowable(t); throw new RuntimeException(t.getMessage(), t); } } @@ -870,8 +872,10 @@ public class ApplicationContextFacade im } if (ex instanceof InvocationTargetException) { - realException = - ((InvocationTargetException) ex).getTargetException(); + realException = ex.getCause(); + if (realException == null) { + realException = ex; + } } else { realException = ex; } Modified: tomcat/trunk/java/org/apache/tomcat/util/IntrospectionUtils.java URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/util/IntrospectionUtils.java?rev=1201568&r1=1201567&r2=1201568&view=diff ============================================================================== --- tomcat/trunk/java/org/apache/tomcat/util/IntrospectionUtils.java (original) +++ tomcat/trunk/java/org/apache/tomcat/util/IntrospectionUtils.java Mon Nov 14 01:10:51 2011 @@ -264,6 +264,7 @@ public final class IntrospectionUtils { log.debug("IntrospectionUtils: IllegalAccessException for " + o.getClass() + " " + name + "=" + value + ")", iae); } catch (InvocationTargetException ie) { + ExceptionUtils.handleThrowable(ie.getCause()); if (log.isDebugEnabled()) log.debug("IntrospectionUtils: InvocationTargetException for " + o.getClass() + " " + name + "=" + value + ")", ie); @@ -312,6 +313,7 @@ public final class IntrospectionUtils { log.debug("IntrospectionUtils: IllegalAccessException for " + o.getClass() + " " + name + ")", iae); } catch (InvocationTargetException ie) { + ExceptionUtils.handleThrowable(ie.getCause()); if (log.isDebugEnabled()) log.debug("IntrospectionUtils: InvocationTargetException for " + o.getClass() + " " + name + ")"); @@ -454,7 +456,12 @@ public final class IntrospectionUtils { if (m == null) throw new NoSuchMethodException(target.getClass().getName() + " " + methodN); - return m.invoke(target, new Object[] { param1 }); + try { + return m.invoke(target, new Object[] { param1 }); + } catch (InvocationTargetException ie) { + ExceptionUtils.handleThrowable(ie.getCause()); + throw ie; + } } /** @@ -478,7 +485,12 @@ public final class IntrospectionUtils { if (m == null) throw new NoSuchMethodException(target.getClass().getName() + " " + methodN); - return m.invoke(target, emptyArray); + try { + return m.invoke(target, emptyArray); + } catch (InvocationTargetException ie) { + ExceptionUtils.handleThrowable(ie.getCause()); + throw ie; + } } /** @@ -497,21 +509,27 @@ public final class IntrospectionUtils { " in " + target + " CLASS " + target.getClass()); return null; } - Object o = m.invoke(target, params); + try { + Object o = m.invoke(target, params); - if (log.isDebugEnabled()) { - // debug - StringBuilder sb = new StringBuilder(); - sb.append("" + target.getClass().getName() + "." + methodN + "( "); - for (int i = 0; i < params.length; i++) { - if (i > 0) - sb.append(", "); - sb.append(params[i]); + if (log.isDebugEnabled()) { + // debug + StringBuilder sb = new StringBuilder(); + sb.append(target.getClass().getName()).append('.') + .append(methodN).append("( "); + for (int i = 0; i < params.length; i++) { + if (i > 0) + sb.append(", "); + sb.append(params[i]); + } + sb.append(")"); + log.debug("IntrospectionUtils:" + sb.toString()); } - sb.append(")"); - log.debug("IntrospectionUtils:" + sb.toString()); + return o; + } catch (InvocationTargetException ie) { + ExceptionUtils.handleThrowable(ie.getCause()); + throw ie; } - return o; } public static Object convert(String object, Class<?> paramType) { Modified: tomcat/trunk/java/org/apache/tomcat/util/digester/Digester.java URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/util/digester/Digester.java?rev=1201568&r1=1201567&r2=1201568&view=diff ============================================================================== --- tomcat/trunk/java/org/apache/tomcat/util/digester/Digester.java (original) +++ tomcat/trunk/java/org/apache/tomcat/util/digester/Digester.java Mon Nov 14 01:10:51 2011 @@ -2669,8 +2669,14 @@ public class Digester extends DefaultHan public SAXException createSAXException(String message, Exception e) { if ((e != null) && (e instanceof InvocationTargetException)) { - Throwable t = ((InvocationTargetException) e).getTargetException(); - if ((t != null) && (t instanceof Exception)) { + Throwable t = e.getCause(); + if (t instanceof ThreadDeath) { + throw (ThreadDeath) t; + } + if (t instanceof VirtualMachineError) { + throw (VirtualMachineError) t; + } + if (t instanceof Exception) { e = (Exception) t; } } @@ -2699,8 +2705,14 @@ public class Digester extends DefaultHan */ public SAXException createSAXException(Exception e) { if (e instanceof InvocationTargetException) { - Throwable t = ((InvocationTargetException) e).getTargetException(); - if ((t != null) && (t instanceof Exception)) { + Throwable t = e.getCause(); + if (t instanceof ThreadDeath) { + throw (ThreadDeath) t; + } + if (t instanceof VirtualMachineError) { + throw (VirtualMachineError) t; + } + if (t instanceof Exception) { e = (Exception) t; } } Modified: tomcat/trunk/test/org/apache/catalina/tribes/demos/IntrospectionUtils.java URL: http://svn.apache.org/viewvc/tomcat/trunk/test/org/apache/catalina/tribes/demos/IntrospectionUtils.java?rev=1201568&r1=1201567&r2=1201568&view=diff ============================================================================== --- tomcat/trunk/test/org/apache/catalina/tribes/demos/IntrospectionUtils.java (original) +++ tomcat/trunk/test/org/apache/catalina/tribes/demos/IntrospectionUtils.java Mon Nov 14 01:10:51 2011 @@ -164,6 +164,13 @@ public final class IntrospectionUtils { log.debug("IntrospectionUtils: IllegalAccessException for " + o.getClass() + " " + name + "=" + value + ")", iae); } catch (InvocationTargetException ie) { + Throwable cause = ie.getCause(); + if (cause instanceof ThreadDeath) { + throw (ThreadDeath) cause; + } + if (cause instanceof VirtualMachineError) { + throw (VirtualMachineError) cause; + } if (log.isDebugEnabled()) log.debug("IntrospectionUtils: InvocationTargetException for " + o.getClass() + " " + name + "=" + value + ")", ie); --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org For additional commands, e-mail: dev-h...@tomcat.apache.org