You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@groovy.apache.org by "Eric Milles (Jira)" <ji...@apache.org> on 2023/10/17 20:52:00 UTC

[jira] [Commented] (GROOVY-5909) NullObject is ignored by metaClass.getProperty and category, but works in methods

    [ https://issues.apache.org/jira/browse/GROOVY-5909?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17776386#comment-17776386 ] 

Eric Milles commented on GROOVY-5909:
-------------------------------------

It probably does not make sense to allow overriding methods on null, except for "toString()", "asBoolean()" and some other basic things.

> NullObject is ignored by metaClass.getProperty and category, but works in methods
> ---------------------------------------------------------------------------------
>
>                 Key: GROOVY-5909
>                 URL: https://issues.apache.org/jira/browse/GROOVY-5909
>             Project: Groovy
>          Issue Type: Bug
>          Components: groovy-runtime
>    Affects Versions: 2.0.5
>         Environment: Linux Ubuntu 12.04 32 bits
>            Reporter: Will P
>            Priority: Minor
>
> With the exception of methods, can't apply metaprogramming on top of NullObject:
> import org.codehaus.groovy.runtime.NullObject
> NullObject.metaClass.b = "b"
> assert NullObject.b == "b" // fails
> assert null.b == "b" // fails
> NullObject.metaClass.c = { "c" } 
> assert NullObject.c() == "c" // fails
> assert null.c() == "c" // pass
> NullObject.metaClass.getProperty = { String prop -> prop }
> assert null.a == "a" // fails
> class NullCategory {
>   static Object getProperty(NullObject n, String property) { property }
>   static Object d(NullObject n) { "d" }
> }
> use (NullCategory) {
>   assert null.d() == "d" // pass
>   assert null.e == "e" // fails
> }



--
This message was sent by Atlassian Jira
(v8.20.10#820010)