You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@groovy.apache.org by "Jason Garrett (Jira)" <ji...@apache.org> on 2023/01/30 20:08:00 UTC

[jira] [Created] (GROOVY-10922) stack overflow calling implicit getter/setter from override

Jason Garrett created GROOVY-10922:
--------------------------------------

             Summary: stack overflow calling implicit getter/setter from override
                 Key: GROOVY-10922
                 URL: https://issues.apache.org/jira/browse/GROOVY-10922
             Project: Groovy
          Issue Type: Bug
          Components: Compiler
    Affects Versions: 2.5.21, 2.5.20, 3.0.14, 2.5.19
            Reporter: Jason Garrett


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.
{code:java}
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
   }
}
 {code}



--
This message was sent by Atlassian Jira
(v8.20.10#820010)