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

final variable set in try fails to compile if throws in catch

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Open
    • Minor
    • Resolution: Unresolved
    • 2.5.1
    • None
    • Compiler
    • None

    Description

      final Date date = new Date()
      final Long ms
      try {
        ms = date.parse('')
      } catch (IllegalArgumentException e) {
        throw new RuntimeException(e)
      }
      println ms
      

      Expected result (Groovy 2.4.15):

      Java.lang.RuntimeException: java.lang.IllegalArgumentException
      	at ConsoleScript0.run(ConsoleScript0:6)
      Caused by: java.lang.IllegalArgumentException
      	at java_util_Date$parse.call(Unknown Source)
      	at ConsoleScript0.run(ConsoleScript0:4)
      

      Fails to compile with Groovy 2.5.1:

      The variable [ms] may be uninitialized
      . At [8:9]  at line: 8, column: 9
      

      Attachments

        Activity

          People

            Unassigned Unassigned
            jexler Jex Jexler
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated: