LUCENE-7515: RunListenerPrintReproduceInfo may try to access static rule fields without

the rule being called. This flag is needed to ensure this isn't the case.
This commit is contained in:
Dawid Weiss 2016-10-21 10:41:38 +02:00
parent a19ec194d2
commit bc0116af69
2 changed files with 13 additions and 4 deletions

View File

@ -125,7 +125,7 @@ public final class RunListenerPrintReproduceInfo extends RunListener {
/** print some useful debugging information about the environment */
private static void printDebuggingInformation() {
if (classEnvRule != null) {
if (classEnvRule != null && classEnvRule.isInitialized()) {
System.err.println("NOTE: test params are: codec=" + classEnvRule.codec +
", sim=" + classEnvRule.similarity +
", locale=" + classEnvRule.locale.toLanguageTag() +
@ -176,7 +176,7 @@ public final class RunListenerPrintReproduceInfo extends RunListener {
// Environment.
if (!TEST_LINE_DOCS_FILE.equals(DEFAULT_LINE_DOCS_FILE)) addVmOpt(b, "tests.linedocsfile", TEST_LINE_DOCS_FILE);
if (classEnvRule != null) {
if (classEnvRule != null && classEnvRule.isInitialized()) {
addVmOpt(b, "tests.locale", classEnvRule.locale.toLanguageTag());
if (classEnvRule.timeZone != null) {
addVmOpt(b, "tests.timezone", classEnvRule.timeZone.getID());

View File

@ -72,13 +72,17 @@ final class TestRuleSetupAndRestoreClassEnv extends AbstractBeforeAfterRule {
Similarity similarity;
Codec codec;
/**
* Indicates whether the rule has executed its {@link #before()} method fully.
*/
private boolean initialized;
/**
* @see SuppressCodecs
*/
HashSet<String> avoidCodecs;
static class ThreadNameFixingPrintStreamInfoStream extends PrintStreamInfoStream {
public ThreadNameFixingPrintStreamInfoStream(PrintStream out) {
super(out);
}
@ -99,6 +103,10 @@ final class TestRuleSetupAndRestoreClassEnv extends AbstractBeforeAfterRule {
stream.println(component + " " + messageID + " [" + getTimestamp() + "; " + name + "]: " + message);
}
}
public boolean isInitialized() {
return initialized;
}
@Override
protected void before() throws Exception {
@ -113,7 +121,6 @@ final class TestRuleSetupAndRestoreClassEnv extends AbstractBeforeAfterRule {
if (VERBOSE) {
System.out.println("Loaded codecs: " + Codec.availableCodecs());
System.out.println("Loaded postingsFormats: " + PostingsFormat.availablePostingsFormats());
}
savedInfoStream = InfoStream.getDefault();
@ -235,6 +242,8 @@ final class TestRuleSetupAndRestoreClassEnv extends AbstractBeforeAfterRule {
}
LuceneTestCase.setLiveIWCFlushMode(flushMode);
initialized = true;
}
/**