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

Assigning with empty String as hash key (i.e. a['']=t) yields StringIndexOutOfBoundsException



    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 1.7.1
    • Fix Version/s: 1.7.2, 1.8-beta-1
    • Component/s: Groovlet / GSP
    • Labels:
    • Environment:
      SuSE Linux 10 / JDK 1.6 / Tomcat 6.0.20


      This is a bizarre one - and I can't always get it to replicate; but where it fails, it ALWAYS fails. (e.g. in my IDE, it works fine. In a standalone Tomcat instance, it reliably seems to bomb on two different machines - even though the IDE is using the exact same version of Tomcat. Seems OK when I run it on the command line - no failure.

      The line looks about like this :

      topics[id] = t
      where id.getClass() is java.lang.String and id==''
      t is a complex class, with various fields.
      i.e. topics[''] = t

      It's the '' that seems to throw it. (other assignments using non-empty strings work fine).

      At the bottom is the stack trace, with the topics['']=t line on the very bottom. (it goes down further, and I will gladly provide it if needed, but I don't think that part is probably useful).

      A few other bizarre details:

      1) after this error occurs (if I catch it and keep going) 'topics' will contain the key/value pair, but groovy will not be able to fetch them by key. However, by casting 'topics' as a map and going from java (or jsp) I can use topics.get("") to successfully retrieve the correct value.

      2) at this same point (after the error), java can see the entry by enumerating the values; but groovy cannot see the '' when it enumerates the keys (using keySet())

      My question is, regarding the below stack trace, why the hell is doing all this crap just to put a value into a hash? I count 15 stack frames, most of which involve groovy classes. Shouldn't it just be map.put(key,value) ???

      Whatever. It bombed.

      If I find out more, I'll post it here.

      [from catalina.out]:------------------------------------

      id is ''
      GroovyServlet Error: script: '/index.groovy': Script processing failed.String index out of range: -1java.lang.String.substring(String.java:1938)
      java.lang.StringIndexOutOfBoundsException: String index out of range: -1
      at java.lang.String.substring(String.java:1938)
      at java.lang.String.substring(String.java:1905)
      at org.codehaus.groovy.runtime.MetaClassHelper.capitalize(MetaClassHelper.java:453)
      at groovy.lang.MetaClassImpl.setProperty(MetaClassImpl.java:2312)
      at groovy.lang.MetaClassImpl.setProperty(MetaClassImpl.java:3306)
      at org.codehaus.groovy.runtime.InvokerHelper.setProperty(InvokerHelper.java:183)
      at org.codehaus.groovy.runtime.DefaultGroovyMethods.putAt(DefaultGroovyMethods.java:185)
      at org.codehaus.groovy.runtime.dgm$504.doMethodInvoke(Unknown Source)
      at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1058)
      at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:886)
      at org.codehaus.groovy.runtime.callsite.PojoMetaClassSite.call(PojoMetaClassSite.java:44)
      at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:40)
      at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:117)
      at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:129)
      at kb.TopList$_refresh_closure1.doCall(TopList.groovy:58)




            • Assignee:
              roshandawrani Roshan Dawrani
              mlzarathustra miles zarathustra
            • Votes:
              0 Vote for this issue
              0 Start watching this issue


              • Created: