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

Invalid this reference in nested class

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 2.4.15, 2.5.1
    • 3.0.0-rc-3, 2.5.19
    • None
    • None

    Description

      The following snippet throws an exception when trying to initialise the `y` attribute

      class Foo {
      
          static class Bar extends Closure {
      
              private int x
      
              private int y
      
              Bar(int a) {
                  super(null, null);
                  x = a
                  this.y = a 
              }
              
              public int getMaximumNumberOfParameters() {
                  throw new UnsupportedOperationException()
              }
      
              public Class[] getParameterTypes() {
                  throw new UnsupportedOperationException()
              }
      
              public Object call(final Object... args) {
                  throw new UnsupportedOperationException()
              }
      
              public Object call(final Object arguments) {
                  throw new UnsupportedOperationException()
              }
      
              public Object call() {
                  throw new UnsupportedOperationException()
              }
          }
      
          def doSomething() {
              new Bar(1)
          }
      }
      
      
      assert new Foo().doSomething() 
      

      Reported error:

      java.lang.NullPointerException
      	at Foo$Bar.<init>(ConsoleScript8:12)
      	at Foo.doSomething(ConsoleScript8:37)
      	at Foo$doSomething.call(Unknown Source)
      	at ConsoleScript8.run(ConsoleScript8:42)
      

      Attachments

        Activity

          People

            emilles Eric Milles
            pablo72 paolo di tommaso
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: