groovy
  1. groovy
  2. GROOVY-543

Incorrect exception MissingMethodException when closure references an uninitialized variable

    Details

    • Type: Bug Bug
    • Status: Closed Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 1.0-beta-5
    • Fix Version/s: 1.0-JSR-1
    • Component/s: None
    • Labels:
      None
    • Environment:
      Intel based Linux, java version "1.4.1_05"
    • Number of attachments :
      0

      Description

      The enclosed simple program demostrates the problem:
      #!/usr/bin/env groov

      def process( root, group, item ) {
      g = [root, group, item];
      g.sort

      { a, b | b < c }

      }

      if (args.size() < 3) {
      println "3 args please";
      } else {
      args[2..args.size()-1].each

      { process(args[0], args[1], it) }

      }

      When run with more than 3 arguments, this traceback is reported when the actual error is the reference to the uninitialized variable "c" in the sort closure.

      102 9:37am mhusby@gallium ~/groovy > ./junk.groovy 9 2 3
      Caught: groovy.lang.MissingMethodException: No signature of method junk$1.process() is applicable for argument types: (java.lang.String, java.lang.String, java.lang.String) values: [9, 2, 3]
      groovy.lang.MissingMethodException: No signature of method junk$1.process() is applicable for argument types: (java.lang.String, java.lang.String, java.lang.String) values: [9, 2, 3]
      at groovy.lang.MetaClass.invokeMethod(MetaClass.java:317)
      at groovy.lang.MetaClass.invokeMethod(MetaClass.java:291)
      at groovy.lang.Closure.doInvokeMethod(Closure.java:90)
      at groovy.lang.Closure.invokeMethod(Closure.java:75)
      at org.codehaus.groovy.runtime.Invoker.invokeMethod(Invoker.java:126)
      at org.codehaus.groovy.runtime.InvokerHelper.invokeMethod(InvokerHelper.java:106)
      at junk$1.doCall(junk.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:324)
      at org.codehaus.groovy.runtime.ReflectionMetaMethod.invoke(ReflectionMetaMethod.java:63)
      at groovy.lang.Closure.call(Closure.java:208)
      at org.codehaus.groovy.runtime.DefaultGroovyMethods.each(DefaultGroovyMethods.java:304)
      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:324)
      at org.codehaus.groovy.runtime.ReflectionMetaMethod.invoke(ReflectionMetaMethod.java:63)
      at org.codehaus.groovy.runtime.NewInstanceMetaMethod.invoke(NewInstanceMetaMethod.java:99)
      at groovy.lang.MetaClass.doMethodInvoke(MetaClass.java:1020)
      at groovy.lang.MetaClass.invokeMethod(MetaClass.java:314)
      at org.codehaus.groovy.runtime.Invoker.invokeMethod(Invoker.java:139)
      at org.codehaus.groovy.runtime.InvokerHelper.invokeMethod(InvokerHelper.java:106)
      at junk.run(junk.groovy:12)
      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:324)
      at org.codehaus.groovy.runtime.ReflectionMetaMethod.invoke(ReflectionMetaMethod.java:63)
      at groovy.lang.MetaClass.doMethodInvoke(MetaClass.java:1020)
      at groovy.lang.MetaClass.invokeMethod(MetaClass.java:314)
      at groovy.lang.MetaClass.invokeMethod(MetaClass.java:291)
      at groovy.lang.GroovyObjectSupport.invokeMethod(GroovyObjectSupport.java:73)
      at org.codehaus.groovy.runtime.Invoker.invokeMethod(Invoker.java:126)
      at org.codehaus.groovy.runtime.InvokerHelper.invokeMethod(InvokerHelper.java:106)
      at org.codehaus.groovy.runtime.InvokerHelper.runScript(InvokerHelper.java:374)
      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:324)
      at org.codehaus.groovy.runtime.ReflectionMetaMethod.invoke(ReflectionMetaMethod.java:63)
      at groovy.lang.MetaClass.doMethodInvoke(MetaClass.java:1020)
      at groovy.lang.MetaClass.invokeStaticMethod(MetaClass.java:375)
      at org.codehaus.groovy.runtime.Invoker.invokeMethod(Invoker.java:133)
      at org.codehaus.groovy.runtime.InvokerHelper.invokeMethod(InvokerHelper.java:106)
      at junk.main(junk.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:324)
      at org.codehaus.groovy.runtime.ReflectionMetaMethod.invoke(ReflectionMetaMethod.java:63)
      at groovy.lang.MetaClass.doMethodInvoke(MetaClass.java:1020)
      at groovy.lang.MetaClass.invokeStaticMethod(MetaClass.java:375)
      at org.codehaus.groovy.runtime.Invoker.invokeMethod(Invoker.java:133)
      at org.codehaus.groovy.runtime.InvokerHelper.invokeMethod(InvokerHelper.java:106)
      at groovy.lang.GroovyShell.run(GroovyShell.java:222)
      at groovy.lang.GroovyShell.main(GroovyShell.java:92)
      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:324)
      at org.codehaus.classworlds.Launcher.launchStandard(Launcher.java:410)
      at org.codehaus.classworlds.Launcher.launch(Launcher.java:344)
      at org.codehaus.classworlds.Launcher.main(Launcher.java:474)

        Activity

        Hide
        blackdrag blackdrag added a comment -

        fixed due to better exception handling

        Show
        blackdrag blackdrag added a comment - fixed due to better exception handling

          People

          • Assignee:
            blackdrag blackdrag
            Reporter:
            Erik Husby
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: