groovy-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Jacek Karas (JIRA)" <>
Subject [jira] [Created] (GROOVY-7861) asType(null) called in @CompileStatic method returns a string 'null'
Date Mon, 13 Jun 2016 20:58:11 GMT
Jacek Karas created GROOVY-7861:

             Summary: asType(null) called in @CompileStatic method returns a string 'null'
                 Key: GROOVY-7861
             Project: Groovy
          Issue Type: Bug
          Components: Static compilation
    Affects Versions: 2.4.7
         Environment: Win, jdk1.7.79
            Reporter: Jacek Karas
            Priority: Minor

The following code:
import groovy.transform.CompileStatic
class Test {
    static Object castToType(Object o, Class clazz) { 
        return o.asType(clazz)
def foo = Test.castToType(null, String.class)
println "'${foo}' class: ${foo.getClass()} bytes: ${foo?.getBytes()}"

'null' class: class java.lang.String bytes: [110, 117, 108, 108]
i.e. the method annotated with @CompileStatic converts null to the actual string 'null' (which
is quite a nasty surprise when trying to "speed things up" by adding @CompileStatic to existing
non-static code).

The same without @CompileStatic returns:
'null' class: class org.codehaus.groovy.runtime.NullObject bytes: null
as expected.

This message was sent by Atlassian JIRA

View raw message