Author: hlship Date: Wed Sep 1 18:57:32 2010 New Revision: 991651 URL: http://svn.apache.org/viewvc?rev=991651&view=rev Log: Handle the unlikely case where an exception includes a property that is the same exception (i.e., detect the infinite loop)
Modified: tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/services/ExceptionAnalyzerImpl.java tapestry/tapestry5/trunk/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/internal/services/ExceptionAnalyzerImplTest.java Modified: tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/services/ExceptionAnalyzerImpl.java URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/services/ExceptionAnalyzerImpl.java?rev=991651&r1=991650&r2=991651&view=diff ============================================================================== --- tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/services/ExceptionAnalyzerImpl.java (original) +++ tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/services/ExceptionAnalyzerImpl.java Wed Sep 1 18:57:32 2010 @@ -128,7 +128,13 @@ public class ExceptionAnalyzerImpl imple if (cause == null && Throwable.class.isAssignableFrom(pa.getType())) { // Ignore the property, but track it as the cause. - cause = (Throwable) pa.get(t); + + Throwable nestedException = (Throwable) pa.get(t); + + // Handle the case where an exception is its own cause (avoid endless loop!) + if (t != nestedException) + cause = nestedException; + continue; } Modified: tapestry/tapestry5/trunk/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/internal/services/ExceptionAnalyzerImplTest.java URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/internal/services/ExceptionAnalyzerImplTest.java?rev=991651&r1=991650&r2=991651&view=diff ============================================================================== --- tapestry/tapestry5/trunk/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/internal/services/ExceptionAnalyzerImplTest.java (original) +++ tapestry/tapestry5/trunk/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/internal/services/ExceptionAnalyzerImplTest.java Wed Sep 1 18:57:32 2010 @@ -179,4 +179,37 @@ public class ExceptionAnalyzerImplTest e assertEquals(ei.getProperty("code"), "0099"); } + @SuppressWarnings("all") + public static class SelfCausedException extends RuntimeException + { + public SelfCausedException(String message) + { + super(message); + } + + public Throwable getCause() + { + return this; + } + } + + @Test + public void exception_that_is_its_own_cause() + { + String message = "Hey! We've Got Not Tomatoes!"; + + Throwable t = new SelfCausedException(message); + + ExceptionAnalysis ea = analyzer.analyze(t); + + assertEquals(ea.getExceptionInfos().size(), 1); + + ExceptionInfo ei = ea.getExceptionInfos().get(0); + + assertEquals(ei.getClassName(), SelfCausedException.class.getName()); + assertEquals(ei.getMessage(), message); + + assertTrue(ei.getPropertyNames().isEmpty()); + assertFalse(ei.getStackTrace().isEmpty()); + } }