Groovy
  1. Groovy
  2. GROOVY-5175

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

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 2.0-beta-1
    • Fix Version/s: 2.0-beta-2
    • Component/s: Static Type Checker
    • Labels:
      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) {
      
          }
      }
      

        Activity

        Valery Shyshkin created issue -
        Cédric Champeau made changes -
        Field Original Value New Value
        Assignee Cedric Champeau [ melix ]
        Cédric Champeau made changes -
        Affects Version/s 2.0-beta-2 [ 18072 ]
        Description STC Error when calling a method with an argument of null when the parameter is an array

        {code}
        import groovy.transform.*

        @TypeChecked
        class Foo {
            def say() {
                methodWithArrayParam(null) // STC Error
            }
            def methodWithArrayParam(String[] s) {
                
            }
        }

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

        {code}
        import groovy.transform.*

        @TypeChecked
        class Foo {
            def say() {
                methodWithArrayParam(null) // STC Error
            }
            def methodWithArrayParam(String[] s) {
                
            }
        }

        {code}

        Other cases tested too:

        {code:title=Simple method call with null argument}
        class Foo {
            def say() {
                methodWithArrayParam(null)
            }

            def methodWithArrayParam(Date date) {

            }
        }
        {code}

        {code:title=Multiple parameters where one of them is null}
        class Foo {
            def say() {
                methodWithArrayParam(null, new Date())
            }
            def methodWithArrayParam(Date date1, Date date2) {

            }
        }
        {code}

        {code:title=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) {

            }
        }
        {code}

        {code:Disambiguated method call}
        class Foo {
            def say() {
                methodWithArrayParam((Date)null, new Date())
            }
            def methodWithArrayParam(Date date1, Date date2) {

            }
            def methodWithArrayParam(String o, Date date2) {

            }
        }
        {code}
        Fix Version/s 2.0-beta-2 [ 18072 ]
        Hide
        Cédric Champeau added a comment -

        Fixed typo

        Show
        Cédric Champeau added a comment - Fixed typo
        Cédric Champeau made changes -
        Description STC Error when calling a method with an argument of null when the parameter is an array

        {code}
        import groovy.transform.*

        @TypeChecked
        class Foo {
            def say() {
                methodWithArrayParam(null) // STC Error
            }
            def methodWithArrayParam(String[] s) {
                
            }
        }

        {code}

        Other cases tested too:

        {code:title=Simple method call with null argument}
        class Foo {
            def say() {
                methodWithArrayParam(null)
            }

            def methodWithArrayParam(Date date) {

            }
        }
        {code}

        {code:title=Multiple parameters where one of them is null}
        class Foo {
            def say() {
                methodWithArrayParam(null, new Date())
            }
            def methodWithArrayParam(Date date1, Date date2) {

            }
        }
        {code}

        {code:title=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) {

            }
        }
        {code}

        {code:Disambiguated method call}
        class Foo {
            def say() {
                methodWithArrayParam((Date)null, new Date())
            }
            def methodWithArrayParam(Date date1, Date date2) {

            }
            def methodWithArrayParam(String o, Date date2) {

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

        {code:title=Null parameter with array argument}
        import groovy.transform.*

        @TypeChecked
        class Foo {
            def say() {
                methodWithArrayParam(null) // STC Error
            }
            def methodWithArrayParam(String[] s) {
                
            }
        }

        {code}

        Other cases tested too:

        {code:title=Simple method call with null argument}
        class Foo {
            def say() {
                methodWithArrayParam(null)
            }

            def methodWithArrayParam(Date date) {

            }
        }
        {code}

        {code:title=Multiple parameters where one of them is null}
        class Foo {
            def say() {
                methodWithArrayParam(null, new Date())
            }
            def methodWithArrayParam(Date date1, Date date2) {

            }
        }
        {code}

        {code:title=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) {

            }
        }
        {code}

        {code:title=Disambiguated method call}
        class Foo {
            def say() {
                methodWithArrayParam((Date)null, new Date())
            }
            def methodWithArrayParam(Date date1, Date date2) {

            }
            def methodWithArrayParam(String o, Date date2) {

            }
        }
        {code}
        Cédric Champeau made changes -
        Status Open [ 1 ] Resolved [ 5 ]
        Resolution Fixed [ 1 ]
        Paul King made changes -
        Status Resolved [ 5 ] Closed [ 6 ]
        Mark Thomas made changes -
        Project Import Sun Apr 05 13:32:57 UTC 2015 [ 1428240777691 ]
        Mark Thomas made changes -
        Workflow jira [ 12734099 ] Default workflow, editable Closed status [ 12745868 ]
        Mark Thomas made changes -
        Project Import Mon Apr 06 02:11:23 UTC 2015 [ 1428286283443 ]
        Mark Thomas made changes -
        Workflow jira [ 12973741 ] Default workflow, editable Closed status [ 12980909 ]
        Transition Time In Source Status Execution Times Last Executer Last Execution Date
        Open Open Resolved Resolved
        2h 51m 1 Cédric Champeau 08/Dec/11 08:58
        Resolved Resolved Closed Closed
        15d 18h 9m 1 Paul King 24/Dec/11 03:08

          People

          • Assignee:
            Cédric Champeau
            Reporter:
            Valery Shyshkin
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development