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

Final variable analysis doesn't account for early exit for try/catch/finally

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Closed
    • Major
    • Resolution: Fixed
    • None
    • 2.5.0-rc-2
    • None
    • None

    Description

      An example with early return from a method:

      def method(String foo) {
          final str
          try {
              str = foo.trim()
          }
          catch(e) {
              println e
              return null
          }
          int exitCode = str.isInteger() ? str.toInteger() : null
          exitCode
          //str.isInteger() ? str.toInteger() : null // this doesn't trigger the error
      }
      
      println method(null)
      

      And a slight rearrangement of above:

      def method(String foo) {
          final str
          try {
              return foo.trim()
          }
          catch(e) {
              str = '-1'
          }
          int exitCode = str.toInteger() // The variable [str] may be uninitialized
          exitCode
      }
      
      println method(null)
      

      Attachments

        Issue Links

          Activity

            People

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

              Dates

                Created:
                Updated:
                Resolved: