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

compare operators throws comparing a Long type to a numeric String

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Critical
    • Resolution: Won't Fix
    • 1.0-RC-1
    • 1.1-rc-3
    • groovy-jdk
    • None
    • Java / WindowsXP

    Description

      Comparing a value 60 of type Long with a value 4 of type String throws a ClassCastException.
      Stack Trace:
      60
      4.0
      Exception in thread "main" java.lang.ClassCastException: java.lang.String
      at java.lang.Long.compareTo(Long.java:34)
      at org.codehaus.groovy.runtime.typehandling.DefaultTypeTransformation.compareTo(DefaultTypeTransformation.java:481)
      at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.compareTo(ScriptBytecodeAdapter.java:732)
      at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.compareGreaterThan(ScriptBytecodeAdapter.java:750)
      at Script1.run(Script1.groovy:1)
      at groovy.lang.GroovyShell.evaluate(GroovyShell.java:484)
      at groovy.lang.GroovyShell.evaluate(GroovyShell.java:459)
      at groovyprj.TestEmbeddedGroovy.main(TestEmbeddedGroovy.java:29)

      The code to reproduce (using embedded groovy)
      //call groovy expressions from Java code
      Binding binding = new Binding() {

      public Object getVariable(String key) {
      if (key.equals("lValue"))

      { return new Long(60); }

      if (key.equals("rValue"))

      { return "4.0"; }

      return super.getVariable(key);
      }
      };

      GroovyShell shell = new GroovyShell(binding);
      String expr = "println lValue; println rValue; println lValue > rValue; return lValue+rValue";

      Object value = shell.evaluate(expr);
      System.out.println(value);

      Attachments

        Activity

          People

            Unassigned Unassigned
            svinayak S Vinayaka
            Votes:
            1 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: