Details
-
Bug
-
Status: Closed
-
Major
-
Resolution: Fixed
-
2.4.0-rc-1
-
None
-
None
Description
NullObject shouldn't be exposed outside groovy internals.
This code example shows when NullObject leaks to application code:
Object.metaClass.delegateClass = { delegate?.getClass() } println null.delegateClass().name
This prints out "org.codehaus.groovy.runtime.NullObject".
-------
possible solution:
I assume that NullObject should be "filtered" in ClosureMetaMethod.
public Object invoke(final Object object, Object[] arguments) { Closure cloned = (Closure) callable.clone(); cloned.setDelegate(object); arguments = coerceArgumentsToClasses(arguments); return doCall.invoke(cloned, arguments); }
replacing "cloned.setDelegate(object)" with
cloned.setDelegate(!(object instanceof NullObject) ? object : null)
would prevent the leak of NullObject in ClosureMetaMethod class.
Attachments
Attachments
Issue Links
- relates to
-
GROOVY-11196 ambiguous method error for tap on null receiver
- Closed