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

Conditionally initialized `final` variables considered maybe uninitialized

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 4.0.1
    • 4.0.2
    • None
    • None

    Description

      Running the following in `groovyConsole`:

      final int i
      final boolean a = true
      if (a) {
          i = 1
      } else {
          throw new IllegalStateException('a is false')
      }
      println "i = $i"
      

      would give me:

      1 compilation error:
      The variable [i] may be uninitialized
      . At [9:15] at line: 9, column: 15
      

      It seems groovyc does not take throwing an exception as a non-reachable branch.

      This code is almost a verbatim copy from a java code that is working.

      This looks similar to GROOVY-8472, and a few others.

      Attachments

        Activity

          People

            paulk Paul King
            azurvii V
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Time Tracking

                Estimated:
                Original Estimate - Not Specified
                Not Specified
                Remaining:
                Remaining Estimate - 0h
                0h
                Logged:
                Time Spent - 20m
                20m