Uploaded image for project: 'Groovy'
  1. Groovy
  2. GROOVY-8889

@NamedParam(required=true) is not enforced

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Not A Problem
    • 2.5.4
    • None
    • None
    • None

    Description

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

      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()
      

      Attachments

        Activity

          People

            Unassigned Unassigned
            musketyr VladimĂ­r OranĂ˝
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: