From f0830673281d9caee135140131a47f864acb4be2 Mon Sep 17 00:00:00 2001 From: Gus Heck Date: Fri, 28 Feb 2020 14:20:35 -0500 Subject: [PATCH] SOLR-14283 ensure that the test only runs on JVM's where it can succeeed --- .../org/apache/solr/SourceHomeNullifier.java | 40 +++++++++++-------- 1 file changed, 23 insertions(+), 17 deletions(-) diff --git a/solr/core/src/test/org/apache/solr/SourceHomeNullifier.java b/solr/core/src/test/org/apache/solr/SourceHomeNullifier.java index e3dff564dcc..563a75360ff 100644 --- a/solr/core/src/test/org/apache/solr/SourceHomeNullifier.java +++ b/solr/core/src/test/org/apache/solr/SourceHomeNullifier.java @@ -35,18 +35,21 @@ public class SourceHomeNullifier extends TestWatcher { @Override protected void starting(Description description) { - boolean nullify = RandomizedContext.current().getRandom().nextBoolean(); - if (nullify) { - oldSourceHome = ExternalPaths.SOURCE_HOME; - try { - sourceHomeField = ExternalPaths.class.getDeclaredField("SOURCE_HOME"); - setFinalStatic(sourceHomeField, null); - } catch (Exception e) { - e.printStackTrace(); - fail(e.getMessage()); + // see https://stackoverflow.com/a/2591122 + // this test is only meant to run under java < 9.0 + if (System.getProperty("java.version").startsWith("1.")) { + boolean nullify = RandomizedContext.current().getRandom().nextBoolean(); + if (nullify) { + oldSourceHome = ExternalPaths.SOURCE_HOME; + try { + sourceHomeField = ExternalPaths.class.getDeclaredField("SOURCE_HOME"); + setFinalStatic(sourceHomeField, null); + } catch (Exception e) { + e.printStackTrace(); + fail(e.getMessage()); + } } } - super.starting(description); } @SuppressForbidden(reason = "Need to tweak the value of a static final field on a per test basis") @@ -62,14 +65,17 @@ public class SourceHomeNullifier extends TestWatcher { @Override protected void finished(Description description) { - if (sourceHomeField != null) { - try { - sourceHomeField.set(null, oldSourceHome); - } catch (IllegalAccessException e) { - e.printStackTrace(); - fail(e.getMessage()); + // see https://stackoverflow.com/a/2591122 + // this test is only meant to run under java < 9.0 + if (System.getProperty("java.version").startsWith("1.")) { + if (sourceHomeField != null) { + try { + sourceHomeField.set(null, oldSourceHome); + } catch (IllegalAccessException e) { + e.printStackTrace(); + fail(e.getMessage()); + } } } - super.finished(description); } }