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

Stackoverflow error when calling super from overridden method

    XMLWordPrintableJSON

Details

    Description

      The following script throws Stackoverflow error when calling super.add(Object o) from overridden add(Object o) (it ends up calling itself). With @CompileDynamic on the overridden method the code works.

       

      import groovy.transform.CompileStatic
      @CompileStatic
      class MySet extends DirtyCheckingSet {
          MySet(Set delegate, DirtyCheckable entity, String propertyName) {
              super(delegate, entity, propertyName)
          }
          @Override
          boolean add(Object o) {
              def added = super.add(o) // <-- Offending command
              println "Added $o"
              return added
          }
      }
      @CompileStatic
      class MyEntity implements DirtyCheckable {
          String myProperty
      }
      @CompileStatic
      class DirtyCheckingSet extends DirtyCheckingCollection implements Set {
          DirtyCheckingSet(Set target, DirtyCheckable parent, String property) {
              super(target, parent, property)
          }
      }
      @CompileStatic
      trait DirtyCheckable {
          void markDirty(String propertyName) {
              println "$propertyName marked dirty"
          }
      }
      @CompileStatic
      class DirtyCheckingCollection implements Collection {
          
          final @Delegate Collection target
          final DirtyCheckable parent
          final String property
          
          DirtyCheckingCollection(Collection target, DirtyCheckable parent, String property) {
              this.target = target
              this.parent = parent
              this.property = property
          }
          @Override
          boolean add(Object o) {
              parent.markDirty(property)
              target.add(o)
          }
      }
      MySet set = new MySet([] as Set, new MyEntity([myProperty: 'hello']), 'myProperty')
      set.add('myProperty')
      

       

      Attachments

        Issue Links

          Activity

            People

              emilles Eric Milles
              matrei Mattias Reichel
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: