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

Passing a Double to a method expecting String causes a StackOverflowError

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Critical
    • Resolution: Fixed
    • None
    • 1.0-RC-1
    • None
    • None

    Description

      If I pass a Double object to a method that expects a String (see code
      example below), I get the following error (at runtime):

      Exception in thread "main" java.lang.StackOverflowError
      at java.lang.reflect.ReflectAccess.copyMethod(ReflectAccess.java:118)
      at sun.reflect.ReflectionFactory.copyMethod(ReflectionFactory.java:282)
      at java.lang.Class.copyMethods(Class.java:2689)
      at java.lang.Class.getDeclaredMethods(Class.java:1763)
      at groovy.lang.Closure$1.run(Closure.java:91)
      at java.security.AccessController.doPrivileged(Native Method)
      at groovy.lang.Closure.<init>(Closure.java:89)
      at org.codehaus.groovy.runtime.MethodClosure.<init>(MethodClosure.java:22)
      at groovy.lang.MetaClassImpl.getProperty(MetaClassImpl.java:684)
      at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:353)
      at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:301)
      at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:357)
      at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:301)

      This is bad, because it is impossible to determine exactly what is
      causing this problem based on the stacktrace and the compiler does not
      complain about the code either.

      The code I'm using:

      def statFile = new File("${tmpdir}/${dataFilename}-stat")
      statFile.withWriter { stat ->
      statistics.values.each

      { val -> stat.writeLine(val) }

      }

      Here val is a Double and stat.writeLine() expects a String.

      I would expect it to convert the Double to a String before passing it to the method.

      Hopefully this will be fixed by on going work to improve MetaClass and friends.

      Attachments

        Issue Links

          Activity

            People

              blackdrag Jochen Theodorou
              meling Hein Meling
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: