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

Stack trace doesn't point to source of error in DELEGATE_ONLY assignment case

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • None
    • 1.6.5, 1.7-beta-2
    • None
    • None

    Description

      In some cases, the stack trace doesn't point to the source of error. Here is a case where the source of error is located properly:

      def moo(Closure closure) {
      closure.delegate = new Object()
      closure.resolveStrategy = Closure.DELEGATE_ONLY
      closure()
      }

      moo {
      xyz
      }

      Exception in thread "main" groovy.lang.MissingPropertyException: No such property: xyz for class: java.lang.Object
      ... snip ...
      at BindingDemo$_run_closure1.doCall(BindingDemo.groovy:8)
      ... snip ...
      at BindingDemo.moo(BindingDemo.groovy:4)
      ... snip ...
      at BindingDemo.run(BindingDemo.groovy:7)
      ... snip ...

      BindingDemo.groovy:7 is the closure containing the error, BindingDemo.groovy:4 is where I call the problem closure and BindingDemo.groovy:8 is the line where the error is located (ie. missing property exception). Awesome.

      Now try the same thing except with assignment:

      def moo(Closure closure) {
      closure.delegate = new Object()
      closure.resolveStrategy = Closure.DELEGATE_ONLY
      closure()
      }

      moo {
      xyz = 1
      }

      Exception in thread "main" groovy.lang.MissingPropertyException: No such property: xyz for class: java.lang.Object
      ... snip ...
      at BindingDemo.moo(BindingDemo.groovy:4)
      ... snip ...
      at BindingDemo.run(BindingDemo.groovy:7)
      ... snip ...

      This gives the same stack trace except BindingDemo.groovy:8 is missing.

      Getting a line number for a the error is a useful diagnostic to have and the first case demonstrates that this is possible.

      Attachments

        Activity

          People

            blackdrag Jochen Theodorou
            newhoggy John Ky
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: