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

Class Cast Exception when using Groovy 2.0 Indy="true" and using an integer with a double.

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 2.0.0
    • 2.0.1
    • groovy-jdk
    • groovy 2.0.x
      java version "1.7.0_04"
      Java(TM) SE Runtime Environment (build 1.7.0_04-b21)
      Java HotSpot(TM) 64-Bit Server VM (build 23.0-b21, mixed mode)
      Mac OS X 10.7.4

    Description

      The following code causes a Class Cast Exception.

      import java.awt.geom.Point2D;
      
      def width = 240.0
      def radius = width / 3.0
       
      new Point2D.Double(x: 0, y: radius * 2 / 4)
      
      Exception in thread "main" java.lang.ClassCastException: java.lang.Integer cannot be cast to java.math.BigInteger
      	at org.codehaus.groovy.runtime.dgm$364.invoke(Unknown Source)
      	at java.lang.invoke.MethodHandleImpl$GuardWithCatch.invoke_L2(MethodHandleImpl.java:1130)
      	at org.codehaus.groovy.vmplugin.v7.IndyInterface.selectMethod(IndyInterface.java:681)
      	at Main.run(Main.groovy:7)
      	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
      	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      	at java.lang.reflect.Method.invoke(Method.java:601)
      	at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:90)
      	at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:233)
      	at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1074)
      	at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:904)
      	at org.codehaus.groovy.runtime.InvokerHelper.invokePogoMethod(InvokerHelper.java:848)
      	at org.codehaus.groovy.runtime.InvokerHelper.invokeMethod(InvokerHelper.java:831)
      	at org.codehaus.groovy.runtime.InvokerHelper.runScript(InvokerHelper.java:407)
      	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
      	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      	at java.lang.reflect.Method.invoke(Method.java:601)
      	at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:90)
      	at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:233)
      	at groovy.lang.MetaClassImpl.invokeStaticMethod(MetaClassImpl.java:1307)
      	at groovy.lang.MetaClassImpl.invokeStaticMethod(MetaClassImpl.java:1293)
      	at java.lang.invoke.MethodHandleImpl$GuardWithCatch.invoke_L3(MethodHandleImpl.java:1138)
      	at org.codehaus.groovy.vmplugin.v7.IndyInterface.selectMethod(IndyInterface.java:681)
      	at Main.main(Main.groovy)
      

      If you change the Groovy code to:

      import java.awt.geom.Point2D;
      
      def width = 240.0
      def radius = width / 3.0
       
      new Point2D.Double(x: 0, y: radius * 2D / 4D)
      

      it works ok.

      Attachments

        1. Main.groovy
          0.1 kB
          Jim Clarke

        Activity

          People

            blackdrag Jochen Theodorou
            jimclarke5 Jim Clarke
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: