Details
-
Type:
Bug
-
Status:
Closed
-
Priority:
Minor
-
Resolution: Fixed
-
Affects Version/s: 1.7.0
-
Fix Version/s: 1.7.2, 1.8-beta-1
-
Component/s: None
-
Labels:None
-
Testcase included:yes
-
Number of attachments :
Description
So we upgraded from 1.6.3 to Groovy 1.7.0 and realized that one of our tests started failing... it seems that in 1.7.0 unchecked exceptions are simply rethrown (groovy.lang.Closure#throwRuntimeException(Throwable) called from #call(Object[])). Which in groovy.util.GroovyTestCase#shouldFailWithCause(Class,Closure), the exception falls to the catch Throwable branch and the cause is not attempted to be determined beyond that, which causes the test to fail.
Example test showing a successful checked and unsuccessful unchecked exception:
package dummy; import groovy.util.GroovyTestCase; import java.io.IOException; import org.junit.Test; /** * Demonstrates cases of should fail with cause. * @author Charlie Huggard-Lee */ class DummyTest extends GroovyTestCase { public static void failChecked() throws Exception { throw new Exception(new IOException()); } public static void failUnchecked() { throw new RuntimeException(new IOException()); } @Test public void testcheckedFailure() { //Hurray! shouldFailWithCause(IOException.class, {DummyTest.failChecked()}) } @Test public void testuncheckedFailure() { //BOO!!! shouldFailWithCause(IOException.class, {DummyTest.failUnchecked()}) } }
I don't think it is related to groovy.lang.Closure#throwRuntimeException(Throwable) simply rethrowing unchecked exceptions. Even in 1.6.3, it does the same thing - https://svn.codehaus.org/groovy/tags/GROOVY_1_6_3/src/main/groovy/lang/Closure.java
I think it is possibly related to - http://fisheye.codehaus.org/browse/groovy/trunk/groovy/groovy-core/src/main/org/codehaus/groovy/reflection/CachedMethod.java?r1=12759&r2=17769