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

super.setMetaClass() generates StackOverflowError when there is no base class

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 1.8.2
    • 2.0-beta-3
    • None

    Description

      The following code will generate a StackOverflowError. It seems "setMetaClass(MetaClass)" is called recursivly, although "super.setMetaClass(MetaClass)" is used. Note that this problem only occures when "Test" has no base class.

      class Test {
          void setMetaClass(MetaClass metaClass) {
              super.setMetaClass(metaClass)
          }
      }
      
      def obj = new Test()
      obj.metaClass = obj.metaClass
      

      On the other hand, the following code works just fine:

      class Base {}
      
      class Test extends Base {
          void setMetaClass(MetaClass metaClass) {
              super.setMetaClass(metaClass)
          }
      }
      
      def obj = new Test()
      obj.metaClass = obj.metaClass
      

      Attachments

        Activity

          People

            melix Cédric Champeau
            hojerst Stefan Hojer
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: