db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kahat...@apache.org
Subject svn commit: r1495035 - in /db/derby/code/branches/10.8: ./ java/client/org/apache/derby/client/net/ java/drda/org/apache/derby/impl/drda/ java/engine/org/apache/derby/jdbc/ java/engine/org/apache/derby/loc/ java/shared/org/apache/derby/shared/common/re...
Date Thu, 20 Jun 2013 14:54:21 GMT
Author: kahatlen
Date: Thu Jun 20 14:54:20 2013
New Revision: 1495035

URL: http://svn.apache.org/r1495035
Log:
DERBY-6224: Many test failures on latest JDK 8 EA build because of missing SQLPermission

Merged revisions 1490291 and 1494947 from 10.9.

Added:
    db/derby/code/branches/10.8/java/testing/org/apache/derbyTesting/functionTests/tests/engine/ShutdownWithoutDeregisterPermissionTest.java
      - copied unchanged from r1494947, db/derby/code/branches/10.9/java/testing/org/apache/derbyTesting/functionTests/tests/engine/ShutdownWithoutDeregisterPermissionTest.java
    db/derby/code/branches/10.8/java/testing/org/apache/derbyTesting/functionTests/tests/engine/noDeregisterPermission.policy
      - copied unchanged from r1494947, db/derby/code/branches/10.9/java/testing/org/apache/derbyTesting/functionTests/tests/engine/noDeregisterPermission.policy
Modified:
    db/derby/code/branches/10.8/   (props changed)
    db/derby/code/branches/10.8/java/client/org/apache/derby/client/net/NetCursor.java   (props
changed)
    db/derby/code/branches/10.8/java/drda/org/apache/derby/impl/drda/NetworkServerControlImpl.java
    db/derby/code/branches/10.8/java/engine/org/apache/derby/jdbc/AutoloadedDriver.java
    db/derby/code/branches/10.8/java/engine/org/apache/derby/loc/messages.xml
    db/derby/code/branches/10.8/java/shared/org/apache/derby/shared/common/reference/MessageId.java
    db/derby/code/branches/10.8/java/testing/org/apache/derbyTesting/functionTests/tests/derbynet/ServerPropertiesTest.policy
    db/derby/code/branches/10.8/java/testing/org/apache/derbyTesting/functionTests/tests/engine/_Suite.java
    db/derby/code/branches/10.8/java/testing/org/apache/derbyTesting/functionTests/tests/engine/build.xml
    db/derby/code/branches/10.8/java/testing/org/apache/derbyTesting/functionTests/util/derby_tests.policy

Propchange: db/derby/code/branches/10.8/
------------------------------------------------------------------------------
  Merged /db/derby/code/branches/10.9:r1490291,1494947
  Merged /db/derby/code/trunk:r1488125,1493077
  Merged /db/derby/code/branches/10.10:r1494758,1494888

Propchange: db/derby/code/branches/10.8/java/client/org/apache/derby/client/net/NetCursor.java
------------------------------------------------------------------------------
  Merged /db/derby/code/branches/10.9/java/client/org/apache/derby/client/net/NetCursor.java:r1490291,1494947

Modified: db/derby/code/branches/10.8/java/drda/org/apache/derby/impl/drda/NetworkServerControlImpl.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.8/java/drda/org/apache/derby/impl/drda/NetworkServerControlImpl.java?rev=1495035&r1=1495034&r2=1495035&view=diff
==============================================================================
--- db/derby/code/branches/10.8/java/drda/org/apache/derby/impl/drda/NetworkServerControlImpl.java
(original)
+++ db/derby/code/branches/10.8/java/drda/org/apache/derby/impl/drda/NetworkServerControlImpl.java
Thu Jun 20 14:54:20 2013
@@ -910,7 +910,14 @@ public final class NetworkServerControlI
 						if (passwordArg != null) {
 							p.setProperty("password", passwordArg);
 						}
-						cloudscapeDriver.connect("jdbc:derby:;shutdown=true", p);
+                        // DERBY-6224: DriverManager.deregisterDriver() requires
+                        // an extra permission in JDBC 4.2 and later. Invoke
+                        // system shutdown with deregister=false to avoid the
+                        // need for the extre permission in the default server
+                        // policy. Since the JVM is about to terminate, we don't
+                        // care whether the JDBC driver is deregistered.
+                        cloudscapeDriver.connect(
+                            "jdbc:derby:;shutdown=true;deregister=false", p);
 					}
 				} catch (SQLException sqle) {
 					// If we can't shutdown Derby, perhaps, authentication has

Modified: db/derby/code/branches/10.8/java/engine/org/apache/derby/jdbc/AutoloadedDriver.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.8/java/engine/org/apache/derby/jdbc/AutoloadedDriver.java?rev=1495035&r1=1495034&r2=1495035&view=diff
==============================================================================
--- db/derby/code/branches/10.8/java/engine/org/apache/derby/jdbc/AutoloadedDriver.java (original)
+++ db/derby/code/branches/10.8/java/engine/org/apache/derby/jdbc/AutoloadedDriver.java Thu
Jun 20 14:54:20 2013
@@ -27,14 +27,16 @@ import java.sql.Connection;
 import java.sql.DriverPropertyInfo;
 import java.sql.SQLException;
 
-import java.io.PrintStream;
+import java.security.AccessControlException;
+import java.security.AccessController;
+import java.security.PrivilegedActionException;
+import java.security.PrivilegedExceptionAction;
 import java.util.Properties;
 
 import org.apache.derby.iapi.reference.MessageId;
-import org.apache.derby.iapi.reference.Attribute;
 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;
 
 
 /**
@@ -62,7 +64,7 @@ public class AutoloadedDriver implements
 	
 
     // This is the driver that memorizes the autoloadeddriver (DERBY-2905)
-    private static Driver _autoloadedDriver;
+    private static AutoloadedDriver _autoloadedDriver;
 
     // This flag is true unless the deregister attribute has been set to
     // false by the user (DERBY-2905)
@@ -249,20 +251,47 @@ public class AutoloadedDriver implements
         try {
             // deregister is false if user set deregister=false attribute (DERBY-2905)
             if (deregister && _autoloadedDriver != null) {
-                DriverManager.deregisterDriver(_autoloadedDriver);
+                deregisterDriver(_autoloadedDriver);
                 _autoloadedDriver = null;
-            } else {
-                DriverManager.deregisterDriver(_driverModule);
-                //DERBY 5085, need to restore the default value
-                deregister = true;
             }
+
+            // DERBY-5085, need to restore the default value
+            deregister = true;
+
             _driverModule = null;
         } catch (SQLException e) {
             if (SanityManager.DEBUG)
                 SanityManager.THROWASSERT(e);
         }
 	}
-	
+
+    private static void deregisterDriver(final AutoloadedDriver driver)
+            throws SQLException {
+        // DERBY-6224: DriverManager.deregisterDriver() requires a special
+        // permission in JDBC 4.2 and later. Call it in a privileged block
+        // so that the permission doesn't have to be granted to code that
+        // invokes engine shutdown.
+        try {
+            AccessController.doPrivileged(
+                    new PrivilegedExceptionAction() {
+                public Object run() throws SQLException {
+                    // Requires SQLPermission("deregisterDriver")
+                    DriverManager.deregisterDriver(driver);
+                    return null;
+                }
+            });
+        } 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);
+        }
+    }
 
 	/*
 	** Return true if the engine has been booted.

Modified: db/derby/code/branches/10.8/java/engine/org/apache/derby/loc/messages.xml
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.8/java/engine/org/apache/derby/loc/messages.xml?rev=1495035&r1=1495034&r2=1495035&view=diff
==============================================================================
--- db/derby/code/branches/10.8/java/engine/org/apache/derby/loc/messages.xml (original)
+++ db/derby/code/branches/10.8/java/engine/org/apache/derby/loc/messages.xml Thu Jun 20 14:54:20
2013
@@ -7955,6 +7955,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/branches/10.8/java/shared/org/apache/derby/shared/common/reference/MessageId.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.8/java/shared/org/apache/derby/shared/common/reference/MessageId.java?rev=1495035&r1=1495034&r2=1495035&view=diff
==============================================================================
--- db/derby/code/branches/10.8/java/shared/org/apache/derby/shared/common/reference/MessageId.java
(original)
+++ db/derby/code/branches/10.8/java/shared/org/apache/derby/shared/common/reference/MessageId.java
Thu Jun 20 14:54:20 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
 	*/

Modified: db/derby/code/branches/10.8/java/testing/org/apache/derbyTesting/functionTests/tests/derbynet/ServerPropertiesTest.policy
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.8/java/testing/org/apache/derbyTesting/functionTests/tests/derbynet/ServerPropertiesTest.policy?rev=1495035&r1=1495034&r2=1495035&view=diff
==============================================================================
--- db/derby/code/branches/10.8/java/testing/org/apache/derbyTesting/functionTests/tests/derbynet/ServerPropertiesTest.policy
(original)
+++ db/derby/code/branches/10.8/java/testing/org/apache/derbyTesting/functionTests/tests/derbynet/ServerPropertiesTest.policy
Thu Jun 20 14:54:20 2013
@@ -88,6 +88,10 @@ grant codeBase "${derbyTesting.codejar}d
   // might not be unregistered from the MBean server. See DERBY-3561.
   permission javax.management.MBeanPermission "org.apache.derby.*#[org.apache.derby:*]","unregisterMBean";
 
+
+  // This permission is needed to call DriverManager.deregisterDriver()
+  // on Java SE 8 and later.
+  permission java.sql.SQLPermission "deregisterDriver";
 };
 
 //
@@ -227,6 +231,10 @@ grant codeBase "${derbyTesting.codeclass
   // may be testing JMX functionality. Without this permission, old MBeans
   // might not be unregistered from the MBean server. See DERBY-3561.
   permission javax.management.MBeanPermission "org.apache.derby.*#[org.apache.derby:*]","unregisterMBean";
+
+  // This permission is needed to call DriverManager.deregisterDriver()
+  // on Java SE 8 and later.
+  permission java.sql.SQLPermission "deregisterDriver";
 };
 
 // JUnit jar file tries to read junit.properties in the user's

Modified: db/derby/code/branches/10.8/java/testing/org/apache/derbyTesting/functionTests/tests/engine/_Suite.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.8/java/testing/org/apache/derbyTesting/functionTests/tests/engine/_Suite.java?rev=1495035&r1=1495034&r2=1495035&view=diff
==============================================================================
--- db/derby/code/branches/10.8/java/testing/org/apache/derbyTesting/functionTests/tests/engine/_Suite.java
(original)
+++ db/derby/code/branches/10.8/java/testing/org/apache/derbyTesting/functionTests/tests/engine/_Suite.java
Thu Jun 20 14:54:20 2013
@@ -24,6 +24,7 @@ package org.apache.derbyTesting.function
 import junit.framework.Test;
 import junit.framework.TestSuite;
 import org.apache.derbyTesting.junit.BaseTestCase;
+import org.apache.derbyTesting.junit.JDBC;
 
 /**
  * Suite to run all JUnit tests in this package:
@@ -49,6 +50,10 @@ public class _Suite extends BaseTestCase
         suite.addTest(ErrorStreamTest.suite());
         suite.addTest(LockInterruptTest.suite());
         suite.addTest(ModuleLoadingTest.suite());
+        if (JDBC.vmSupportsJDBC3()) {
+            // Test that requires DriverManager.
+            suite.addTest(ShutdownWithoutDeregisterPermissionTest.suite());
+        }
 
         return suite;
     }

Modified: db/derby/code/branches/10.8/java/testing/org/apache/derbyTesting/functionTests/tests/engine/build.xml
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.8/java/testing/org/apache/derbyTesting/functionTests/tests/engine/build.xml?rev=1495035&r1=1495034&r2=1495035&view=diff
==============================================================================
--- db/derby/code/branches/10.8/java/testing/org/apache/derbyTesting/functionTests/tests/engine/build.xml
(original)
+++ db/derby/code/branches/10.8/java/testing/org/apache/derbyTesting/functionTests/tests/engine/build.xml
Thu Jun 20 14:54:20 2013
@@ -65,7 +65,7 @@
     <mkdir dir="${out.dir}/${derby.testing.functest.dir}/tests/engine"/>
   </target>
 
-  <target name="compilet1" >
+  <target name="compilet1" depends="compile_jdk14">
      <javac
         source="1.4"
         target="1.4"
@@ -84,9 +84,33 @@
            <pathelement path="${junit}"/>
         </classpath>
         <include name="${this.dir}/*.java"/>
+        <exclude name="${this.dir}/ShutdownWithoutDeregisterPermissionTest.java"/>
      </javac>
   </target>
 
+  <target name="compile_jdk14">
+     <javac
+        source="1.4"
+        target="1.4"
+        bootclasspath="${empty}"
+        nowarn="on"
+        debug="true"
+        depend="${depend}"
+        deprecation="${deprecation}"
+        optimize="${optimize}"
+        proceed="${proceed}"
+        verbose="${verbose}"
+        srcdir="${derby.testing.src.dir}"
+        destdir="${out.dir}">
+        <classpath>
+           <pathelement path="${java14compile.classpath}"/>
+           <pathelement path="${junit}"/>
+        </classpath>
+        <include name="${this.dir}/ShutdownWithoutDeregisterPermissionTest.java"/>
+     </javac>
+  </target>
+
+
   <target name="copyfiles">
     <copy todir="${out.dir}/${derby.testing.functest.dir}/tests/engine">
       <fileset dir="${derby.testing.src.dir}/${derby.testing.functest.dir}/tests/engine"

Modified: db/derby/code/branches/10.8/java/testing/org/apache/derbyTesting/functionTests/util/derby_tests.policy
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.8/java/testing/org/apache/derbyTesting/functionTests/util/derby_tests.policy?rev=1495035&r1=1495034&r2=1495035&view=diff
==============================================================================
--- db/derby/code/branches/10.8/java/testing/org/apache/derbyTesting/functionTests/util/derby_tests.policy
(original)
+++ db/derby/code/branches/10.8/java/testing/org/apache/derbyTesting/functionTests/util/derby_tests.policy
Thu Jun 20 14:54:20 2013
@@ -136,6 +136,10 @@ grant codeBase "${derbyTesting.codejar}d
 
   // This permission is needed to call the Connection.abort(Executor) method added by JDBC
4.1
   permission java.sql.SQLPermission "callAbort";
+
+  // This permission is needed to call DriverManager.deregisterDriver()
+  // on Java SE 8 and later.
+  permission java.sql.SQLPermission "deregisterDriver";
 };
 
 //
@@ -335,6 +339,9 @@ grant codeBase "${derbyTesting.codeclass
   permission org.apache.derby.security.SystemPermission "jmx", "control";
   permission org.apache.derby.security.SystemPermission "engine", "monitor";
   permission org.apache.derby.security.SystemPermission "server", "control,monitor";
+  // This permission is needed to call DriverManager.deregisterDriver()
+  // on Java SE 8 and later.
+  permission java.sql.SQLPermission "deregisterDriver";
 };
 
 // JUnit jar file tries to read junit.properties in the user's



Mime
View raw message