Java crashes on getting field value
I am not able to execute my code with DarkNotes. Running the same code multiple times results in one of the following:
- A field which is guaranteed to be non-null is read as null (
IntPtr.Zerois returned at the JavaClass.cs#L127). - Execution freezes at the JniWrapper.cs#L538.
- An object with unrelated type is read from the field (e.g.
sun.net.www.protocol.file.Handler). - An object with type
java.lang.Threadis being returned. When invokingstarton this object,AccessViolationExceptionis thrown at the JniWrapper.cs#L528.
The problem reproduces on JRE6, 7 and 8, both 32-bit and 64-bit.
The same code runs with jni4net via generated proxies without any problems.
The specific line which fails:
mainFrame.mt.start();
where mainFrame is an instance of this Java class (unrelated members stripped):
public class MainFrame extends java.awt.Frame
{
public final java.lang.Thread mt;
public MainFrame()
{
this.mt = new HackThread(this.g, this);
}
}
public class HackThread extends java.lang.Thread
{
}
I was finally able to execute my code by getting the mt field via reflection:
var field = [email protected]("mt");
var mt = field.get(mainFrame);
mt.start();
I got an instance of HackThread in mt and start runs without problems.
there was no getDeclaredField there is just getField
i just implemented it in my fork (https://github.com/shimondoodkin/DarkNotes/)
if it is called with "@class" https://github.com/mooso/DarkNotes/blob/master/DarkNotes/JavaClass.cs#L316 then it creates a class based on DarkNotes/JavaClass.cs which holds a pointer and accesses jvm's methods using DarkNotes/CoreClassProxies/JClassClass.cs