Uploaded image for project: 'Groovy'
  1. Groovy
  2. GROOVY-4477

Exceptions do not get unwrapped from InvokerInvocationException

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 1.7.4
    • 1.7.6, 1.8-beta-3
    • 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.

      MyFoo.java
      public interface MyFoo {
          void baz() throws MyException;
      }
      
      MyException.java
      public class MyException extends Exception {
          public MyException(final String message) {
              super(message);
          }
      }
      

      Processor.java representing a third-party library

      Processor.java
      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.

      Attachments

        Activity

          People

            blackdrag Jochen Theodorou
            roller_vaclav Vaclav Pech
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: