Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8202518

JNI_CreateJavaVM access violation reading location 0x00 when debugging in VS2017

    • x86_64
    • windows_10

      ADDITIONAL SYSTEM INFORMATION :
      Windows 10 64 bit - Build 16299.rs3_release.170928-1534
      JDK 10.0.1
      Visual Studio 2017 15.6.6

      A DESCRIPTION OF THE PROBLEM :
      Having just migrated an application from VM2013 to VS2017 which uses JNI we experienced not previously seen errors when debugging the JNI code. Migration of application has been discounted as a factor as have reproduced this using standalone C++ program.

      Simply call JNI_CreateJavVM and you will get an exception caught in VS2017 showing access violation reading location 0x000000000000000

      Issue appears to replicate with JDKs 8,9,10

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Compile and link source below. Run in VS2017 debugger with additional command line java/util/Map

      Put a break point on the line with JNI_CreateJavaVM, stop at BP and then step over line;

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      step action completes correctly and moves to next line in c++ code
      ACTUAL -
       VS2017 reports "Frame not in module" and shows window with message

      Exception thrown at 0x000002C33444075C in test2.exe: 0xC0000005: Access violation reading location 0x0000000000000000.

      this is not an exception from the .NET CLR it appears to be some null memory dereference.

      ---------- BEGIN SOURCE ----------
      #include <windows.h>
      #include <jni.h>

      int main(int argc, char **argv)
      {
      JavaVMOption options[1];
      JNIEnv *env;
      JavaVM *jvm;
      JavaVMInitArgs vm_args;
      jint status;
      jclass cls;

      options[0].optionString = (char *) "-Djava.class.path=.";
      memset(&vm_args, 0, sizeof(vm_args));
      vm_args.version = JNI_VERSION_1_6;
      vm_args.nOptions = 1;
      vm_args.options = options;

      status = JNI_CreateJavaVM(&jvm, (void **)&env, &vm_args);
      printf("JNI_CreateJavaVM returned %x\n", status);

      if (status != JNI_ERR)
      {
      if (argc > 1) {
      for (int arg = 1; arg < argc; arg++) {
      char *className = argv[arg];
      cls = env->FindClass(className);
      if (cls != 0)
      {
      printf("Found [%s]\n",className);
      }
      else {
      printf("Failed to find [%s]\n", className);
      }

      }
      }

      jvm->DestroyJavaVM();
      return 0;
      }
      else
      return -1;
      }
      ---------- END SOURCE ----------

      FREQUENCY : always


            fmatte Fairoz Matte
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: