Skip to content

Commit f088734

Browse files
authored
Enable helpful null pointer exceptions (elastic#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.
1 parent 515e408 commit f088734

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

distribution/tools/launchers/src/main/java/org/elasticsearch/tools/launchers/SystemJvmOptions.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919

2020
package org.elasticsearch.tools.launchers;
2121

22+
import org.elasticsearch.tools.java_version_checker.JavaVersion;
23+
2224
import java.util.List;
2325

2426
final class SystemJvmOptions {
@@ -50,6 +52,8 @@ static List<String> systemJvmOptions() {
5052
* debugging.
5153
*/
5254
"-XX:-OmitStackTraceInFastThrow",
55+
// enable helpful NullPointerExceptions (https://openjdk.java.net/jeps/358), if they are supported
56+
maybeShowCodeDetailsInExceptionMessages(),
5357
// flags to configure Netty
5458
"-Dio.netty.noUnsafe=true",
5559
"-Dio.netty.noKeySetOptimization=true",
@@ -66,4 +70,12 @@ static List<String> systemJvmOptions() {
6670
);
6771
}
6872

73+
private static String maybeShowCodeDetailsInExceptionMessages() {
74+
if (JavaVersion.majorVersion(JavaVersion.CURRENT) >= 14) {
75+
return "-XX:+ShowCodeDetailsInExceptionMessages";
76+
} else {
77+
return "";
78+
}
79+
}
80+
6981
}

0 commit comments

Comments
 (0)