A fatal error has been detected by the Java Runtime Environment: JNI (Internal Error)


I am trying to call VB DLL method in Java. I have succeeded in calling simple Hello World method. Now I try to call a method that takes String as input and returns String as output. The Wrapper DLL is compiled successfully. But on running the Java code, the error

A fatal error has been detected by the Java Runtime Environment:

Internal Error (0xe0434352), pid=3668, tid=1124

On searching, I found that following error comes mostly due to error in native code, which I can't figure out.

Following is the log file:

A fatal error has been detected by the Java Runtime Environment:

Internal Error (0xe0434352), pid=1940, tid=2640

JRE version: 6.0_32-b05 Java VM: Java HotSpot(TM) Client VM (20.7-b02 mixed mode, sharing windows-x86 ) Problematic frame: C [KERNELBASE.dll+0x969b]

--------------- T H R E A D ---------------

Current thread (0x002d9800):  JavaThread "main" [_thread_in_native,id=2640,            

siginfo: ExceptionCode=0xe0434352, ExceptionInformation=0x80070002 0x00000000  
0x00000000 0x00000000 0x617c0000 

EAX=0x0198ea44, EBX=0x00000005, ECX=0x00000005, EDX=0x00000000
ESP=0x0198ea44, EBP=0x0198ea94, ESI=0x0198eb04, EDI=0x00000001
EIP=0x75a3969b, EFLAGS=0x00000216

Top of Stack: (sp=0x0198ea44)
0x0198ea44:   e0434352 00000001 00000000 75a3969b
0x0198ea54:   00000005 80070002 00000000 00000000
0x0198ea64:   00000000 617c0000 00000001 00000000
0x0198ea74:   776a1e37 00000000 03ea11bc 00004000
0x0198ea84:   0022ae68 0198ea9c 001d9a98 0198ea4c
0x0198ea94:   0198eb38 618e48c7 e0434352 00000001
0x0198eaa4:   00000005 0198eb04 4dc4fa37 040ba034
0x0198eab4:   00227be0 0198ebf0 001d9a98 00000001 

Instructions: (pc=0x75a3969b)
0x75a3967b:   89 45 c0 c1 e0 02 50 ff 75 14 8d 45 c4 50 e8 9d
0x75a3968b:   d1 ff ff 83 c4 0c 8d 45 b0 50 ff 15 5c 11 a3 75
0x75a3969b:   c9 c2 10 00 89 45 c0 eb ed 90 90 90 90 90 8b ff
0x75a396ab:   55 8b ec 83 ec 1c 6a 00 6a 1c 8d 45 e4 50 6a 00 

Register to memory mapping:

EAX=0x0198ea44 is pointing into the stack for thread: 0x002d9800
EBX=0x00000005 is an unknown value
ECX=0x00000005 is an unknown value
EDX=0x00000000 is an unknown value
ESP=0x0198ea44 is pointing into the stack for thread: 0x002d9800
EBP=0x0198ea94 is pointing into the stack for thread: 0x002d9800
ESI=0x0198eb04 is pointing into the stack for thread: 0x002d9800
EDI=0x00000001 is an unknown value

Stack: [0x01940000,0x01990000],  sp=0x0198ea44,  free space=314k
Native frames: (J=compiled Java code, j=interpreted, Vv=VM code, C=native code)
C  [KERNELBASE.dll+0x969b]  RaiseException+0x54
C  [clr.dll+0x1248c7]  DllGetClassObjectInternal+0x5f84e
C  [clr.dll+0x223abf]  GetHistoryFileDirectory+0x1427a
C  [clr.dll+0x22c222]  GetHistoryFileDirectory+0x1c9dd
C  [clrjit.dll+0x10cf]
C  [clrjit.dll+0x1f0b0]
C  [clrjit.dll+0x1a60]
C  [clrjit.dll+0x1c42]
C  [clrjit.dll+0x244d]
C  [clrjit.dll+0x401c]
C  [clrjit.dll+0x4132]
C  [clrjit.dll+0x4282]
C  [clrjit.dll+0x4595]
C  [clr.dll+0x33669]  CreateAssemblyNameObject+0x61d0
C  [clr.dll+0x33701]  CreateAssemblyNameObject+0x6268
C  [clr.dll+0x33743]  CreateAssemblyNameObject+0x62aa
C  [clr.dll+0x3399c]  CreateAssemblyNameObject+0x6503
C  [clr.dll+0x33496]  CreateAssemblyNameObject+0x5ffd
C  [clr.dll+0x340db]  CreateAssemblyNameObject+0x6c42
C  [clr.dll+0x1bcd5]  DllRegisterServerInternal+0x98c9
C  [clr.dll+0x2ae9]
C  0x03f0ba9e
j  CsharpConsumer.displayWithParam(Ljava/lang/String;)Ljava/lang/String;+0
j  CsharpConsumer.main([Ljava/lang/String;)V+50
v  ~StubRoutines::call_stub
V  [jvm.dll+0xfad4b]
V  [jvm.dll+0x18c421]
V  [jvm.dll+0xfadcd]
V  [jvm.dll+0x95836]
V  [jvm.dll+0x9d778]
V  [jvm.dll+0xaf22b]
C  [java.exe+0x2155]
C  [java.exe+0x85b4]
C  [kernel32.dll+0x51154]  BaseThreadInitThunk+0x12
C  [ntdll.dll+0x5b299]  RtlInitializeExceptionChain+0x63
C  [ntdll.dll+0x5b26c]  RtlInitializeExceptionChain+0x36

Java frames: (J=compiled Java code, j=interpreted, Vv=VM code)
j  CsharpConsumer.displayWithParam(Ljava/lang/String;)Ljava/lang/String;+0
j  CsharpConsumer.main([Ljava/lang/String;)V+50
v  ~StubRoutines::call_stub

---------------  P R O C E S S  ---------------

Java Threads: ( => current thread )
  0x01a24400 JavaThread "Low Memory Detector" daemon [_thread_blocked, id=3172,
  0x01a1e800 JavaThread "C1 CompilerThread0" daemon [_thread_blocked, id=2236,
  0x01a1dc00 JavaThread "Attach Listener" daemon [_thread_blocked, id=5308, 
  0x01a1b400 JavaThread "Signal Dispatcher" daemon [_thread_blocked, id=3916, 
  0x01a0c000 JavaThread "Finalizer" daemon [_thread_blocked, id=3660, 
  0x01a0a000 JavaThread "Reference Handler" daemon [_thread_blocked, id=5116, 
=>0x002d9800 JavaThread "main" [_thread_in_native, id=2640, 

Other Threads:
  0x019ce000 VMThread [stack: 0x03c20000,0x03c70000] [id=240]
  0x01a35c00 WatcherThread [stack: 0x03e50000,0x03ea0000] [id=2652]

VM state:not at safepoint (normal execution)

VM Mutex/Monitor currently owned by a thread: None

 def new generation   total 4928K, used 281K [0x23700000, 0x23c50000, 0x28c50000)
  eden space 4416K,   6% used [0x23700000, 0x23746498, 0x23b50000)
  from space 512K,   0% used [0x23b50000, 0x23b50000, 0x23bd0000)
  to   space 512K,   0% used [0x23bd0000, 0x23bd0000, 0x23c50000)
 tenured generation   total 10944K, used 0K [0x28c50000, 0x29700000, 0x33700000)
   the space 10944K,   0% used [0x28c50000, 0x28c50000, 0x28c50200, 0x29700000)
 compacting perm gen  total 12288K, used 31K [0x33700000, 0x34300000, 0x37700000)
   the space 12288K,   0% used [0x33700000, 0x33707fb0, 0x33708000, 0x34300000)
    ro space 10240K,  54% used [0x37700000, 0x37c7ee18, 0x37c7f000, 0x38100000)
    rw space 12288K,  55% used [0x38100000, 0x387a27d8, 0x387a2800, 0x38d00000)

 Code Cache  [0x01a90000, 0x01b00000, 0x03a90000)
 total_blobs=116 nmethods=2 adapters=59 free_code_cache=33110656 largest_free_block=0

The VB code has a function that takes as input as string and outputs a string

Public Class Level2Display
    Public Function displayWithParam(str As String) As String
        Return "hello world" + str
    End Function
End Class

Here's the C++/CLI Wrapper code

JNIEXPORT jstring JNICALL Java_CsharpConsumer_displayWithParam
(JNIEnv *env, jobject jobj, jstring myStr)

         const jchar* temp = (env)->GetStringChars(myStr, null); //Tried changing to JNI_FALSE, still the error persisted. 
             return NULL;

        System::String^ managedString = gcnew System::String((const wchar_t*)temp);
        env->ReleaseStringChars(myStr, temp);

        Level2Display^ lds = gcnew Level2Display();    //class in the VB dll
        System::String^ result = (System::String^)lds->displayWithParam(managedString);         //displayWithParam method
        return env->NewStringUTF((const char*)System::Runtime::InteropServices::Marshal::StringToHGlobalAnsi(result).ToPointer());


Kindly help!

asked on Stack Overflow Jun 16, 2014 by Peps0791

2 Answers


This line is all screwed up.

return env->NewStringUTF((const char*)System::Runtime::InteropServices::Marshal::StringToHGlobalAnsi(result).ToPointer());

You've got a mismash of Ansi and UTF-8 and a memory leak. I recommend never using any of the Marshal methods with HGlobal in the name. (They violate the Single Responsibility Principle by doing both memory allocation and character set conversion, and they crash if you actually use them with real HGLOBALs)

Instead, try

pin_ptr<const wchar_t> resultChars = PtrToStringChars(result);
return env->NewString(resultChars, result->Length);
answered on Stack Overflow Jun 16, 2014 by Ben Voigt

You should be using GetStringUTFChars instead of GetStringChars. Does System::String make a deep copy of temp? If not, call ReleaseStringChars after NewStringUTF or check the isCopy pointer. Other than that, everything looks ok in the code you posted.

answered on Stack Overflow Jun 16, 2014 by Alex Barker • edited Jun 16, 2014 by Alex Barker

User contributions licensed under CC BY-SA 3.0