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

groovy.lang.MetaClassRegistry$MetaClassCreationHandle.create() causing java.lang.StackOverflowError

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Critical
    • Resolution: Fixed
    • 1.1-rc-1
    • 1.1-rc-3
    • groovy-jdk
    • None
    • Windows XP
      Eclipse Europa 3.3 & command line groovy

      D:\Profiles\Adam\Desktop\Delegate Test>groovy -v
      Groovy Version: 1.1-rc-1 JVM: 1.6.0_03-b05

    Description

      I was attempting to create a custom delegate class for a third party library. Researching this, I found the following page:
      http://docs.codehaus.org/display/GROOVY/Using+the+Delegating+Meta+Class

      When I tried to follow the "Package Name Convention Solution", by creating a FuzzyVariableMetaClass file in groovy.runtime.metaclass.ncr.fuzzyj.FuzzyVariableMetaClass, I got a java.lang.StackOverflowError. This was with no inherited methods. I only created the shell of the class and constructor.

      As a test, I followed the instructions on the page, creating a StringMetaClass as documented on the page. This also gave me the java.lang.StackOverflowError. When I ran this in the Eclipse debugger, the problem appears to occur during the groovy.lang.MetaClassRegistry$MetaClassCreationHandle.create(Class theClass, MetaClassRegistry registry) call.

      Specifically, this method does the following
      --------------------
      final Class customMetaClass = Class.forName("groovy.runtime.metaclass." + theClass.getName() + "MetaClass");
      final Constructor customMetaClassConstructor = customMetaClass.getConstructor(new Class[]

      {MetaClassRegistry.class, Class.class}

      );
      return (MetaClass)customMetaClassConstructor.newInstance(new Object[]

      {registry, theClass}

      );
      ---------------------
      This calls the constructor on the new MetaClass we are creating, which calls DelegateMetaClass's constructor, which calls GroovySystem.getMetaClassRegistry().getMetaClass(...), which calls getMetaClassFor(theClass), which calls metaClassCreationHandle.create(theClass, this), completing the infinite loop.

      I have NOT tested this under Groovy 1.0. But I imagine it worked then since the webpage has not been updated since Jan 28, 2007.

      ------------------------
      I also ran into issues when I tried the "InvokeHelper Solution " on the same page. Those errors were different and will be entered as a separate bug.

      Attachments

        1. StringMetaClass.groovy
          0.4 kB
          Adam Rinehart
        2. DelegatingMetaClassPackageImpliedTest.groovy
          0.2 kB
          Adam Rinehart

        Activity

          People

            Unassigned Unassigned
            johannz Adam Rinehart
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: