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

Cannot invoke method next() on varible, which is initialized by default, in each\eachWithIndex

    XMLWordPrintableJSON

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Minor
    • Resolution: Fixed
    • Affects Version/s: 2.1.3
    • Fix Version/s: 2.2.1
    • Component/s: primtive opts
    • Labels:
      None

      Description

      The following code throws java.lang.NullPointerException: Cannot invoke method next() on null object

      int x 
      [1..10].each{
      x++
      }
      

      Expected result:
      X should be increased in each step.

      Stacktrace for code:
      java.lang.NullPointerException: Cannot invoke method next() on null object

      at org.codehaus.groovy.runtime.NullObject.invokeMethod(NullObject.java:77)

      at org.codehaus.groovy.runtime.callsite.PogoMetaClassSite.call(PogoMetaClassSite.java:45)

      at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:45)

      at org.codehaus.groovy.runtime.callsite.NullCallSite.call(NullCallSite.java:32)

      at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:45)

      at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:108)

      at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:112)

      at ConsoleScript18$_run_closure1.doCall(ConsoleScript18:3)

      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.reflection.CachedMethod.invoke(CachedMethod.java:90)

      at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:233)

      at org.codehaus.groovy.runtime.metaclass.ClosureMetaClass.invokeMethod(ClosureMetaClass.java:272)

      at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:909)

      at groovy.lang.Closure.call(Closure.java:411)

      at groovy.lang.Closure.call(Closure.java:427)

      at org.codehaus.groovy.runtime.DefaultGroovyMethods.each(DefaultGroovyMethods.java:1325)

      at org.codehaus.groovy.runtime.DefaultGroovyMethods.each(DefaultGroovyMethods.java:1297)

      at org.codehaus.groovy.runtime.dgm$148.invoke(Unknown Source)

      at org.codehaus.groovy.runtime.callsite.PojoMetaMethodSite$PojoMetaMethodSiteNoUnwrapNoCoerce.invoke(PojoMetaMethodSite.java:271)

      at org.codehaus.groovy.runtime.callsite.PojoMetaMethodSite.call(PojoMetaMethodSite.java:53)

      at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:45)

      at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:108)

      at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:116)

      at ConsoleScript18.run(ConsoleScript18:2)

      at groovy.lang.GroovyShell.runScriptOrMainOrTestOrRunnable(GroovyShell.java:257)

      at groovy.lang.GroovyShell.run(GroovyShell.java:481)

      at groovy.lang.GroovyShell.run(GroovyShell.java:163)

      at groovy.lang.GroovyShell$run.call(Unknown Source)

      at groovy.ui.Console$_runScriptImpl_closure17.doCall(Console.groovy:951)

      at groovy.ui.Console$_runScriptImpl_closure17.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.reflection.CachedMethod.invoke(CachedMethod.java:90)

      at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:233)

      at org.codehaus.groovy.runtime.metaclass.ClosureMetaClass.invokeMethod(ClosureMetaClass.java:272)

      at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:909)

      at groovy.lang.Closure.call(Closure.java:411)

      at groovy.lang.Closure.call(Closure.java:405)

      at groovy.lang.Closure.run(Closure.java:492)

      at java.lang.Thread.run(Thread.java:662)

      java.lang.NullPointerException: Cannot invoke method next() on null object

      at ConsoleScript18$_run_closure1.doCall(ConsoleScript18:3)

      at ConsoleScript18.run(ConsoleScript18:2)

        Attachments

          Activity

            People

            • Assignee:
              blackdrag Jochen Theodorou
              Reporter:
              aievdokimov andrii ievdokimov
            • Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: