groovy
  1. groovy
  2. GROOVY-3305

Can't use list argument when The method's first argument class is int

    Details

    • Type: Bug Bug
    • Status: Closed Closed
    • Priority: Minor Minor
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 1.6.1, 1.5.8, 1.7-beta-1
    • Component/s: None
    • Labels:
      None
    • Environment:
      OS: WindowsXP, Java: 1.6.0_11, Groovy: 1.6-RC-1
    • Number of attachments :
      0

      Description

      When I run the following codes, I caught
      java.lang.ClassCastException: java.util.ArrayList cannot be cast to java.lang.Number
      at org.codehaus.groovy.reflection.stdclasses.IntegerCachedClass.coerceArgument(IntegerCachedClass.java:37)
      ...

      def foo(int arg0, String arg1, arg2){
          println arg0
          println arg1
          println arg2
      }
      foo([ 1, "B", 0.5 ])
      

      but I was able to run the next methods

      def foo(Number arg0, String arg1, int arg2){...}
      
      def foo(String arg0, int arg1, int arg2){...}
      

      I tried

        Number GOOD
        String GOOD
        char GOOD
        Object GOOD
        BigInteger GOOD
      
        int BAD
        BigDecimal BAD
        float BAD
        byte BAD
      

        Activity

        blackdrag blackdrag made changes -
        Field Original Value New Value
        Fix Version/s 1.6.1 [ 14852 ]
        Fix Version/s 1.5.8 [ 14630 ]
        Fix Version/s 1.7-beta-1 [ 14014 ]
        Paul King made changes -
        Description When I run the following codes, I caught
        java.lang.ClassCastException: java.util.ArrayList cannot be cast to java.lang.Number
        at org.codehaus.groovy.reflection.stdclasses.IntegerCachedClass.coerceArgument(IntegerCachedClass.java:37)
        ...

        def foo(int arg0, String arg1, arg2){
            println arg0
            println arg1
            println arg2
        }
        foo([ 1, "B", 0.5 ])

        but I was able to run the next methods

        def foo(Number arg0, String arg1, int arg2){...}

        def foo(String arg0, int arg1, int arg2){...}

        I tried
          Number GOOD
          String GOOD
          char GOOD
          Object GOOD
          BigInteger GOOD

          int BAD
          BigDecimal BAD
          float BAD
          byte BAD
        When I run the following codes, I caught
        java.lang.ClassCastException: java.util.ArrayList cannot be cast to java.lang.Number
        at org.codehaus.groovy.reflection.stdclasses.IntegerCachedClass.coerceArgument(IntegerCachedClass.java:37)
        ...
        {code}
        def foo(int arg0, String arg1, arg2){
            println arg0
            println arg1
            println arg2
        }
        foo([ 1, "B", 0.5 ])
        {code}

        but I was able to run the next methods

        {code}
        def foo(Number arg0, String arg1, int arg2){...}

        def foo(String arg0, int arg1, int arg2){...}
        {code}

        I tried
        {noformat}
          Number GOOD
          String GOOD
          char GOOD
          Object GOOD
          BigInteger GOOD

          int BAD
          BigDecimal BAD
          float BAD
          byte BAD
        {noformat}
        Roshan Dawrani made changes -
        Assignee Roshan Dawrani [ roshandawrani ]
        Roshan Dawrani made changes -
        Resolution Fixed [ 1 ]
        Status Open [ 1 ] Resolved [ 5 ]
        Paul King made changes -
        Status Resolved [ 5 ] Closed [ 6 ]

          People

          • Assignee:
            Roshan Dawrani
            Reporter:
            Takashi Mitsubuchi
          • Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: