diff --git a/lucene/common-build.xml b/lucene/common-build.xml index e191d949c03..7d2483ca054 100644 --- a/lucene/common-build.xml +++ b/lucene/common-build.xml @@ -329,20 +329,45 @@ + + + + + + + + + + + + + + + + + - - + + + + + + - - - - - + + + @@ -362,7 +387,9 @@ - + + + @@ -379,9 +406,11 @@ - + - + + + @@ -1824,7 +1853,10 @@ ${ant.project.name}.test.dependencies=${test.classpath.list} - + + + + diff --git a/lucene/core/src/java/org/apache/lucene/util/Constants.java b/lucene/core/src/java/org/apache/lucene/util/Constants.java index ec703d9d6b2..4d767081570 100644 --- a/lucene/core/src/java/org/apache/lucene/util/Constants.java +++ b/lucene/core/src/java/org/apache/lucene/util/Constants.java @@ -18,7 +18,8 @@ package org.apache.lucene.util; */ import java.lang.reflect.Field; -import java.util.Collections; +import java.util.StringTokenizer; + /** * Some useful constants. @@ -31,6 +32,7 @@ public final class Constants { public static final String JVM_VENDOR = System.getProperty("java.vm.vendor"); public static final String JVM_VERSION = System.getProperty("java.vm.version"); public static final String JVM_NAME = System.getProperty("java.vm.name"); + public static final String JVM_SPEC_VERSION = System.getProperty("java.specification.version"); /** The value of System.getProperty("java.version"). **/ public static final String JAVA_VERSION = System.getProperty("java.version"); @@ -51,13 +53,21 @@ public final class Constants { public static final String OS_ARCH = System.getProperty("os.arch"); public static final String OS_VERSION = System.getProperty("os.version"); public static final String JAVA_VENDOR = System.getProperty("java.vendor"); - - public static final boolean JRE_IS_MINIMUM_JAVA8; + private static final int JVM_MAJOR_VERSION; + private static final int JVM_MINOR_VERSION; + /** True iff running on a 64bit JVM */ public static final boolean JRE_IS_64BIT; static { + final StringTokenizer st = new StringTokenizer(JVM_SPEC_VERSION, "."); + JVM_MAJOR_VERSION = Integer.parseInt(st.nextToken()); + if (st.hasMoreTokens()) { + JVM_MINOR_VERSION = Integer.parseInt(st.nextToken()); + } else { + JVM_MINOR_VERSION = 0; + } boolean is64Bit = false; try { final Class unsafeClass = Class.forName("sun.misc.Unsafe"); @@ -81,16 +91,10 @@ public final class Constants { } } JRE_IS_64BIT = is64Bit; - - // 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; } + + public static final boolean JRE_IS_MINIMUM_JAVA8 = JVM_MAJOR_VERSION > 1 || (JVM_MAJOR_VERSION == 1 && JVM_MINOR_VERSION >= 8); + public static final boolean JRE_IS_MINIMUM_JAVA9 = JVM_MAJOR_VERSION > 1 || (JVM_MAJOR_VERSION == 1 && JVM_MINOR_VERSION >= 9); /** * This is the internal Lucene version, including bugfix versions, recorded into each segment.