Hello all,
I have a problem in a program I'm trying to write. The program loads a
class, executes its main() function, and records any runtime exceptions that
occur. This is repeated a few thousand times under a variety of conditions.
This works fine, but today I decided to add functionality to load a program
from an executable JAR file. I won't put all my code in here (unless you
want it) because it's kind of long but it goes something like this:
1. Get manifest from JAR file. Retrieve Main-Class attribute and Class-Path
attribute. Generate URLs for JAR file and every file in its classpath and
create a URLClassLoader with these urls as its search path.
2. Call loadClass() to load the class specified in the manifest as the main
class.
3. Get that method's main(String[] args) function as a Method.
4. Call the Method (actually the Method object gets passed to a Thread which
calls it)
By adding debug messages I've determined that the program gets past #2. The
class is loaded fine. But whenever I try to retrieve the main method, I get
the following error (I'm testing it with ArgoUML because I happened to have
it and it's a pretty simple executable JAR):
java.lang.VerifyError: (class: org/argouml/application/Main, method: main
signature: ([Ljava/lang/String;)V) Incompatible argument to function
at java.lang.Class.getDeclaredMethods0(Native Method)
at java.lang.Class.privateGetDeclaredMethods(Class.java:1627)
at java.lang.Class.getDeclaredMethods(Clas.java:114)
The reason it's getDeclaredMethods instead of getMethod is because for
debugging purposes I wanted to see if it was possible to enumerate the
methods - I get the same error when I call getMethod.
So what is a VerifyError and why does this occur? The application is widely
distributed and I know it works with my version of JDK (1.4.1) so what can I
do to make my program able to load it?
Thanks,
-Jeremy