groovy
  1. groovy
  2. GROOVY-4471

NPE in property access in anonymous inner classes

    Details

    • Testcase included:
      yes
    • Number of attachments :
      0

      Description

      class X {
          private A a = new A()
          public B b
          public X() {
              b = new B() {
                  public String getFoo() {a}
              }
          }
      }
      
      class A {}
      class B {
          B(){getFoo()}
          def getFoo(){}
      }
      
      def x = new X()
      

      The code above fails with

      Caught: java.lang.NullPointerException
      	at X$1.propertyMissing(TryGroovy.groovy)
      	at X$1.getFoo(TryGroovy.groovy:6)
      	at X$1.getFoo(TryGroovy.groovy)
      	at B.<init>(TryGroovy.groovy:13)
      	at X$1.<init>(TryGroovy.groovy)
      	at X.<init>(TryGroovy.groovy:5)
      	at TryGroovy.run(TryGroovy.groovy:16)
      

        Activity

        CÚdric Champeau made changes -
        Field Original Value New Value
        Assignee Jochen Theodorou [ blackdrag ] Cedric Champeau [ melix ]
        Hide
        CÚdric Champeau added a comment -

        Fixed in master and 1.8.x branch. However, I'm not closing it since backporting to 1.7.x is still under discussion.

        Show
        CÚdric Champeau added a comment - Fixed in master and 1.8.x branch. However, I'm not closing it since backporting to 1.7.x is still under discussion.
        CÚdric Champeau made changes -
        Status Open [ 1 ] Resolved [ 5 ]
        Fix Version/s 1.7.11 [ 17244 ]
        Fix Version/s 1.8.4 [ 17852 ]
        Fix Version/s 1.9-beta-4 [ 17656 ]
        Resolution Fixed [ 1 ]
        Paul King made changes -
        Status Resolved [ 5 ] Closed [ 6 ]

          People

          • Assignee:
            CÚdric Champeau
            Reporter:
            Roshan Dawrani
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: