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

Access to a private property of a parent object is not caught

    XMLWordPrintableJSON

Details

    Description

      I have the following ill-typed program

      class A {
        private int getX() {
          return 1;
        }
      }
      
      class B extends A {
        void test() {
          def y = super.x;
          System.out.println(y);
        }
      }
      
      public class Test {
          public static void main(String[] args) {
            new B().test();
          }
      }
      

      Actual behavior

      The program compiles. When I run it, I receive:

      Exception in thread "main" groovy.lang.MissingPropertyException: No such property: x for class: B
              at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.unwrap(ScriptBytecodeAdapter.java:68)
              at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.getPropertyOnSuper(ScriptBytecodeAdapter.java:426)
              at B.test(test.groovy:9)
              at Test.main(test.groovy:16)
      

      Expected behavior

      The problem is on line 9, when the program accesses the private property x of the parent object.

      Tested against master (commit: e17149013c5943ad3493f9597e6720eb6529d120)

      Attachments

        Issue Links

          Activity

            People

              emilles Eric Milles
              theosot Thodoris Sotiropoulos
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: