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
-
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.