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

"Expecting to find object/array on stack" VerifyError when passing static member as argument to chained ctor call

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Minor
    • Resolution: Fixed
    • 2.2.2, 2.4.0-rc-1
    • 2.5.15, 3.0.8, 4.0.0-alpha-3
    • Compiler
    • None
    • GNU/Linux (x64 SUSE and x86 Fedora Core 18)

    Description

      The attached script causes the following syntax error when run with Groovy 2.2.2.

      Caught: java.lang.VerifyError: (class: ReproBug$MyClass, method: <init> signature: ()V) Expecting to find object/array on stack
      java.lang.VerifyError: (class: ReproBug$MyClass, method: <init> signature: ()V) Expecting to find object/array on stack
      at ReproBug.main(ReproBug.groovy:18)

      The code compiles and runs fine as a Java class, which is why I think this is a bug in Groovy.

      The problem requires the conjunction of two things:
      1) A constructor that invokes another constructor
      2) Converting an integer to a string as a parameter to the constructor

      I encountered this during real-world scripting (although I used a integer literal), but was able to figure out the cause and work-around the problem. As such, this does not personally impact me; I am reporting it because I like Groovy and this is an easy way to contribute.

      Since I don't know whether you prefer an attachment or an inline quote, here is the code.

      public class ReproBug {
      
          static private Integer MYINT = 4;
          
          private static class MyClass {
              public final String value;
      
              public MyClass(String string) {
                  value = string;
              }
      
              public MyClass() {
                  this(MYINT.toString()); // <--- causes problems
              }
          }
      
          public static void main(String[] args) {
              System.out.println(new MyClass().value);
          }
      }
      

      I haven't figured out how to create a Groovy unit test case. If someone can point me to an example where simply getting the script to compile is proof that the bug is fixed, I'll try to work the attached code into a Groovy unit test case.

      Attachments

        1. ReproBug.groovy
          0.4 kB
          David Costanzo

        Issue Links

          Activity

            People

              emilles Eric Milles
              david_costanzo David Costanzo
              Votes:
              1 Vote for this issue
              Watchers:
              5 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: