I think that the reflection in the JVM on linux is failing somehow. I have a
static method in a class which sets a static boolean to true. This static
method is called from static void main(String arg[]); Reflection calls the
static method in the class, however the static variable it has set seems to get
reset when the constructor accesses that variable.
This behaviour occurs on Linux, not on NT or solaris. So I'm tempted to think
that something in Linux is goofed up.
If I hard code a class.setDebug(true) in my main class, it works okey.
I am running jdk1.1.6 released 6/13/98 from blackdown
Does a later date release fix these problems?
Here is a more detailed explanation of the above:::::::::::::::::::::::::::
I have a fairly large system and in the main class I parse some command line
parameters. One of the options is to enable debug for certain classes. for
example:
java LWD -d ESMTP.SMTPworker
The main routine finds the class listed after the -d, and calls setDebug(true)
using reflection.
The problem is that on NT this method workes perfectly, on Linux, however... the
debug never works.
To diagnose this problem further, I did the following:
1. I put a static section in SMTPworker
static {
System.out.println("Initalizing SMTPworker");
}
2. I put a println in setDebug to show that debug was being set.
3. In the constructor I printed out the value of debug
When I run the program I see:
Initalizing SMTPworker
setDebug is being called with true
constructor: debug is false
If I insert a hard coded "ESMTP.SMTPworker.setDebug(true)", the program says:
Initalizing SMTPworker
setDebug is being called with true <---- the reflection set Debug call
setDebug is being called with true <---- the hard coded setDEbug call
constructor: debug is true
HERE IS MY REFLECTION CODE:
Class dbg_cl=null;
String dbg_dirs[]={"","ESMTP.","lwd.",
"lwd.bounce.", "lwd.cos.email.",
"lwd.cos.email.command.",
"lwd.dispatch.", "lwdb.", "HTTP."};
if (args[i+1].equals("DSN"))
lwd.bounce.BounceHandlerDSN.setDebug2(true);
else {
int ii;
for (ii=0; ii < dbg_dirs.length; ii++) {
dbg_cl=LWobjUtils.getClass(dbg_dirs[ii]+args[i+1]); <- finds class
if (LWobjUtils.setDebug(dbg_cl)) <- calls ()
break;
}
if (ii == dbg_dirs.length) {
System.out.println (args[i+1] + ".setDebug(boolean) method not found\n");
System.exit(1);
}
}
GetCLASS() is here:
public static Class getClass(String name) {
try {
return Class.forName(name);
} catch (ClassNotFoundException e7) {
}
return null;
}
setDebug() is here:
public static boolean setDebug(Class c) {
if (c == null) return false;
java.lang.reflect.Method m=null;
Class cl[]=new Class[1];
cl[0]=Boolean.TYPE;
try {
m=c.getMethod("setDebug", cl);
Object oo[]= new Object[1];
oo[0]=Boolean.TRUE;
m.invoke(null, oo);
} catch (Exception ee) {
return false;
}
return true;
}