You are viewing a plain text version of this content. The canonical link for it is here.
Posted to derby-commits@db.apache.org by ka...@apache.org on 2013/06/14 16:05:04 UTC
svn commit: r1493077 - in /db/derby/code/trunk/java:
engine/org/apache/derby/jdbc/ engine/org/apache/derby/loc/
shared/org/apache/derby/shared/common/reference/
testing/org/apache/derbyTesting/functionTests/tests/engine/
Author: kahatlen
Date: Fri Jun 14 14:05:03 2013
New Revision: 1493077
URL: http://svn.apache.org/r1493077
Log:
DERBY-6224: Many test failures on latest JDK 8 EA build because of missing SQLPermission
Continue shutdown if deregistering fails, and report the failure in derby.log.
Added:
db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/engine/ShutdownWithoutDeregisterPermissionTest.java (with props)
db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/engine/noDeregisterPermission.policy
- copied, changed from r1492446, db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/util/derby_tests.policy
Modified:
db/derby/code/trunk/java/engine/org/apache/derby/jdbc/AutoloadedDriver.java
db/derby/code/trunk/java/engine/org/apache/derby/loc/messages.xml
db/derby/code/trunk/java/shared/org/apache/derby/shared/common/reference/MessageId.java
db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/engine/_Suite.java
Modified: db/derby/code/trunk/java/engine/org/apache/derby/jdbc/AutoloadedDriver.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/jdbc/AutoloadedDriver.java?rev=1493077&r1=1493076&r2=1493077&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/jdbc/AutoloadedDriver.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/jdbc/AutoloadedDriver.java Fri Jun 14 14:05:03 2013
@@ -28,7 +28,7 @@ import java.sql.DriverPropertyInfo;
import java.sql.SQLException;
import java.sql.SQLFeatureNotSupportedException;
-import java.io.PrintStream;
+import java.security.AccessControlException;
import java.security.AccessController;
import java.security.PrivilegedActionException;
import java.security.PrivilegedExceptionAction;
@@ -36,11 +36,10 @@ import java.util.Properties;
import java.util.logging.Logger;
import org.apache.derby.iapi.reference.MessageId;
-import org.apache.derby.iapi.reference.Attribute;
import org.apache.derby.iapi.reference.SQLState;
import org.apache.derby.iapi.services.i18n.MessageService;
import org.apache.derby.iapi.services.sanity.SanityManager;
-import org.apache.derby.iapi.jdbc.JDBCBoot;
+import org.apache.derby.iapi.services.monitor.Monitor;
import org.apache.derby.impl.jdbc.Util;
@@ -294,6 +293,14 @@ public class AutoloadedDriver implements
});
} catch (PrivilegedActionException pae) {
throw (SQLException) pae.getCause();
+ } catch (AccessControlException ace) {
+ // Since no permission was needed for deregisterDriver() before
+ // Java 8, applications may be surprised to find that engine
+ // shutdown fails because of it. For backward compatibility,
+ // don't fail shutdown if the permission is missing. Instead,
+ // log a message saying the driver could not be deregistered.
+ Monitor.logTextMessage(MessageId.CONN_DEREGISTER_NOT_PERMITTED);
+ Monitor.logThrowable(ace);
}
}
Modified: db/derby/code/trunk/java/engine/org/apache/derby/loc/messages.xml
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/loc/messages.xml?rev=1493077&r1=1493076&r2=1493077&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/loc/messages.xml (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/loc/messages.xml Fri Jun 14 14:05:03 2013
@@ -8222,6 +8222,11 @@ Shutting down instance {0} on database d
<text>There was an XA transaction associated with the connection being closed. The transaction is going to be rolled back. The transaction Xid is {0}.</text>
<arg>transactionXid</arg>
</msg>
+
+ <msg>
+ <name>J137</name>
+ <text>Could not deregister the JDBC driver when shutting down the Derby engine. Make sure SQLPermission("deregisterDriver") is granted to derby.jar.</text>
+ </msg>
</family>
Modified: db/derby/code/trunk/java/shared/org/apache/derby/shared/common/reference/MessageId.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/shared/org/apache/derby/shared/common/reference/MessageId.java?rev=1493077&r1=1493076&r2=1493077&view=diff
==============================================================================
--- db/derby/code/trunk/java/shared/org/apache/derby/shared/common/reference/MessageId.java (original)
+++ db/derby/code/trunk/java/shared/org/apache/derby/shared/common/reference/MessageId.java Fri Jun 14 14:05:03 2013
@@ -174,6 +174,9 @@ public interface MessageId {
String CONN_XA_TRANSACTION_TIMED_OUT = "J135";
String CONN_CLOSE_XA_TRANSACTION_ROLLED_BACK = "J136";
+ /** Shutdown couldn't deregister driver because of missing permission. */
+ String CONN_DEREGISTER_NOT_PERMITTED = "J137";
+
/*
** Authentication
*/
Added: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/engine/ShutdownWithoutDeregisterPermissionTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/engine/ShutdownWithoutDeregisterPermissionTest.java?rev=1493077&view=auto
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/engine/ShutdownWithoutDeregisterPermissionTest.java (added)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/engine/ShutdownWithoutDeregisterPermissionTest.java Fri Jun 14 14:05:03 2013
@@ -0,0 +1,83 @@
+/*
+
+ Derby - Class org.apache.derbyTesting.functionTests.tests.engine.ShutdownWithoutDeregisterPermissionTest
+
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+
+ */
+
+package org.apache.derbyTesting.functionTests.tests.engine;
+
+import java.sql.Driver;
+import java.sql.DriverManager;
+import java.sql.SQLException;
+import java.util.Enumeration;
+import junit.framework.Test;
+import org.apache.derbyTesting.junit.BaseJDBCTestCase;
+import org.apache.derbyTesting.junit.JDBC;
+import org.apache.derbyTesting.junit.SecurityManagerSetup;
+import org.apache.derbyTesting.junit.TestConfiguration;
+
+/**
+ * Test that shutdown works even if derby.jar does not have permission to
+ * deregister the JDBC driver. Regression test case for DERBY-6224.
+ */
+public class ShutdownWithoutDeregisterPermissionTest extends BaseJDBCTestCase {
+ public ShutdownWithoutDeregisterPermissionTest(String name) {
+ super(name);
+ }
+
+ public static Test suite() {
+ return new SecurityManagerSetup(
+ TestConfiguration.embeddedSuite(
+ ShutdownWithoutDeregisterPermissionTest.class),
+ "org/apache/derbyTesting/functionTests/tests/engine/" +
+ "noDeregisterPermission.policy");
+ }
+
+ public void testShutdownWithoutPermission() throws SQLException {
+ // First get a connection to make sure the engine is booted.
+ getConnection().close();
+
+ // Shut down the engine. This used to fail with an
+ // AccessControlException on Java 8 before DERBY-6224.
+ TestConfiguration config = TestConfiguration.getCurrent();
+ config.shutdownEngine();
+
+ // Test whether shutdown deregistered the driver. On versions prior
+ // to Java 8/JDBC 4.2, we expect the driver to be deregistered even
+ // though the permission is missing, and the call to getDrivers()
+ // should not return any instance of AutoloadedDriver.
+ // On Java 8/JDBC 4.2 and higher, we expect AutoloadedDriver to
+ // be in the list of registered drivers.
+
+ Enumeration<Driver> drivers = DriverManager.getDrivers();
+ Driver found = null;
+ while (found == null && drivers.hasMoreElements()) {
+ Driver driver = drivers.nextElement();
+ if (driver.getClass().getName().startsWith(
+ "org.apache.derby.jdbc.AutoloadedDriver")) {
+ found = driver;
+ }
+ }
+
+ if (JDBC.vmSupportsJDBC42()) {
+ assertNotNull("Expected driver to be registered", found);
+ } else {
+ assertNull("Expected driver to be deregistered", found);
+ }
+ }
+}
Propchange: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/engine/ShutdownWithoutDeregisterPermissionTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/engine/_Suite.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/engine/_Suite.java?rev=1493077&r1=1493076&r2=1493077&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/engine/_Suite.java (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/engine/_Suite.java Fri Jun 14 14:05:03 2013
@@ -53,6 +53,7 @@ public class _Suite extends BaseTestCase
suite.addTest(RestrictiveFilePermissionsTest.suite());
suite.addTest(ModuleLoadingTest.suite());
suite.addTest(ReadMeFilesTest.suite());
+ suite.addTest(ShutdownWithoutDeregisterPermissionTest.suite());
return suite;
}
Copied: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/engine/noDeregisterPermission.policy (from r1492446, db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/util/derby_tests.policy)
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/engine/noDeregisterPermission.policy?p2=db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/engine/noDeregisterPermission.policy&p1=db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/util/derby_tests.policy&r1=1492446&r2=1493077&rev=1493077&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/util/derby_tests.policy (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/engine/noDeregisterPermission.policy Fri Jun 14 14:05:03 2013
@@ -1,5 +1,5 @@
//
-// * Derby - Class org.apache.derbyTesting.functionTests.util.derby_tests.policy
+// * Derby - Class org.apache.derbyTesting.functionTests.tests.engine.noDeregisterPermission.policy
// *
// * Licensed to the Apache Software Foundation (ASF) under one
// * or more contributor license agreements. See the NOTICE file
@@ -20,27 +20,9 @@
// *
//
-// Policy file with minimal set of permissions to run derby's
-// functional tests.
+// Copy of derby_tests.policy except that the permission to invoke
+// java.sql.DriverManager.deregisterDriver() is not granted to derby.jar.
//
-// The test harness sets up four variables used by this policy file
-//
-// derbyTesting.codejar - URL to the jar files when they are in the classpath
-// derbyTesting.codeclasses - URL to the classes directory when it is in the classpath
-//
-// Only one of derbyTesting.codejar and derbyTesting.codeclasses will be valid, the
-// other will be set to a bogus URL like file://unused
-//
-// derbyTesting.codedir - File location of either derbyTesting.codejar or derbyTesting.codeclasses.
-// Only required due to a BUG (see below for more info).
-//
-// derbyTesting.jaxpjar - URL to the jar file containing the JAXP implementation
-// for XML-based tests (ex. lang/XMLBindingTest.java).
-//
-// derbyTesting.serverhost - Host name or ip where network server is started
-// derbyTesting.clienthost - specifies the clients ip address/hostName.
-// when testing with networkserver on a remote host, this needs to be passed in
-// with the NetworkServerControl start command
//
// Permissions for the embedded engine (derby.jar)
@@ -138,8 +120,9 @@ grant codeBase "${derbyTesting.codejar}d
permission java.sql.SQLPermission "callAbort";
// This permission is needed to call DriverManager.deregisterDriver()
- // on Java SE 8 and later.
- permission java.sql.SQLPermission "deregisterDriver";
+ // on Java SE 8 and later. Not granted by this policy, so that we can
+ // test that Derby handles the lack of the permission gracefully.
+ //permission java.sql.SQLPermission "deregisterDriver";
};
//
@@ -369,8 +352,9 @@ grant codeBase "${derbyTesting.codeclass
permission java.lang.RuntimePermission "getFileStoreAttributes";
// This permission is needed to call DriverManager.deregisterDriver()
- // on Java SE 8 and later.
- permission java.sql.SQLPermission "deregisterDriver";
+ // on Java SE 8 and later. Not granted by this policy, so that we can
+ // test that Derby handles the lack of the permission gracefully.
+ //permission java.sql.SQLPermission "deregisterDriver";
};
// JUnit jar file tries to read junit.properties in the user's