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

GString usage with Java Integration causes calsscasstexception if we cast returned string in java code

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Won't Fix
    • 1.5.1
    • 1.5.1
    • None
    • None

    Description

      I am using groovy with java. When i used GString in groovy and returned GString to java code or passed this string in a collection and returned this collection to java, this GString passes as GString object instead of String object. This sometimes causes some problems in Java if casting to String is used in Java. Can you convert GString values to real String while returning them back to Java?

      A sample usage resulting calsscastexception can be as:

      Assume that I want to execute following groovy code from java

      Groovy Code
      def name = "Mustafa";
      def listOfProperties = [];
      listOfProperties += "My name is ${name}";
      return listOfProperties;
      

      In java i use this list as

      Java Code
      List properties = //get returned properties from groovy
      for (Iterator iterator = properties.iterator(); iterator.hasNext();)
      {
            String prop = (String) iterator.next();            
            .
            .
           .
      }
      

      Above code will throw ClassCastException.

      Attachments

        Activity

          People

            blackdrag Jochen Theodorou
            enguzekli enguzekli
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: