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

MissingPropertyException for access to private static field from inner class when subclassing

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 2.5.10
    • 4.0.0-alpha-1, 3.0.4, 2.5.12
    • None
    • None

    Description

      Consider the following:

      class Main extends Outer {
        static main(args) {
          newInstance().newThread()
        }
      }
      
      abstract class Outer {
        private static volatile boolean flag
      
        protected void newThread() {
          Thread thread = new Inner()
          thread.start()
          thread.join()
        }
      
        private final class Inner extends Thread {
          void run() {
           try {
            if (!flag) {
              sleep(1000)
            }
           } catch (Throwable t) {
            t.printStackTrace()
           }
          }
        }
      }
      

      In this example, Main extends Outer and is the type that is instantiated and used. Inner makes reference to private static field flag of Outer. When Inner is non-static as in this example, it gets the following error when reading "flag":

      groovy.lang.MissingPropertyException: No such property: flag for class: Main
      Possible solutions: class
      	at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.unwrap(ScriptBytecodeAdapter.java:65)
      	at org.codehaus.groovy.runtime.callsite.GetEffectivePogoPropertySite.getProperty(GetEffectivePogoPropertySite.java:87)
      	at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callGroovyObjectGetProperty(AbstractCallSite.java:309)
      	at Outer$Inner.run(Script1.groovy:20)
      

      Note: changing Inner from final to static fixes this specific case. However, non-static inners that need to be that way are going to have this problem.

      This is possibly related to: GROOVY-8999, et al.

      Attachments

        Activity

          People

            emilles Eric Milles
            emilles Eric Milles
            Votes:
            0 Vote for this issue
            Watchers:
            2 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 - 20m
                20m