[ https://issues.apache.org/jira/browse/GROOVY-6567?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Paul King closed GROOVY-6567. ----------------------------- > delegate is NullObject instance for closure metamethods invoked on null > ----------------------------------------------------------------------- > > Key: GROOVY-6567 > URL: https://issues.apache.org/jira/browse/GROOVY-6567 > Project: Groovy > Issue Type: Bug > Affects Versions: 2.4.0-rc-1 > Reporter: Lari Hotari > Assignee: Eric Milles > Priority: Major > Fix For: 5.0.0-alpha-3 > > > NullObject shouldn't be exposed outside groovy internals. > This code example shows when NullObject leaks to application code: > {code} > Object.metaClass.delegateClass = { > delegate?.getClass() > } > println null.delegateClass().name > {code} > This prints out "org.codehaus.groovy.runtime.NullObject". > ------- > possible solution: > I assume that NullObject should be "filtered" in [ClosureMetaMethod| > https://github.com/groovy/groovy-core/blob/master/src/main/org/codehaus/groovy/runtime/metaclass/ClosureMetaMethod.java#L77]. > {code} > public Object invoke(final Object object, Object[] arguments) { > Closure cloned = (Closure) callable.clone(); > cloned.setDelegate(object); > arguments = coerceArgumentsToClasses(arguments); > return doCall.invoke(cloned, arguments); > } > {code} > replacing "cloned.setDelegate(object)" with > {code} > cloned.setDelegate(!(object instanceof NullObject) ? object : null) > {code} > would prevent the leak of NullObject in ClosureMetaMethod class. -- This message was sent by Atlassian Jira (v8.20.10#820010)