You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@groovy.apache.org by "Paul King (JIRA)" <ji...@apache.org> on 2018/01/20 21:45:00 UTC

[jira] [Updated] (GROOVY-8454) Method with wrong argument typed is called when passing 'null'

     [ https://issues.apache.org/jira/browse/GROOVY-8454?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Paul King updated GROOVY-8454:
------------------------------
    Description: 
The output of the following code is 'Map:  null' instead of 'String: null'
{code:java}
class Stat {
    def static m(String s) {
        println 'String: ' + s
    }

    def static m(Map m) {
        println 'Map: ' + m
    }
}

class Main {

    def run() {
        String n = null
        Stat.m(n)
    }

    def static void main(String ... args) {
        new Main().run()
    }
}
{code}
To get the correct output I must explicitly cast the null value to String.
{code:java}
Stat.m((String)n)
{code}

  was:
The output of the following code is 'Map:  null' instead of 'String: null'
{code:java}
def class Stat {

    def static m(String s) {
        println 'String: ' + s
    }

    def static m(Map m) {
        println 'Map: ' + m
    }

}

def class Main {

    def run() {
        String n = null
        Stat.m(n)
    }

    def static void main(String ... args) {
        new Main().run()
    }

{code}
To get the correct output I must explicitly cast the null value to String.
{code:java}
Stat.m((String)n){code}


> Method with wrong argument typed is called when passing 'null'
> --------------------------------------------------------------
>
>                 Key: GROOVY-8454
>                 URL: https://issues.apache.org/jira/browse/GROOVY-8454
>             Project: Groovy
>          Issue Type: Bug
>    Affects Versions: 2.4.3
>            Reporter: Marek Baluch
>            Priority: Major
>
> The output of the following code is 'Map:  null' instead of 'String: null'
> {code:java}
> class Stat {
>     def static m(String s) {
>         println 'String: ' + s
>     }
>     def static m(Map m) {
>         println 'Map: ' + m
>     }
> }
> class Main {
>     def run() {
>         String n = null
>         Stat.m(n)
>     }
>     def static void main(String ... args) {
>         new Main().run()
>     }
> }
> {code}
> To get the correct output I must explicitly cast the null value to String.
> {code:java}
> Stat.m((String)n)
> {code}



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)