DarkNotes icon indicating copy to clipboard operation
DarkNotes copied to clipboard

Java crashes on getting field value

Open DarkDaskin opened this issue 10 years ago • 1 comments

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.Zero is 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.Thread is being returned. When invoking start on this object, AccessViolationException is 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.

DarkDaskin avatar Aug 07 '15 08:08 DarkDaskin

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

shimondoodkin avatar Jan 31 '16 09:01 shimondoodkin