Skip to content

Apache Lucene open-source search software

Merged revision(s) 1201739 from lucene/dev/branches/branch_3x: LUCENE-3574: Deprecate outdated constants in org.apache.lucene.util.Constants and add new ones for Java 6 and Java 7

Uwe Schindler627817bed322
diff --git a/lucene/CHANGES.txt b/lucene/CHANGES.txt
index 355f8115973..3e006f9a3d0 100644
--- a/lucene/CHANGES.txt
+++ b/lucene/CHANGES.txt
@@ -735,6 +735,9 @@ API Changes
for multi-segment indexes. They were only needed for tests of
NumericRangeQuery. (Mike McCandless, Uwe Schindler)
+* LUCENE-3574: Deprecate outdated constants in org.apache.lucene.util.Constants
+ and add new ones for Java 6 and Java 7. (Uwe Schindler)
+
New Features
* LUCENE-3448: Added FixedBitSet.and(other/DISI), andNot(other/DISI).
diff --git a/lucene/src/java/org/apache/lucene/util/Constants.java b/lucene/src/java/org/apache/lucene/util/Constants.java
index 3a99ab4b617..814ad430ad4 100644
--- a/lucene/src/java/org/apache/lucene/util/Constants.java
+++ b/lucene/src/java/org/apache/lucene/util/Constants.java
@@ -28,12 +28,6 @@ public final class Constants {
/** The value of <tt>System.getProperty("java.version")<tt>. **/
public static final String JAVA_VERSION = System.getProperty("java.version");
- /** True iff this is Java version 1.1. */
- public static final boolean JAVA_1_1 = JAVA_VERSION.startsWith("1.1.");
- /** True iff this is Java version 1.2. */
- public static final boolean JAVA_1_2 = JAVA_VERSION.startsWith("1.2.");
- /** True iff this is Java version 1.3. */
- public static final boolean JAVA_1_3 = JAVA_VERSION.startsWith("1.3.");
/** The value of <tt>System.getProperty("os.name")<tt>. **/
public static final String OS_NAME = System.getProperty("os.name");
@@ -50,11 +44,16 @@ public final class Constants {
public static final String OS_VERSION = System.getProperty("os.version");
public static final String JAVA_VENDOR = System.getProperty("java.vendor");
- // NOTE: this logic may not be correct; if you know of a
- // more reliable approach please raise it on java-dev!
- public static final boolean JRE_IS_64BIT;
+ /** @deprecated With Lucene 4.0, we are always on Java 6 */
+ @Deprecated
+ public static final boolean JRE_IS_MINIMUM_JAVA6 = true;
+
+ public static final boolean JRE_IS_64BIT;
+ public static final boolean JRE_IS_MINIMUM_JAVA7;
static {
- String x = System.getProperty("sun.arch.data.model");
+ // NOTE: this logic may not be correct; if you know of a
+ // more reliable approach please raise it on java-dev!
+ final String x = System.getProperty("sun.arch.data.model");
if (x != null) {
JRE_IS_64BIT = x.indexOf("64") != -1;
} else {
@@ -64,6 +63,15 @@ public final class Constants {
JRE_IS_64BIT = false;
}
}
+
+ // this method only exists in Java 7:
+ boolean v7 = true;
+ try {
+ Throwable.class.getMethod("getSuppressed");
+ } catch (NoSuchMethodException nsme) {
+ v7 = false;
+ }
+ JRE_IS_MINIMUM_JAVA7 = v7;
}
// this method prevents inlining the final version constant in compiled classes,
diff --git a/lucene/src/test/org/apache/lucene/util/TestIOUtils.java b/lucene/src/test/org/apache/lucene/util/TestIOUtils.java
index 8b7ded80810..904be4f1e72 100644
--- a/lucene/src/test/org/apache/lucene/util/TestIOUtils.java
+++ b/lucene/src/test/org/apache/lucene/util/TestIOUtils.java
@@ -44,15 +44,7 @@ public class TestIOUtils extends LuceneTestCase {
}
public void testSuppressedExceptions() {
- boolean isJava7 = true;
- try {
- // this class only exists in Java 7:
- Class.forName("java.lang.AutoCloseable");
- } catch (ClassNotFoundException cnfe) {
- isJava7 = false;
- }
-
- if (!isJava7) {
+ if (!Constants.JRE_IS_MINIMUM_JAVA7) {
System.err.println("WARNING: TestIOUtils.testSuppressedExceptions: Full test coverage only with Java 7, as suppressed exception recording is not supported before.");
}
@@ -71,7 +63,7 @@ public class TestIOUtils extends LuceneTestCase {
System.out.println("TestIOUtils.testSuppressedExceptions: Thrown Exception stack trace:");
System.out.println(trace);
}
- if (isJava7) {
+ if (Constants.JRE_IS_MINIMUM_JAVA7) {
assertTrue("Stack trace does not contain first suppressed Exception: " + trace,
trace.contains("java.io.IOException: TEST-IO-EXCEPTION-1"));
assertTrue("Stack trace does not contain second suppressed Exception: " + trace,
@@ -97,7 +89,7 @@ public class TestIOUtils extends LuceneTestCase {
System.out.println("TestIOUtils.testSuppressedExceptions: Thrown Exception stack trace:");
System.out.println(trace);
}
- if (isJava7) {
+ if (Constants.JRE_IS_MINIMUM_JAVA7) {
assertTrue("Stack trace does not contain suppressed Exception: " + trace,
trace.contains("java.io.IOException: TEST-IO-EXCEPTION-2"));
}