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

Calling a method with a null argument's value when the parameter is an array

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 2.0-beta-1
    • 2.0-beta-2
    • Static Type Checker
    • None

    Description

      STC Error when calling a method with an argument of null when the parameter is an array

      Null parameter with array argument
      import groovy.transform.*
      
      @TypeChecked 
      class Foo {
          def say() {
              methodWithArrayParam(null) // STC Error
          }
          def methodWithArrayParam(String[] s) {
              
          }
      }
      
      

      Other cases tested too:

      Simple method call with null argument
      class Foo {
          def say() {
              methodWithArrayParam(null)
          }
      
          def methodWithArrayParam(Date date) {
      
          }
      }
      
      Multiple parameters where one of them is null
      class Foo {
          def say() {
              methodWithArrayParam(null, new Date())
          }
          def methodWithArrayParam(Date date1, Date date2) {
      
          }
      }
      
      Ambiguous method call due to null parameters
      class Foo {
          def say() {
              methodWithArrayParam(null, new Date())
          }
          def methodWithArrayParam(Date date1, Date date2) {
      
          }
          def methodWithArrayParam(String o, Date date2) {
      
          }
      }
      
      Disambiguated method call
      class Foo {
          def say() {
              methodWithArrayParam((Date)null, new Date())
          }
          def methodWithArrayParam(Date date1, Date date2) {
      
          }
          def methodWithArrayParam(String o, Date date2) {
      
          }
      }
      

      Attachments

        Activity

          People

            melix Cédric Champeau
            vns Valery Shyshkin
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: