# HG changeset patch
# User Markus Mützel <markus.muetzel@gmx.de>
# Date 1602166192 -7200
#      Thu Oct 08 16:09:52 2020 +0200
# Node ID afd670f8eb437831ca3c3c470c38ff859dedc640
# Parent  35bfa7a31aa2d750d434f567fe69ad54eb2e8ba6
Detect Java versions >= 15 on Windows (bug #59215).

* ov-java.cc (get_jvm_lib_path_from_registry): Also check for Java VM version 15
  or newer.

diff -r 35bfa7a31aa2 -r afd670f8eb43 libinterp/octave-value/ov-java.cc
--- a/libinterp/octave-value/ov-java.cc	Sun Oct 04 22:35:24 2020 +0200
+++ b/libinterp/octave-value/ov-java.cc	Thu Oct 08 16:09:52 2020 +0200
@@ -547,51 +547,92 @@
 get_jvm_lib_path_from_registry ()
 {
   // In Windows, find the location of the JRE from the registry
-  // and load the symbol from the dll.
   std::string key, jversion, value;
 
-  // First search for JRE >= 9
-  key = R"(software\javasoft\jre)";
+  // First search for JRE >= 15
+  key = R"(software\javasoft\jdk)";
 
   jversion = octave::sys::env::getenv ("JAVA_VERSION");
+  bool maybe_version_15_or_newer = true;
   octave_value regval;
   LONG retval;
   if (jversion.empty ())
     {
       value = "CurrentVersion";
-      retval = octave::get_regkey_value (HKEY_LOCAL_MACHINE, key, value, regval);
+      retval = octave::get_regkey_value (HKEY_LOCAL_MACHINE, key, value,
+                                         regval);
 
       if (retval != ERROR_SUCCESS)
         {
-          // Search for JRE < 9
-          key = R"(software\javasoft\java runtime environment)";
-          retval = octave::get_regkey_value (HKEY_LOCAL_MACHINE, key, value, regval);
+          // Search for JRE < 15
+          maybe_version_15_or_newer = false;
+          key = R"(software\javasoft\jre)";
+          retval = octave::get_regkey_value (HKEY_LOCAL_MACHINE, key, value,
+                                             regval);
+
+          if (retval != ERROR_SUCCESS)
+            {
+              // Search for JRE < 9
+              key = R"(software\javasoft\java runtime environment)";
+              retval = octave::get_regkey_value (HKEY_LOCAL_MACHINE, key,
+                                                 value, regval);
+            }
         }
 
       if (retval != ERROR_SUCCESS)
         error ("unable to find Java Runtime Environment: %s::%s",
                key.c_str (), value.c_str ());
 
-      jversion = regval.xstring_value (R"(initialize_jvm: registry value "%s" at "%s" must be a string)",
+      jversion = regval.xstring_value ("initialize_jvm: registry value "
+                                       R"("%s" at "%s" must be a string)",
                                        value.c_str (), key.c_str ());
     }
 
-  key = key + '\\' + jversion;
+  std::string jvm_lib_path;
+  if (maybe_version_15_or_newer)
+    {
+      // Look for value used by JRE >= 15
+      key = key + '\\' + jversion;
+      value = "JavaHome";
+      retval = octave::get_regkey_value (HKEY_LOCAL_MACHINE, key, value,
+                                         regval);
+
+      if (retval != ERROR_SUCCESS)
+        error ("unable to find Java Runtime Environment: %s::%s",
+               key.c_str (), value.c_str ());
+
+      jvm_lib_path
+        = regval.xstring_value (R"(initialize_jvm: registry value "%s" at )"
+                                R"("%s" must be a string)",
+                                value.c_str (), key.c_str ())
+          + R"(\bin\server\jvm.dll)";
+
+      if (! jvm_lib_path.empty ())
+        return jvm_lib_path;
+
+    }
+
+  // Search for JRE < 15
+  key = R"(software\javasoft\jre\)" + jversion;
   value = "RuntimeLib";
-  retval = octave::get_regkey_value (HKEY_LOCAL_MACHINE, key, value, regval);
+  retval = octave::get_regkey_value (HKEY_LOCAL_MACHINE, key, value,
+                                     regval);
+
   if (retval != ERROR_SUCCESS)
     {
       // Search for JRE < 9
       key = R"(software\javasoft\java runtime environment\)" + jversion;
-      retval = octave::get_regkey_value (HKEY_LOCAL_MACHINE, key, value, regval);
+      retval = octave::get_regkey_value (HKEY_LOCAL_MACHINE, key, value,
+                                         regval);
     }
 
   if (retval != ERROR_SUCCESS)
     error ("unable to find Java Runtime Environment: %s::%s",
            key.c_str (), value.c_str ());
 
-  std::string jvm_lib_path
-    = regval.xstring_value (R"(initialize_jvm: registry value "%s" at "%s" must be a string)",
+  jvm_lib_path
+    = regval.xstring_value (R"(initialize_jvm: registry value "%s" at )"
+                            R"("%s" must be a string)",
                             value.c_str (), key.c_str ());
 
   if (jvm_lib_path.empty ())
