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

Incorrect exception behavior when class has @CompileStatic

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 2.1.8
    • 2.2.1
    • Static compilation
    • None

    Description

      import groovy.transform.CompileStatic
      
      @CompileStatic
      class Client<T> {
        static String method() {
          return ({
            try {
              return doSomething()
            } catch (IOException ioe) {
              println "IOException: ${ioe}"
            } catch (Exception e) {
              println "Exception: ${e}"
            }
          })()
        }
      
        private static <T> T doSomething() throws IOException {
          throw new IOException()
          return null
        }
      }
      
      Client.method()
      

      Without the @CompileStatic, it outputs (as expected)

      IOException: java.io.IOException
      

      With the @CompileStatic, it outputs

      Exception: org.codehaus.groovy.runtime.InvokerInvocationException: java.io.IOException
      

      Attachments

        Activity

          People

            melix Cédric Champeau
            acourtneybrown Adam Brown
            Votes:
            5 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: