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

closure-passing syntax not working with Thread constructor in 1.7.6

    XMLWordPrintableJSON

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Won't Fix
    • Affects Version/s: 1.7.6
    • Fix Version/s: None
    • Component/s: parser
    • Labels:
      None

      Description

      The following code fragment:

      def t = new Thread() {
          println 'moo'
      }
      t.start()
      t.join()
      

      works with groovy 1.6.7 but not with groovy 1.7.6. With 1.7.6, I have to use this intead:

      def t = new Thread({
          println 'moo'
      })
      t.start()
      t.join()
      

      I am not a groovy expert, but I thought those two should be equivalent since putting a closure after a function call should be the same as passing the closure as the last argument of the function. Note that this:

      def f(x) {
          x()
      }
      f() {
          println 'moo'
      }
      

      works fine in both versions, so this appears to have something to do with Thread. (Well, I don't really know that. You can come to a better conclusion.)

      For what it's worth, my original code was actually using a Thread constructor that also took a ThreadGroup, more like this:

      def t = new Thread(new ThreadGroup()) {
          println 'moo'
      }
      t.start()
      t.join()
      

      which is why I'm explicitly creating the thread. However, the very minimal example above also appears to illustrate the problem.
      Also, I found this testing an application that has the embeddable groovy in it. I hadn't updated the application since 1.7-rc-1 and had not tested that particular code fragment with a more recent version of groovy until now. However, it did work with 1.7-rc-1. I can't say more precisely than that when it stopped working.

        Attachments

          Activity

            People

            • Assignee:
              guillaume Guillaume Sauthier
              Reporter:
              ejb@ql.org Jay Berkenbilt
            • Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: