db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From krist...@apache.org
Subject svn commit: r1132860 - in /db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit: BaseTestCase.java SecurityManagerSetup.java
Date Tue, 07 Jun 2011 04:39:11 GMT
Author: kristwaa
Date: Tue Jun  7 04:39:11 2011
New Revision: 1132860

URL: http://svn.apache.org/viewvc?rev=1132860&view=rev
Log:
DERBY-5262: Running JUnit tests with Java 1.4.2 fails if the package private tests are on
the classpath 

Check that the running JVM can support Java 1.5 class files before trying to
load the package private file (which are compiled with Java 1.5) when setting
up the security manager for tests.

Patch file: derby-5262-1a-secmansetup_check_class_version.diff


Modified:
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/BaseTestCase.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/SecurityManagerSetup.java

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/BaseTestCase.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/BaseTestCase.java?rev=1132860&r1=1132859&r2=1132860&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/BaseTestCase.java (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/BaseTestCase.java Tue Jun
 7 04:39:11 2011
@@ -625,6 +625,36 @@ public abstract class BaseTestCase
     }
    
     /**
+     * Returns the major version of the class specification version supported
+     * by the running JVM.
+     * <ul>
+     *  <li>48 = Java 1.4</li>
+     *  <li>49 = Java 1.5</li>
+     *  <li>50 = Java 1.6</li>
+     *  <li>51 = Java 1.7</li>
+     * </ul>
+     *
+     * @return Major version of class version specification, i.e. 49 for 49.0,
+     *      or -1 if the version can't be obtained for some reason.
+     */
+    public static int getClassVersionMajor() {
+        String tmp = getSystemProperty("java.class.version");
+        if (tmp == null) {
+            println("VM doesn't have property java.class.version");
+            return -1;
+        }
+        // Is String.split safe to use by now?
+        int dot = tmp.indexOf('.');
+        int major = -1;
+        try {
+            major = Integer.parseInt(tmp.substring(0, dot));
+        } catch (NumberFormatException nfe) {
+            // Ignore, return -1.
+        }
+        return major;
+    }
+
+    /**
      * Check if we have old style (before Sun Java 1.7) Solaris interruptible
      * IO. On Sun Java 1.5 >= update 22 and Sun Java 1.6 this can be disabled
      * with Java option {@code -XX:-UseVMInterruptibleIO}. On Sun Java 1.7 it

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/SecurityManagerSetup.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/SecurityManagerSetup.java?rev=1132860&r1=1132859&r2=1132860&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/SecurityManagerSetup.java
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/SecurityManagerSetup.java
Tue Jun  7 04:39:11 2011
@@ -291,8 +291,12 @@ public final class SecurityManagerSetup 
             classPathSet.setProperty("derbyTesting.jaxpjar", jaxp);
 
 		URL testing = getURL(SecurityManagerSetup.class);
-        URL ppTesting = getURL("org.apache.derby.PackagePrivateTestSuite");
-		
+        URL ppTesting = null;
+        // Only try to load PackagePrivateTestSuite if the running JVM is
+        // Java 1.5 or newer (class version 49 = Java 1.5).
+        if (BaseTestCase.getClassVersionMajor() >= 49) {
+            ppTesting = getURL("org.apache.derby.PackagePrivateTestSuite");
+        }
 		boolean isClasspath = testing.toExternalForm().endsWith("/");
 		if (isClasspath) {
 			classPathSet.setProperty("derbyTesting.codeclasses",



Mime
View raw message