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

NPE in property access in anonymous inner classes

Attach filesAttach ScreenshotVotersWatch issueWatchersCreate sub-taskLinkCloneUpdate Comment AuthorReplace String in CommentUpdate Comment VisibilityDelete Comments
    XMLWordPrintableJSON

Details

    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)
      

      Attachments

        Activity

          This comment will be Viewable by All Users Viewable by All Users
          Cancel

          People

            melix Cédric Champeau
            roshandawrani Roshan Dawrani
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Slack

                Issue deployment