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

Final variable analysis broken with try/catch/finally

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 2.5.x
    • 2.5.0-beta-3
    • Compiler
    • None

    Description

      In this code:

      final begin
      try {
        begin = new Date()
      } finally {
        println 'done'
      }
      

      The current error is:

      The variable [begin] may be uninitialized
      

      But this should only happen if begin is used in the catch or finally blocks or prior to the first assignment.

      This impacts Spock usage since it converts the following into something similar to above:

      @Grab('org.spockframework:spock-core:1.1-groovy-2.4-SNAPSHOT')
      @GrabExclude('org.codehaus.groovy:groovy-all')
      import spock.lang.Specification
      
      class DummySpec extends Specification {
          def 'FVA when using Spock'() {
              given:
              final begin = new Date()
      
              cleanup:
              println 'done'
          }
      }
      

      Attachments

        1. screenshot-1.png
          13 kB
          Paul King

        Issue Links

          Activity

            People

              paulk Paul King
              paulk Paul King
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: