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

finally blocks do not always execute

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Critical
    • Resolution: Fixed
    • 2.2.1, 2.2.2
    • 2.4.0-rc-1
    • None
    • None
    • Mavericks, JDK 1.7.0_12-ea

    Description

      finally blocks do not always run, e.g. when an exception is thrown from another nested finally block. I can confirm this issue in at least 2.2.2, 2.2.1, 2.0.5 and 1.8

      /tmp$ cat finally.groovy
      count = 0
      
      def outer() {
          try {
              inner()
          } catch (Exception e) {
              println 'count is: ' + count
          }
      }
      
      def inner() {
          try {
              try {
                  count = 1
              } finally {
                  count = 2
                  throw new RuntimeException('barf')
              }
          } finally {
              count = 3
          }
      }
      
      outer()
      /tmp$ groovy-2.2.2/bin/groovy finally.groovy
      count is: 2
      

      Attachments

        1. finally.groovy
          0.3 kB
          Joe Jordan

        Activity

          People

            Unassigned Unassigned
            joedj Joe Jordan
            Votes:
            2 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: