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

This reference is null during construction of object of abstract class implemented as closure map

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Minor
    • Resolution: Fixed
    • 1.8.6
    • 2.0-beta-3
    • None
    • None

    Description

      The following code produces NPE when the second object is created:

      abstract class C {
          public abstract String f(Object o);
      
          private void g(Object val) { 
              println f(val) // NPE when 'y' is created !!!
          }
      
          public C() {this('DEF')}
      
          public C(Object val) { g(val) }
      }
      
      class D extends C {
          public String f(Object o) { return o ? 'Not null' : 'Is null' }
      }
      
      def x = new D()
      
      def y = [ 'f' : { it -> return '123' + it } ] as C
      

      Somehow 'this' becomes null when 'f' is invoked in 'g'.

      Attachments

        Activity

          People

            melix Cédric Champeau
            almo Alexander Monakhov
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: