Apache Lucene open-source search software
Allow detecting of Java 8
Uwe Schindler4a54cc8b169f
diff --git a/lucene/core/src/java/org/apache/lucene/util/Constants.java b/lucene/core/src/java/org/apache/lucene/util/Constants.javaindex 4ac00bd753c..f44a5f4b6f9 100644--- a/lucene/core/src/java/org/apache/lucene/util/Constants.java+++ b/lucene/core/src/java/org/apache/lucene/util/Constants.java@@ -18,6 +18,7 @@ package org.apache.lucene.util;*/import java.lang.reflect.Field;+import java.util.Collections;import org.apache.lucene.LucenePackage;/**@@ -56,6 +57,7 @@ public final class Constants {new Boolean(true).booleanValue(); // prevent inlining in foreign class filespublic static final boolean JRE_IS_MINIMUM_JAVA7;+ public static final boolean JRE_IS_MINIMUM_JAVA8;/** True iff running on a 64bit JVM */public static final boolean JRE_IS_64BIT;@@ -93,6 +95,19 @@ public final class Constants {v7 = false;}JRE_IS_MINIMUM_JAVA7 = v7;++ if (JRE_IS_MINIMUM_JAVA7) {+ // this method only exists in Java 8:+ boolean v8 = true;+ try {+ Collections.class.getMethod("emptySortedSet");+ } catch (NoSuchMethodException nsme) {+ v8 = false;+ }+ JRE_IS_MINIMUM_JAVA8 = v8;+ } else {+ JRE_IS_MINIMUM_JAVA8 = false;+ }}// this method prevents inlining the final version constant in compiled classes,diff --git a/solr/core/src/test/org/apache/solr/handler/component/SpellCheckComponentTest.java b/solr/core/src/test/org/apache/solr/handler/component/SpellCheckComponentTest.javaindex 634015dc454..77dbf1ab95e 100644--- a/solr/core/src/test/org/apache/solr/handler/component/SpellCheckComponentTest.java+++ b/solr/core/src/test/org/apache/solr/handler/component/SpellCheckComponentTest.java@@ -20,6 +20,7 @@ package org.apache.solr.handler.component;import java.io.File;import java.util.*;+import org.apache.lucene.util.Constants;import org.apache.lucene.util.LuceneTestCase.Slow;import org.apache.solr.SolrTestCaseJ4;import org.apache.solr.common.params.CommonParams;@@ -35,7 +36,6 @@ import org.apache.solr.response.SolrQueryResponse;import org.apache.solr.spelling.AbstractLuceneSpellChecker;import org.apache.solr.spelling.SolrSpellChecker;import org.junit.BeforeClass;-import org.junit.Ignore;import org.junit.Test;/**@@ -99,8 +99,8 @@ public class SpellCheckComponentTest extends SolrTestCaseJ4 {@Test- @Ignore("This test fails in most cases with Java 8+, looks like it depends on order of some HashSet/HashMap whatever")public void testPerDictionary() throws Exception {+ assumeFalse("This test fails in most cases with Java 8+, looks like it depends on order of some HashSet/HashMap whatever", Constants.JRE_IS_MINIMUM_JAVA8);assertJQ(req("json.nl","map", "qt",rh, SpellCheckComponent.COMPONENT_NAME, "true", SpellingParams.SPELLCHECK_BUILD, "true", "q","documemt", SpellingParams.SPELLCHECK_DICT, "perDict", SpellingParams.SPELLCHECK_PREFIX + ".perDict.foo", "bar", SpellingParams.SPELLCHECK_PREFIX + ".perDict.bar", "foo"),"/spellcheck/suggestions/bar=={'numFound':1, 'startOffset':0, 'endOffset':1, 'suggestion':['foo']}"