You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@groovy.apache.org by "Jörg Prante (JIRA)" <ji...@apache.org> on 2016/07/13 16:33:20 UTC

[jira] [Created] (GROOVY-7885) referencing method in outer class from inner class throws Exception when using newInstance()

Jörg Prante created GROOVY-7885:
-----------------------------------

             Summary: referencing method in outer class from inner class throws Exception when using newInstance()
                 Key: GROOVY-7885
                 URL: https://issues.apache.org/jira/browse/GROOVY-7885
             Project: Groovy
          Issue Type: Bug
    Affects Versions: 2.4.6
            Reporter: Jörg Prante
            Priority: Minor


This code throws an error

class A {

   Object o

   A() {
     def b = B.newInstance()                   
     o = "Hello"
     b.execute()
   }

   Object val() {
       o
   }

   class B {
      void execute() {
         println val()
      }
   }
}

def a = new A()

groovy Test.groovy
Caught: java.lang.NullPointerException
java.lang.NullPointerException
	at A$B.methodMissing(Test.groovy)
	at A$B.execute(Test.groovy:18)
	at A$B$execute.call(Unknown Source)
	at A.<init>(Test.groovy:9)
	at Test.run(Test.groovy:24)

but this code works

class A {

   Object o

   A() {
     def b = new B()        
     o = "Hello"
     b.execute()
   }

   Object val() {
       o
   }

   class B {
      void execute() {
         println val()
      }
   }

}

def a = new A()

Is this expected?



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)