Browse Source

Enable helpful null pointer exceptions (#54853)

Now that JDK 14 is available, and we are bundling it, this commit
enables us to run with helpful null pointer exceptions, which will be a
great aid in debugging.
Jason Tedor 5 years ago
parent
commit
f088734566

+ 12 - 0
distribution/tools/launchers/src/main/java/org/elasticsearch/tools/launchers/SystemJvmOptions.java

@@ -19,6 +19,8 @@
 
 package org.elasticsearch.tools.launchers;
 
+import org.elasticsearch.tools.java_version_checker.JavaVersion;
+
 import java.util.List;
 
 final class SystemJvmOptions {
@@ -50,6 +52,8 @@ final class SystemJvmOptions {
              * debugging.
              */
             "-XX:-OmitStackTraceInFastThrow",
+            // enable helpful NullPointerExceptions (https://openjdk.java.net/jeps/358), if they are supported
+            maybeShowCodeDetailsInExceptionMessages(),
             // flags to configure Netty
             "-Dio.netty.noUnsafe=true",
             "-Dio.netty.noKeySetOptimization=true",
@@ -66,4 +70,12 @@ final class SystemJvmOptions {
         );
     }
 
+    private static String maybeShowCodeDetailsInExceptionMessages() {
+        if (JavaVersion.majorVersion(JavaVersion.CURRENT) >= 14) {
+            return "-XX:+ShowCodeDetailsInExceptionMessages";
+        } else {
+            return "";
+        }
+    }
+
 }