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

Access an element in a Map

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Won't Fix
    • None
    • 1.1-beta-1
    • syntax
    • None
    • Windows XP SP2, JDK 6.0 Final, PC Pentium 4, 3Ghz

    Description

      Groovy allow to access an element in a Map via dot operator like this:

      aMap.aKey

      which should return a Element that associates with the above aKey

      However it only works with aKey as a object (including String object). So Grooy parser fails to run the below code

      class EmptyClass {

      }

      anObject = new EmptyClass();
      x = [1:"Hello", 2:"Hello 2", "name":"pcdinh", "1":"pcdinh1", "2":anObject, anObject:"2"];
      println x.1; // It fails
      println x."2"; // It works
      println x.aGTest; // It works

      The exception is thrown as follows:

      Exception thrown: org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed,

      org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed,
      at org.codehaus.groovy.control.ErrorCollector.failIfErrors(ErrorCollector.java:326)
      at org.codehaus.groovy.control.ErrorCollector.addFatalError(ErrorCollector.java:173)
      at org.codehaus.groovy.control.ErrorCollector.addError(ErrorCollector.java:143)
      at org.codehaus.groovy.control.ErrorCollector.addError(ErrorCollector.java:155)
      at org.codehaus.groovy.control.SourceUnit.addError(SourceUnit.java:382)
      at org.codehaus.groovy.antlr.AntlrParserPlugin.parseCST(AntlrParserPlugin.java:87)
      at org.codehaus.groovy.control.SourceUnit.parse(SourceUnit.java:279)
      at org.codehaus.groovy.control.CompilationUnit$1.call(CompilationUnit.java:184)
      at org.codehaus.groovy.control.CompilationUnit.applyToSourceUnits(CompilationUnit.java:833)
      at org.codehaus.groovy.control.CompilationUnit.compile(CompilationUnit.java:480)
      at groovy.lang.GroovyClassLoader.parseClass(GroovyClassLoader.java:306)
      at groovy.lang.GroovyShell.parseClass(GroovyShell.java:513)
      at groovy.lang.GroovyShell.parse(GroovyShell.java:525)
      at groovy.lang.GroovyShell.parse(GroovyShell.java:505)
      at groovy.lang.GroovyShell.evaluate(GroovyShell.java:483)
      at groovy.lang.GroovyShell.evaluate(GroovyShell.java:425)
      at gjdk.groovy.lang.GroovyShell_GroovyReflector.invoke(Unknown Source)
      at groovy.lang.MetaMethod.invoke(MetaMethod.java:115)
      at org.codehaus.groovy.runtime.MetaClassHelper.doMethodInvoke(MetaClassHelper.java:713)
      at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:561)
      at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:460)
      at org.codehaus.groovy.runtime.Invoker.invokeMethod(Invoker.java:131)
      at org.codehaus.groovy.runtime.InvokerHelper.invokeMethod(InvokerHelper.java:111)
      at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.invokeMethodN(ScriptBytecodeAdapter.java:187)
      at groovy.ui.Console$_runScript_closure10.doCall(Console.groovy:503)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
      at java.lang.reflect.Method.invoke(Method.java:597)
      at org.codehaus.groovy.runtime.ReflectionMetaMethod.invoke(ReflectionMetaMethod.java:69)
      at org.codehaus.groovy.runtime.MetaClassHelper.doMethodInvoke(MetaClassHelper.java:713)
      at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:561)
      at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.invokeMethodOnCurrentN(ScriptBytecodeAdapter.java:97)
      at groovy.ui.Console$_runScript_closure10.doCall(Console.groovy)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
      at java.lang.reflect.Method.invoke(Method.java:597)
      at org.codehaus.groovy.runtime.ReflectionMetaMethod.invoke(ReflectionMetaMethod.java:69)
      at org.codehaus.groovy.runtime.MetaClassHelper.doMethodInvoke(MetaClassHelper.java:713)
      at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:561)
      at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:460)
      at groovy.lang.Closure.call(Closure.java:186)
      at groovy.lang.Closure.call(Closure.java:181)
      at groovy.lang.Closure.run(Closure.java:262)
      at java.lang.Thread.run(Thread.java:619)

      It think that the exception is developer-unfriendly. It shows no clue about the errors and how developers should correct his code. It should be improved

      Attachments

        Activity

          People

            blackdrag Jochen Theodorou
            pcdinh Dinh Pham
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: