groovy 1.7.4 and jdk 1.5

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

groovy 1.7.4 and jdk 1.5

JamieEchlin
Hi,

I have a groovy class compiled with groovy 1.7.4 and JDK 1.6.

However if I try to run it with jdk 1.5 I get:

java.lang.IllegalArgumentException: Action 'com.acme.MyClass' could not be instantiated.  Class is invalid or static initializers have failed to run

I'm not sure why this is, from what I've read groovy does not require java 1.6. Also I would expect to get a different error about bad class magic number or somesuch.

Will it work if I compile with 1.5, and if so are there any negatives to doing that? I'm using the gmaven-plugin if it makes any difference.

cheers, jamie


Reply | Threaded
Open this post in threaded view
|

Re: groovy 1.7.4 and jdk 1.5

Jochen Theodorou
Am 13.04.2011 18:18, schrieb Jamie Echlin:

> Hi,
>
> I have a groovy class compiled with groovy 1.7.4 and JDK 1.6.
>
> However if I try to run it with jdk 1.5 I get:
>
> java.lang.IllegalArgumentException: Action 'com.acme.MyClass' could not
> be instantiated.  Class is invalid or static initializers have failed to run
>
> I'm not sure why this is, from what I've read groovy does not require
> java 1.6. Also I would expect to get a different error about bad class
> magic number or somesuch.
>
> Will it work if I compile with 1.5, and if so are there any negatives to
> doing that? I'm using the gmaven-plugin if it makes any difference.

Groovy needs Java5, the classes produced by Groovy are still Java4 if
possible, if not they are Java5. With that I mean the bytecode of
course. The error message says something about the static initializer
failing as a possibility... have you ensured that this is not the reason
behind this all? It could be for example possible, that the class
com.acme.MyClass uses a Java class that is 1.6 compiled and then the
static initializer of MyClass fails, because there it makes use of the
invalid class. If MyClass were invalid, then normally there should be a
VerifyError. It is possible that something in there catches Error and
then produces this kind of message... then this is not the original
message and if you want to know the real problem you need the original
exception

bye blackdrag

--
Jochen "blackdrag" Theodorou
The Groovy Project Tech Lead
http://blackdragsview.blogspot.com/
For Groovy programming sources visit http://groovy.codehaus.org


---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email


Reply | Threaded
Open this post in threaded view
|

Re: groovy 1.7.4 and jdk 1.5

JamieEchlin
> The error message says something about the static initializer failing as a possibility.

Well, I have seen this error when I compile the class ("the" class extends another class) and the other class has changed method signatures, ie the version the end user has and the version I compiled against are different.  But I think you may be right about something else swallowing the real error, no idea what though.

But this can't be the problem in this case because everything else is equal, I am only changing the JRE running the app. There is some java classes I'm shipping (as bytecode) but they're compiled with -target 1.5.

There is no -target equivalent for groovyc or in the gmaven plugin right?

cheers, jamie


Reply | Threaded
Open this post in threaded view
|

RE: groovy 1.7.4 and jdk 1.5 [SEC=UNCLASSIFIED]

Weber, Derek

UNCLASSIFIED

I don't know if this applies to the Groovy bytecode producted but you can specify a javac class target within a groovyc task in Ant:
 
  <target name="compile">
    <taskdef name="groovyc" classname="org.codehaus.groovy.ant.Groovyc" classpathref="classpath" />
 
    <groovyc srcdir="src" destdir="classes" classpathref="classpath">
      <javac source="1.5" target="1.5" />
    </groovyc>
  </target>

Do those flags affect how groovyc compiles its code?
 
Alternatively, does groovyc always target 1.5?
 
D.

IMPORTANT: This email remains the property of the Department of Defence and is subject to the jurisdiction of section 70 of the Crimes Act 1914. If you have received this email in error, you are requested to contact the sender and delete the email.


From: Jamie Echlin [mailto:[hidden email]]
Sent: Thursday, April 14, 2011 2:22 AM
To: [hidden email]
Subject: Re: [groovy-user] groovy 1.7.4 and jdk 1.5

> The error message says something about the static initializer failing as a possibility.

Well, I have seen this error when I compile the class ("the" class extends another class) and the other class has changed method signatures, ie the version the end user has and the version I compiled against are different.  But I think you may be right about something else swallowing the real error, no idea what though.

But this can't be the problem in this case because everything else is equal, I am only changing the JRE running the app. There is some java classes I'm shipping (as bytecode) but they're compiled with -target 1.5.

There is no -target equivalent for groovyc or in the gmaven plugin right?

cheers, jamie