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

Incorrect exception MissingMethodException when closure references an uninitialized variable

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 1.0-beta-5
    • 1.0-JSR-1
    • None
    • None
    • Intel based Linux, java version "1.4.1_05"

    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)

      Attachments

        Activity

          People

            blackdrag Jochen Theodorou
            erikhusby Erik Husby
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: