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

num.times fails in specific situation (incorrectly removed)

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 1.0-beta-5
    • 1.0-beta-6
    • None
    • None
    • Version: 1.0-beta-6-SNAPSHOT JVM: 1.4.1_01-27; Mac OS X Panther

    Description

      This code still fails, as reported in issue GROOVY-451. This is tested with snapshot dated 14 May. Replacing any of the commented out code with its neighbor removes the crash. Crash report follows code.

      #!/usr/bin/env groovy
      import java.awt.Color
      import java.util.ArrayList
      public class Test {
      ArrayList agents
      int numAgents = 4
      int spaceSize = 50
      // spaceSize = 50 // removing int avoids crash

      public void setup()

      { Random.createUniform() agents = new ArrayList() }

      public void begin() {
      // for (i in 1..numAgents) { // using for avoids crash
      this.numAgents.times

      { btn = new TinyAgent() // btn.move(0,0) // removing use or Random avoids crash // btn.move( // using "50" rather than spaceSize avoids crash // Random.uniform.nextIntFromTo(0, 50), // Random.uniform.nextIntFromTo(0, 50)) btn.move( // removing spaceSize and using literal removes crash Random.uniform.nextIntFromTo(0, spaceSize), Random.uniform.nextIntFromTo(0, spaceSize)) btn.setColor( new Color(Random.uniform.nextIntFromTo(0, Integer.MAX_VALUE))) agents.add(btn) }

      println agents.size()
      }
      }
      public class Random {
      static Random uniform
      static void createUniform()

      {uniform = new Random()}

      int nextIntFromTo (int from, int to)

      {(from + to / 2).intValue()}

      }
      public class TinyAgent {
      int x; int y; Color color
      public void move(int nextX, int nextY)

      { x = nextX y = nextY }

      }

      Test t = new Test()
      t.setup(); t.begin()

      owen|~/src/groovy/tiny[784]
      : ./test.groovy
      Exception in thread "main" java.lang.VerifyError: (class: Test$_begin_closure1, method: doCall signature: (Ljava/lang/Object;)Ljava/lang/Object Expecting to find object/array on stack
      at Test.begin(test.groovy:18)
      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 sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

      Attachments

        Activity

          People

            bingran Bing Ran
            backspaces Owen Densmore
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: