Index: lucene/src/java/org/apache/lucene/util/Constants.java =================================================================== --- lucene/src/java/org/apache/lucene/util/Constants.java (revision 1201662) +++ lucene/src/java/org/apache/lucene/util/Constants.java (working copy) @@ -28,13 +28,20 @@ /** The value of System.getProperty("java.version"). **/ public static final String JAVA_VERSION = System.getProperty("java.version"); - /** True iff this is Java version 1.1. */ + + /** True iff this is Java version 1.1. + * @deprecated This constant is useless since Lucene is on Java 5 */ + @Deprecated public static final boolean JAVA_1_1 = JAVA_VERSION.startsWith("1.1."); - /** True iff this is Java version 1.2. */ + /** True iff this is Java version 1.2. + * @deprecated This constant is useless since Lucene is on Java 5 */ + @Deprecated public static final boolean JAVA_1_2 = JAVA_VERSION.startsWith("1.2."); - /** True iff this is Java version 1.3. */ + /** True iff this is Java version 1.3. + * @deprecated This constant is useless since Lucene is on Java 5 */ + @Deprecated public static final boolean JAVA_1_3 = JAVA_VERSION.startsWith("1.3."); - + /** The value of System.getProperty("os.name"). **/ public static final String OS_NAME = System.getProperty("os.name"); /** True iff running on Linux. */ @@ -50,11 +57,13 @@ 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; + public static final boolean JRE_IS_MINIMUM_JAVA6; + 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 +73,24 @@ JRE_IS_64BIT = false; } } + + // this method only exists in Java 6: + boolean v6 = true; + try { + String.class.getMethod("isEmpty"); + } catch (NoSuchMethodException nsme) { + v6 = false; + } + JRE_IS_MINIMUM_JAVA6 = v6; + + // 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, Index: lucene/src/test/org/apache/lucene/util/TestIOUtils.java =================================================================== --- lucene/src/test/org/apache/lucene/util/TestIOUtils.java (revision 1201662) +++ lucene/src/test/org/apache/lucene/util/TestIOUtils.java (working copy) @@ -44,15 +44,7 @@ } 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 @@ 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 @@ 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")); }