diff --git a/buildSrc/src/main/groovy/org/elasticsearch/gradle/BuildPlugin.groovy b/buildSrc/src/main/groovy/org/elasticsearch/gradle/BuildPlugin.groovy index b3c2f4faef8..19f3846ca5d 100644 --- a/buildSrc/src/main/groovy/org/elasticsearch/gradle/BuildPlugin.groovy +++ b/buildSrc/src/main/groovy/org/elasticsearch/gradle/BuildPlugin.groovy @@ -469,6 +469,7 @@ class BuildPlugin implements Plugin { heapdumpDir.mkdirs() jvmArg '-XX:HeapDumpPath=' + heapdumpDir argLine System.getProperty('tests.jvm.argline') + argLine '-XX:-OmitStackTraceInFastThrow' // we use './temp' since this is per JVM and tests are forbidden from writing to CWD systemProperty 'java.io.tmpdir', './temp' diff --git a/distribution/src/main/resources/config/jvm.options b/distribution/src/main/resources/config/jvm.options index e08ffcabbb0..293e4c092f6 100644 --- a/distribution/src/main/resources/config/jvm.options +++ b/distribution/src/main/resources/config/jvm.options @@ -62,6 +62,10 @@ # use our provided JNA always versus the system one -Djna.nosys=true +# turn off a JDK optimization that throws away stack traces for common +# exceptions because stack traces are important for debugging +-XX:-OmitStackTraceInFastThrow + # use old-style file permissions on JDK9 -Djdk.io.permissionsUseCanonicalPath=true diff --git a/modules/lang-painless/src/test/java/org/elasticsearch/painless/ArrayLikeObjectTestCase.java b/modules/lang-painless/src/test/java/org/elasticsearch/painless/ArrayLikeObjectTestCase.java index 5fc41c8c630..2f7c37e2f69 100644 --- a/modules/lang-painless/src/test/java/org/elasticsearch/painless/ArrayLikeObjectTestCase.java +++ b/modules/lang-painless/src/test/java/org/elasticsearch/painless/ArrayLikeObjectTestCase.java @@ -80,9 +80,14 @@ public abstract class ArrayLikeObjectTestCase extends ScriptTestCase { IndexOutOfBoundsException e = expectScriptThrows(IndexOutOfBoundsException.class, () -> exec(script, singletonMap("val", val), true)); try { + /* If this fails you *might* be missing -XX:-OmitStackTraceInFastThrow in the test jvm + * In Eclipse you can add this by default by going to Preference->Java->Installed JREs, + * clicking on the default JRE, clicking edit, and adding the flag to the + * "Default VM Arguments". + */ assertThat(e.getMessage(), outOfBoundsExceptionMessageMatcher(index, 5)); } catch (AssertionError ae) { - ae.addSuppressed(e); // Mark the exception we are testing as suppressed so we get its stack trace. If it has one :( + ae.addSuppressed(e); // Mark the exception we are testing as suppressed so we get its stack trace. throw ae; } } diff --git a/modules/lang-painless/src/test/java/org/elasticsearch/painless/ListTests.java b/modules/lang-painless/src/test/java/org/elasticsearch/painless/ListTests.java index 1ae7ca0bc4f..88e1f7db817 100644 --- a/modules/lang-painless/src/test/java/org/elasticsearch/painless/ListTests.java +++ b/modules/lang-painless/src/test/java/org/elasticsearch/painless/ListTests.java @@ -25,9 +25,7 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.List; -import static org.hamcrest.Matchers.anyOf; import static org.hamcrest.Matchers.equalTo; -import static org.hamcrest.Matchers.nullValue; /** Tests for working with lists. */ public class ListTests extends ArrayLikeObjectTestCase { @@ -61,10 +59,7 @@ public class ListTests extends ArrayLikeObjectTestCase { if (index > size) { return equalTo("Index: " + index + ", Size: " + size); } - Matcher matcher = equalTo(Integer.toString(index)); - // If we set -XX:-OmitStackTraceInFastThrow we wouldn't need this - matcher = anyOf(matcher, nullValue()); - return matcher; + return equalTo(Integer.toString(index)); } else { // This exception is locale dependent so we attempt to reproduce it List list = new ArrayList<>(); diff --git a/modules/lang-painless/src/test/java/org/elasticsearch/painless/ScriptTestCase.java b/modules/lang-painless/src/test/java/org/elasticsearch/painless/ScriptTestCase.java index 1ab5aa14508..334d311c49c 100644 --- a/modules/lang-painless/src/test/java/org/elasticsearch/painless/ScriptTestCase.java +++ b/modules/lang-painless/src/test/java/org/elasticsearch/painless/ScriptTestCase.java @@ -128,12 +128,13 @@ public abstract class ScriptTestCase extends ESTestCase { if (e instanceof ScriptException) { boolean hasEmptyScriptStack = ((ScriptException) e).getScriptStack().isEmpty(); if (shouldHaveScriptStack && hasEmptyScriptStack) { - if (0 != e.getCause().getStackTrace().length) { - // Without -XX:-OmitStackTraceInFastThrow the jvm can eat the stack trace which causes us to ignore script_stack - AssertionFailedError assertion = new AssertionFailedError("ScriptException should have a scriptStack"); - assertion.initCause(e); - throw assertion; - } + /* If this fails you *might* be missing -XX:-OmitStackTraceInFastThrow in the test jvm + * In Eclipse you can add this by default by going to Preference->Java->Installed JREs, + * clicking on the default JRE, clicking edit, and adding the flag to the + * "Default VM Arguments". */ + AssertionFailedError assertion = new AssertionFailedError("ScriptException should have a scriptStack"); + assertion.initCause(e); + throw assertion; } else if (false == shouldHaveScriptStack && false == hasEmptyScriptStack) { AssertionFailedError assertion = new AssertionFailedError("ScriptException shouldn't have a scriptStack"); assertion.initCause(e);