@@ -162,8 +162,6 @@ void Java::configureAsync(v8::Local<v8::Value>& asyncOptions) {
162162}
163163
164164v8::Local<v8::Value> Java::createJVM (JavaVM** jvm, JNIEnv** env) {
165- JavaVM* jvmTemp;
166- JavaVMInitArgs args;
167165
168166 v8::Local<v8::Value> asyncOptions = NanObjectWrapHandle (this )->Get (NanNew<v8::String>(" asyncOptions" ));
169167 if (asyncOptions->IsObject ()) {
@@ -226,11 +224,28 @@ v8::Local<v8::Value> Java::createJVM(JavaVM** jvm, JNIEnv** env) {
226224 vmOptions[i+1 ].optionString = strdup (*arrayItemStr);
227225 }
228226
229- JNI_GetDefaultJavaVMInitArgs (&args);
227+ JavaVMInitArgs args;
228+ // The JNI invocation is documented to include a function JNI_GetDefaultJavaVMInitArgs that
229+ // was formerly called here. But the documentation from Oracle is confusing/contradictory.
230+ // 1) It claims that the caller must set args.version before calling JNI_GetDefaultJavaVMInitArgs, which
231+ // we did not do.
232+ // 2) The sample code provide at the top of the doc doesn't even call JNI_GetDefaultJavaVMInitArgs.
233+ // 3) The Oracle documentation for Java 6 through Java 8 all contain a comment "Note that in the JDK/JRE, there is no
234+ // longer any need to call JNI_GetDefaultJavaVMInitArgs."
235+ // 4) It seems that some platforms don't implement JNI_GetDefaultJavaVMInitArgs, or have
236+ // marked it deprecated.
237+ // Omitting the call to JNI_GetDefaultJavaVMInitArgs works fine on Mac and Linux with Java 7 and Java 8.
238+ // The Oracle documentation is here:
239+ // http://docs.oracle.com/javase/6/docs/technotes/guides/jni/spec/invocation.html
240+ // http://docs.oracle.com/javase/7/docs/technotes/guides/jni/spec/invocation.html
241+ // http://docs.oracle.com/javase/8/docs/technotes/guides/jni/spec/invocation.html
230242 args.version = JNI_BEST_VERSION;
243+ // JNI_GetDefaultJavaVMInitArgs(&args); // If this turns out to be necessary, it should be called here.
231244 args.ignoreUnrecognized = false ;
232245 args.options = vmOptions;
233246 args.nOptions = vmOptionsCount;
247+
248+ JavaVM* jvmTemp;
234249 JNI_CreateJavaVM (&jvmTemp, (void **)env, &args);
235250 *jvm = jvmTemp;
236251
0 commit comments