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

VerifyError when using DelegatingMetaClass

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 1.1-rc-1
    • 1.1-rc-2
    • None
    • None
    • Environment WinXP SP2
      The eclipse plugin is V 1.0.1 installed on Eclipse 3.3.0
      When trying to run the script standalone I use Groovy Version: 1.1-rc-1 JVM: 1.6.0_03-b05

    Description

      Hi, I have a problem with DelegatingMetaClass. I am trying to extend groovy.sql.Sql class with a static method similar to newInstance but that takes only one parameter ( a file name that contains all the connection parameters )

      So I have used DelegatingMetaClass conventions and here is my SqlMetaClass.groovy:
      ------------------------
      package groovy.runtime.metaclass.groovy.sql

      import groovy.sql.Sql

      class SqlMetaClass extends groovy.lang.DelegatingMetaClass
      {
      SqlMetaClass(MetaClassRegistry a_registry, final Class a_class)

      { super(a_class); }

      public Object invokeStaticMethod(Object a_object, String a_methodName, Object[] a_arguments)
      {
      if(a_methodName == 'newInstance'){
      if(a_arguments.length == 1)

      { //interpret the first argument as a file name Properties props = new Properties() props.load(new FileInputStream(a_arguments[0])) return Sql.newInstance(props['db.url'],props['db.user'], props['db.password'], props['db.drivername']) }

      }
      return super.invokeStaticMethod(a_object, a_methodName, a_arguments)
      }
      }
      ------------------------

      Afterwards calling Sql.newInstance('hsql.properties') in some script worked as expected.
      My problem is that it works only from eclipse, the moment I try to use it standalone I get some errors:

      1. Calling the script as groovy -cp ../bin-groovy bug.groovy ( using the compiled class generated by the eclipse plug-in ) I get:

      Caught: java.lang.VerifyError: (class: groovy/runtime/metaclass/groovy/sql/SqlMetaClass, method: super$2$invokeMethod signature: (Ljava/lang/Class;Ljava/lang/Object;Ljava/lang/String;[Ljava/lang/Object;ZZ)Ljava/lang/Object Illegal use of nonvirtual function call
      at bug.run(bug.groovy:4)
      at bug.main(bug.groovy)

      2. Calling the script as groovy -cp ../clazzez bug.groovy gives me :
      Caught: java.lang.VerifyError: (class: groovy/runtime/metaclass/groovy/sql/SqlMetaClass, method: super$2$setUseReflection signature: (Z)V) Illegal use of nonvirtual function call
      at bug.run(bug.groovy:4)
      at bug.main(bug.groovy)

      where clazzez is the directory where I compiled the SqlMetaClass.groovy file using groovyc

      <?xml version="1.0"?>

      <project name="Compile a groovy class" default="compile" basedir=".">
      <target name="compile">
      <taskdef name="groovyc" classname="org.codehaus.groovy.ant.Groovyc" />

      <groovyc srcdir="scripts/groovy" destdir="clazzez">

      </groovyc>

      </target>
      </project>

      Environment WinXP SP2
      The eclipse plugin is V 1.0.1 installed on Eclipse 3.3.0
      When trying to run the script standalone I use Groovy Version: 1.1-rc-1 JVM: 1.6.0_03-b05

      Attachments

        Activity

          People

            blackdrag Jochen Theodorou
            seven Horia Muntean
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: