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

lazyClassInit is called on proxy ClassNodes

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 1.6-beta-1, 1.5.7, 1.6-beta-2, 1.6-rc-1, 1.6-rc-2, 1.6-rc-3, 1.6
    • 1.6.1, 1.5.8, 1.7-beta-1
    • None
    • None

    Description

      import org.codehaus.groovy.ast.*
      
      def script = """
      class ClassNodeMethodsListGrowth {
          // Setting the type to ArrayList triggers a growth in methodsList
          ArrayList array1=new ArrayList()
      
          // ... using dynamic typing does not
          // def array2=new ArrayList()
          
          // Test method as a sanity check
          def get(o) { return "ok" }
      } 
      """
      listType = ClassHelper.make(List.class);
      5.times {
        def loader = new GroovyClassLoader(this.class.classLoader)
        assert loader.parseClass(script).newInstance().get("default")=="ok"
        println listType.redirect().getMethods().size()
      }
      

      This code reports a growth in size for the cached ClassNode for List.class. The reasons is that a proxy ClassNode which redirects to this node gets its lazyClassInit method called on itself, but it will then add methods to the proxied node. lazyClassInit must not be called if redirect is not null, because that means we don't want to add methods on this node, but on the other, which we redirect to.

      Attachments

        Activity

          People

            blackdrag Jochen Theodorou
            blackdrag Jochen Theodorou
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: