Consider the following code:
When running, this code prints the following:
MethodEntryEvent evt;
ObjectReference con;
...Class evtClass = evt.getClass();
try {
System.out.println("Class of evt: " + evtClass);
System.out.println("Methods of evt: " +
Arrays.asList(evtClass.getMethods()));
try {
Value v = evt.returnValue();
System.out.println(v);
} catch (Throwable ex) {
ex.printStackTrace();
}
java.lang.reflect.Method retvalMethod =
evtClass.getMethod("returnValue", null);
retvalMethod.setAccessible(true);
con = (ObjectReference)retvalMethod.invoke(evt, (Object[])null);
} catch (Throwable t) {
t.printStackTrace();
}
System.out.println("Returned: " + con);
Class of evt: class com.sun.tools.jdi.EventSetImpl$MethodExitEventImpl Methods of evt: [ public com.sun.jdi.Value com.sun.tools.jdi.EventSetImpl$MethodExitEventImpl.returnValue(), public java.lang.String com.sun.tools.jdi.EventSetImpl$LocatableEventImpl.toString(), public com.sun.jdi.Method com.sun.tools.jdi.EventSetImpl$LocatableEventImpl.method(), public com.sun.jdi.Location com.sun.tools.jdi.EventSetImpl$LocatableEventImpl.location(), public com.sun.jdi.ThreadReference com.sun.tools.jdi.EventSetImpl$ThreadedEventImpl.thread(), public int com.sun.tools.jdi.EventSetImpl$EventImpl.hashCode(), public boolean com.sun.tools.jdi.EventSetImpl$EventImpl.equals(java.lang.Object), public com.sun.jdi.request.EventRequest com.sun.tools.jdi.EventSetImpl$EventImpl.request(), public com.sun.jdi.VirtualMachine com.sun.tools.jdi.MirrorImpl.virtualMachine(), public final native java.lang.Class java.lang.Object.getClass(), public final void java.lang.Object.wait(long,int) throws java.lang.InterruptedException, public final void java.lang.Object.wait() throws java.lang.InterruptedException, public final native void java.lang.Object.wait(long) throws java.lang.InterruptedException, public final native void java.lang.Object.notify(), public final native void java.lang.Object.notifyAll()] java.lang.NoSuchMethodError: com.sun.jdi.event.MethodExitEvent.returnValue()Lcom/sun/jdi/Value; at org.hrum.dbdb.DriverManagerMethodExitEventListener.process(DriverManagerMethodExitEventListener.java:99) at org.hrum.dbdb.DbdbEventQueue.removeDebug(DbdbEventQueue.java:168) at org.hrum.dbdb.DbdbEventQueue.remove(DbdbEventQueue.java:47) at org.eclipse.jdt.internal.debug.core.EventDispatcher.run(EventDispatcher.java:226) at java.lang.Thread.run(Thread.java:619) Returned: instance of oracle.jdbc.driver.T4CConnection(id=435)(class com.sun.tools.jdi.ObjectReferenceImpl)
Now, I will run this in debug mode and set a breakpoint at the red line above. When the breakpoint is hit, evaluation of
evt.returnValue()
returns an instance of com.sun.tools.jdi.ObjectReferenceImpl
. However, when the execution is resumed, the result is as above (that is, evt.returnValue()
results in a NoSuchMethodError
).
Further, if we remove the green line (retvalMethod.setAccessible(true);
), we will get an IllegalAccessException
on the invocation:
What is going on? I’d say it’s left as an exercise for the reader, but honestly, at the moment, I don’t feel like looking for an answer at all. I will perhaps let Bob and Dr. Heinz Max Kabutz (did I mention how much I enjoy referring to Dr.Heinz Max Kabutz?) to do the detective work…Class org.hrum.dbdb.DriverManagerMethodExitEventListener can not access a member of class com.sun.tools.jdi.EventSetImpl$MethodExitEventImpl with modifiers “public”
ENVIRONMENT: This code is part of a plug-in project I am running in Eclipse 3.2RC3, with Mustang.
I’m thinking classloaders are involved. -bobh
LikeLike
Thank you, Counselor. 🙂
LikeLike
Hii great reading your post
LikeLike