Details
-
Bug
-
Status: Closed
-
Major
-
Resolution: Fixed
-
1.7.4
-
None
-
None
Description
Based on the brief exchange on the mailing list, here's the problem:
Groovy code calls a Java library passing in a Groovy instance (which was created using the "
{...}as SomeInterface" dynamic cast) as parameter. The Java library calls the passed-in Groovy object. The Groovy object throws an exception. The Java library doesn't see the exception, as it is wrapped (because of the groovy bug) inside InvokerInvocationException, so the catch clause inside the library doesn't trigger and the library cannot react. My Groovy code gets an unexpected library-specific exception thrown up to its face.
I revealed the issue when trying to make Multiverse (STM) work with Groovy. Please find below a distilled code example reproducing the problem.
public interface MyFoo { void baz() throws MyException; }
public class MyException extends Exception { public MyException(final String message) { super(message); } }
Processor.java representing a third-party library
public class Processor { public static void bar(final MyFoo code) { try { code.baz(); } catch (MyException e) { System.out.println("Just swallowed the error"); } } }
Groovy script
Processor.bar( { throw new MyException('test') } as MyFoo)
The problem is probably related to the dynamic casting, since the following script works fine:
Processor.bar new MyFoo() { void baz() { throw new MyException('test') } }
The failing script uses a dynamic cast.