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

stack overflow calling implicit getter/setter from override

    XMLWordPrintableJSON

Details

    Description

      In the following situation, under static compilation:

      • An interface declares a getter and/or setter
      • An implementing class declares a property of the corresponding name and type, so the implicit getter and/or setter implement the interface
      • A subclass overrides the getter/setter and calls the super getter/setter

      the subclass getter/setter will recurse instead of calling the superclass implicit method.

      This appears to have been introduced in 3.0.14.

      Running the main method in this example will reproduce the stack overflow.

      package example
      
      import groovy.transform.CompileStatic
      
      @CompileStatic
      class SuperImplicitSetter {
         interface FooHaving {
            String getFoo()
            void setFoo(String foo)
         }
      
         static class Foo implements FooHaving {
            String foo  // implements interface
         }
      
         static class Bar extends Foo {
            String bar
      
            @Override
            void setFoo(String foo) {
               super.setFoo(foo)  // recurses instead of calling implicit Foo.setFoo(String)
               bar = foo
            }
         }
      
         static void main(String[] args) {
            Bar bar = new Bar()
            bar.setFoo("bar")  // stack overflow
            println bar.foo
         }
      }
       

      Attachments

        Activity

          People

            emilles Eric Milles
            jasongarrett Jason Garrett
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: