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

Verify error when you test a list property and set it then use it

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 1.0-beta-1
    • 1.0-beta-2
    • class generator
    • None
    • CVS 11-21-2003

    Description

      Running the script:

      setProperty("test", ["test1", "test2"])
      if (test == null) {
      test = ["", ""]
      }
      println(test.get(0))

      Or using the script context to bind "test", you get an error:

      Exception in thread "main" java.lang.VerifyError: (class: ifproblem, method: run signature: ()Ljava/lang/Object Accessing value from uninitialized register 2
      at java.lang.Class.getDeclaredConstructors0(Native Method)
      at java.lang.Class.privateGetDeclaredConstructors(Class.java:1590)
      at java.lang.Class.getDeclaredConstructors(Class.java:1152)
      at groovy.lang.MetaClass.<init>(MetaClass.java:111)
      at groovy.lang.MetaClassRegistry.getMetaClass(MetaClassRegistry.java:91)
      at org.codehaus.groovy.runtime.Invoker.invokeMethod(Invoker.java:112)
      at org.codehaus.groovy.runtime.InvokerHelper.invokeMethod(InvokerHelper.java:84)
      at groovy.lang.GroovyShell.run(GroovyShell.java:144)
      at groovy.lang.GroovyShell.main(GroovyShell.java:85)
      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)

      If you decompile the code you find:

      java.util.List list;
      if(InvokerHelper.compareEqual(InvokerHelper.getProperty(this, "test"), null))
      list = InvokerHelper.createList(new Object[]

      { "", "" });

      Clearly list hasn't necessarily been initialized so it don't lie. I would probably change the code around a bit to say:

      java.util.List list = InvokerHelper.getProperty(this, "test");
      if(InvokerHelper.compareEqual(list, null))
      list = InvokerHelper.createList(new Object[] { "", "" }

      );

      So that the list is always initialized.

      Attachments

        Activity

          People

            spullara Sam Pullara
            spullara Sam Pullara
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: