[jira] [Created] (GROOVY-8889) @NamedParam(required=true) is not enforced

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

[jira] [Created] (GROOVY-8889) @NamedParam(required=true) is not enforced

JIRA jira@apache.org
Vladimír Oraný created GROOVY-8889:
--------------------------------------

             Summary: @NamedParam(required=true) is not enforced
                 Key: GROOVY-8889
                 URL: https://issues.apache.org/jira/browse/GROOVY-8889
             Project: Groovy
          Issue Type: Bug
    Affects Versions: 2.5.4
            Reporter: Vladimír Oraný


in following snipped the required parameter is not enforced at all:


{code}
import groovy.transform.CompileStatic
import groovy.transform.NamedParam
import groovy.transform.NamedParams

@CompileStatic
class Tester {
    String text
    String color

    static Tester note(String text, String color) {
        return new Tester(text: text, color: color)
    }
}

@CompileStatic
class TesterBuilder {
    static Tester note(
            @NamedParams([
                    @NamedParam(value = 'text', type = String, required = true),
                    @NamedParam(value = 'color', type = String)
            ])
            Map<String, String> params
    ) {
        return Tester.note(params.text, params.color)
    }
}


@CompileStatic
Tester useBuilder() {
    return TesterBuilder.note(color: 'blue')
}

useBuilder()
{code}



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