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

Strings with $variable embedded are not of java.lang.String class

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Minor
    • Resolution: Won't Fix
    • 1.0-JSR-1
    • None
    • None
    • None

    Description

      int index = 1
      println "test.$index".getClass()

      Result is not java.lang.String as I would expect, but some kind of inner script class. In many cases it will not make any difference, as it will be automatically converted to string as needed, but at least in one place it DOES make a difference - when I try to use sql.dataSet(...).add(map). With string column 'NAME' I cannot do

      def map = [:]
      map.NAME = 'test.$index"
      sql.add(map)

      because sql dataset will try to set NAME to Object (like Script$1) instead of String field.

      While sql dataset could be possibly corrected for this special case, I have no doubts that other similar cases will appear on any api trying to find out argument types dynamically. If it is not possible to change for any reason, then in documentation it should be written with very big letters, that you should use "test.$index".toString() in case of any dynamic api.

      Attachments

        Issue Links

          Activity

            People

              guillaume Guillaume Sauthier
              abies Artur Biesiadowski
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: