You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by gu...@apache.org on 2020/02/28 21:24:11 UTC

[lucene-solr] branch branch_8x updated: SOLR-14283 ensure that the test only runs on JVM's where it can succeeed

This is an automated email from the ASF dual-hosted git repository.

gus pushed a commit to branch branch_8x
in repository https://gitbox.apache.org/repos/asf/lucene-solr.git


The following commit(s) were added to refs/heads/branch_8x by this push:
     new f083067  SOLR-14283 ensure that the test only runs on JVM's where it can succeeed
f083067 is described below

commit f0830673281d9caee135140131a47f864acb4be2
Author: Gus Heck <gu...@apache.org>
AuthorDate: Fri Feb 28 14:20:35 2020 -0500

    SOLR-14283 ensure that the test only runs on JVM's where it can succeeed
---
 .../test/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 e3dff56..563a753 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);
   }
 }