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

Can not see local variable from overriden method called from the constructor of an anonymous class instance

    XMLWordPrintableJSON

Details

    Description

      Reduced code showing the problem: https://gist.github.com/RomanSaveljev/71ed29b0df3eb306485c

      In the runtime it fails with:

      Caught: java.lang.NullPointerException
      java.lang.NullPointerException
      	at bug$1.func(bug.groovy:14)
      	at A.<init>(bug.groovy:3)
      	at bug$1.<init>(bug.groovy)
      	at bug.func(bug.groovy:11)
      	at bug.run(bug.groovy:22)
      

      It happens, because inside the overriden method it tries to access locally defined t. I have translated the same code to Java (see the gist) and it works as expected.

      Attachments

        Activity

          People

            emilles Eric Milles
            roman.saveljev Roman Saveljev
            Votes:
            0 Vote for this issue
            Watchers:
            1 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 - 0.5h
                0.5h