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

Eric Milles commented on GROOVY-6154:
-------------------------------------

In order to support "def o = null; o.getAge()" you need to add an overload for 
{{NullObject}}.
{code:java}
import org.codehaus.groovy.runtime.NullObject;
class Extension {
  public static int getAge(Object o) { return 15; }
  public static int getAge(NullObject o) { return 15; }
}
{code}

> Property added as getProperty() extension method for every object isn't 
> accessible for NullObject
> -------------------------------------------------------------------------------------------------
>
>                 Key: GROOVY-6154
>                 URL: https://issues.apache.org/jira/browse/GROOVY-6154
>             Project: Groovy
>          Issue Type: Bug
>          Components: groovy-runtime
>            Reporter: Mykola Golubyev
>            Priority: Major
>
> When you add an extension method using 
> org.codehaus.groovy.runtime.ExtensionModule
>     static int getAge(Object o) { return 15; }
> you can call the method using Groovy property shortcut like
>    def value = 1
>    assert value.age == 15
>    assert value.getAge() == 15
> however when value is null Groovy property shortcut doesn't work 
> but getAge() method still works as expected
>    def value = null
>    assert value.age == 15 // Cannot get property 'age' on null object
>    assert value.getAge() == 15



--
This message was sent by Atlassian Jira
(v8.20.1#820001)

Reply via email to