[ 
https://issues.apache.org/jira/browse/GROOVY-7885?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15375310#comment-15375310
 ] 

Jörg Prante commented on GROOVY-7885:
-------------------------------------

Here is the code again, but hopefully formatted. Sorry.

{code}
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()
{code}

and

{code}
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()
{code}


> 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)

Reply via email to