[BUG PROPOSAL]: C++ code that calls JNI_CreateJavaVM can be exited by java
adam.farley at uk.ibm.com
Wed Aug 23 15:54:02 UTC 2017
Problem: Several of Java's "c" files call exit(0) if you pass certain
command-line options to JNI_CreateJavaVM, which can terminate the C++ code
JNI users use to initialise the JVM.
Example: If you write some C++ code that calls JNI_CreateJavaVM, and uses
the option "-agentlib:jdwp=help", Java's c files will print the needed
help output and call exit(0).
Result: Your C++ code is terminated on this line, and a return code of 0
Issue 1: The exit(0) prevents your code from doing anything useful after
the JNI_CreateJavaVM call.
Issue 2: The exit(0) indicates to anything monitoring your C++ code that
your code exited normally, even though it was terminated mid-way-through.
Issue 3: This return code is useless to us, as a 0 can indicate the VM
started correctly, or it can indicate the VM was terminated due to one or
more of these command-line options.
Issue 4: Of the other JNI return values (JNI_OK, JNI_ERR, etc) none of
them appear to cover this scenario.
PS1: We should amend the JNI specification to include a "JNI_SILENT_EXIT"
return code, so the C++ code knows a VM was not created, but that it isn't
PS2: We should identify a list of the command-line options that produce
this behaviour via the JNI. (not all of the "help" options are recognised
by the JNI interface. E.g. -version and -help produce a JNI_ERR and an
"Option not recognised" message)
PS3: We should replace these annoying exit(0) calls with code that returns
"JNI_SILENT_EXIT", so the C++ code has a chance to finish.
Unless stated otherwise above:
IBM United Kingdom Limited - Registered in England and Wales with number
Registered office: PO Box 41, North Harbour, Portsmouth, Hampshire PO6 3AU
More information about the core-libs-dev