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

MissingPropertyEx when accessing private static field in closure of same class

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 4.0.13
    • 5.0.0-alpha-1, 4.0.22
    • groovy-runtime
    • None
    • Windows 10, Groovy 4.0.13, Java 17.0.8

    Description

      When accessing a private static final field from a Closure within the same class Groovy 4 throws a MissingPropertyException. The code works in Groovy 2.5.22 & 3.0.18.

      The real instance of the object needs to be a subtype of the class containing the constant.

      See attached code to reproduce.

      Expected behavior:
      The code runs without error

      Actual behavior:
      Groovy 4 throws:

      groovy.lang.MissingPropertyException: No such property: field for class: FirstEvent
          at BaseEvent$_init_closure1.doCall(Test.groovy:7)
          at BaseEvent.init(Test.groovy:7)
          at Test.run(Test.groovy:15)

      Notes:
      Interestingly if you remove the static keyword from private static final String field = "name"
      it fails in all three versions 2.5.22, 3.0.18 & 4.0.13 with a MissingPropertyException.
      I would expect that the code should also work for these cases.

       

      The problem came up in a discussion about a Spock issue #1544.

      Attachments

        1. Test.groovy
          0.3 kB
          Andreas Turban

        Issue Links

          Activity

            People

              emilles Eric Milles
              AndreasTu Andreas Turban
              Votes:
              1 Vote for this issue
              Watchers:
              5 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: