Return-Path: X-Original-To: apmail-db-derby-commits-archive@www.apache.org Delivered-To: apmail-db-derby-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id CA45E113C5 for ; Fri, 4 Jul 2014 08:33:54 +0000 (UTC) Received: (qmail 46678 invoked by uid 500); 4 Jul 2014 08:33:54 -0000 Delivered-To: apmail-db-derby-commits-archive@db.apache.org Received: (qmail 46648 invoked by uid 500); 4 Jul 2014 08:33:54 -0000 Mailing-List: contact derby-commits-help@db.apache.org; run by ezmlm Precedence: bulk list-help: list-unsubscribe: List-Post: Reply-To: "Derby Development" List-Id: Delivered-To: mailing list derby-commits@db.apache.org Received: (qmail 46637 invoked by uid 99); 4 Jul 2014 08:33:54 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 04 Jul 2014 08:33:54 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 04 Jul 2014 08:33:52 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id BEEB723889FA; Fri, 4 Jul 2014 08:33:32 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1607795 - in /db/derby/code/trunk/java: engine/org/apache/derby/impl/sql/catalog/ engine/org/apache/derby/loc/ shared/org/apache/derby/shared/common/reference/ testing/org/apache/derbyTesting/functionTests/master/ tools/org/apache/derby/im... Date: Fri, 04 Jul 2014 08:33:32 -0000 To: derby-commits@db.apache.org From: kahatlen@apache.org X-Mailer: svnmailer-1.0.9 Message-Id: <20140704083332.BEEB723889FA@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: kahatlen Date: Fri Jul 4 08:33:31 2014 New Revision: 1607795 URL: http://svn.apache.org/r1607795 Log: DERBY-6626: Check type of user-supplied modules before creating instances Make SequenceUpdater verify that the class specified by the derby.language.sequence.preallocator property is a SequencePreallocator before attempting to create an instance of it. Make dblook and ij verify that user-specified JDBC driver class names and DataSource class names implement the correct interfaces before attempting to create and use them. Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/catalog/SequenceUpdater.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/SQLState.java db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/ij.out db/derby/code/trunk/java/tools/org/apache/derby/impl/tools/ij/util.java db/derby/code/trunk/java/tools/org/apache/derby/impl/tools/ij/utilMain.java db/derby/code/trunk/java/tools/org/apache/derby/loc/toolsmessages.properties db/derby/code/trunk/java/tools/org/apache/derby/tools/dblook.java Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/catalog/SequenceUpdater.java URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/catalog/SequenceUpdater.java?rev=1607795&r1=1607794&r2=1607795&view=diff ============================================================================== --- db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/catalog/SequenceUpdater.java (original) +++ db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/catalog/SequenceUpdater.java Fri Jul 4 08:33:31 2014 @@ -558,8 +558,14 @@ public abstract class SequenceUpdater im { return new SequenceRange( Integer.parseInt( className ) ); } - - return (SequencePreallocator) Class.forName( className ).newInstance(); + + Class klass = Class.forName(className); + if (!SequencePreallocator.class.isAssignableFrom(klass)) { + throw StandardException.newException( + SQLState.LANG_NOT_A_SEQUENCE_PREALLOCATOR, propertyName); + } + + return (SequencePreallocator) klass.newInstance(); } catch (ClassNotFoundException e) { throw missingAllocator( propertyName, className, e ); } catch (ClassCastException e) { throw missingAllocator( propertyName, className, e ); } 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=1607795&r1=1607794&r2=1607795&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 Jul 4 08:33:31 2014 @@ -3834,6 +3834,12 @@ Guide. + X0Y85.S.1 + The Derby property '{0}' identifies a class which does not implement the org.apache.derby.catalog.SequencePreallocator interface. + propertyName + + + X0Y86.S Derby could not obtain the locks needed to release the unused, preallocated values for the sequence '{0}'.'{1}'. As a result, unexpected gaps may appear in this sequence. schemaName Modified: db/derby/code/trunk/java/shared/org/apache/derby/shared/common/reference/SQLState.java URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/shared/org/apache/derby/shared/common/reference/SQLState.java?rev=1607795&r1=1607794&r2=1607795&view=diff ============================================================================== --- db/derby/code/trunk/java/shared/org/apache/derby/shared/common/reference/SQLState.java (original) +++ db/derby/code/trunk/java/shared/org/apache/derby/shared/common/reference/SQLState.java Fri Jul 4 08:33:31 2014 @@ -1429,6 +1429,7 @@ public interface SQLState { String LANG_IGNORE_MISSING_INDEX_ROW_DURING_DELETE = "X0Y83.S"; String LANG_TOO_MUCH_CONTENTION_ON_SEQUENCE = "X0Y84.T"; String LANG_UNKNOWN_SEQUENCE_PREALLOCATOR = "X0Y85.S"; + String LANG_NOT_A_SEQUENCE_PREALLOCATOR = "X0Y85.S.1"; String LANG_CANT_FLUSH_PREALLOCATOR = "X0Y86.S"; String LANG_BAD_UDA_OR_FUNCTION_NAME = "X0Y87.S"; String LANG_UNKNOWN_TOOL_NAME = "X0Y88.S"; Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/ij.out URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/ij.out?rev=1607795&r1=1607794&r2=1607795&view=diff ============================================================================== --- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/ij.out (original) +++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/ij.out Fri Jul 4 08:33:31 2014 @@ -53,7 +53,7 @@ IJ ERROR: Unable to establish connection ij> -- moved from errorcode.sql -- specify an invalid driver driver 'java.lang.Integer'; -IJ ERROR: Could not locate class java.lang.Integer +IJ ERROR: The class 'java.lang.Integer' does not implement the interface 'java.sql.Driver'. ij> -- now a valid driver driver 'org.apache.derby.jdbc.EmbeddedDriver'; ij> -- specify an invalid database Modified: db/derby/code/trunk/java/tools/org/apache/derby/impl/tools/ij/util.java URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/tools/org/apache/derby/impl/tools/ij/util.java?rev=1607795&r1=1607794&r2=1607795&view=diff ============================================================================== --- db/derby/code/trunk/java/tools/org/apache/derby/impl/tools/ij/util.java (original) +++ db/derby/code/trunk/java/tools/org/apache/derby/impl/tools/ij/util.java Fri Jul 4 08:33:31 2014 @@ -33,6 +33,7 @@ import java.lang.reflect.InvocationTarge import java.security.AccessController; import java.security.PrivilegedAction; import java.sql.Connection; +import java.sql.Driver; import java.sql.DriverManager; import java.sql.SQLException; import java.sql.Statement; @@ -44,6 +45,7 @@ import java.sql.Types; import java.util.Properties; import java.util.Vector; import java.util.Locale; +import javax.sql.DataSource; /** Methods used to control setup for apps as @@ -53,7 +55,6 @@ import java.util.Locale; */ public final class util implements java.security.PrivilegedAction { - private static final Class[] DS_GET_CONN_TYPES = {"".getClass(), "".getClass()}; private util() {} //----------------------------------------------------------------- @@ -345,24 +346,23 @@ public final class util implements java. public static Connection getDataSourceConnection(String dsName,String user,String password, String dbName,boolean firstTime) throws SQLException{ // Get a new proxied connection through DataSource - Object ds = null; // really javax.sql.DataSource + DataSource ds; try { Class dc = Class.forName(dsName); - ds = dc.newInstance(); - + if (DataSource.class.isAssignableFrom(dc)) { + ds = (DataSource) dc.newInstance(); + } else { + throw new ijException(LocalizedResource.getMessage( + "TL_notInstanceOf", dsName, DataSource.class.getName())); + } + // set datasource properties setupDataSource(ds,dbName,firstTime); - // Java method call "by hand" { con = ds.getConnection(); } - // or con = ds.getConnection(user, password) - - java.lang.reflect.Method m = - user == null ? dc.getMethod("getConnection", null) : - dc.getMethod("getConnection", DS_GET_CONN_TYPES); - - return (java.sql.Connection) m.invoke(ds, - user == null ? null : new String[] {user, password}); + return user == null + ? ds.getConnection() + : ds.getConnection(user, password); } catch (InvocationTargetException ite) { if (ite.getTargetException() instanceof SQLException) @@ -754,8 +754,16 @@ AppUI.out.println("SIZE="+l); create an instance. @exception IllegalAccessException if driver class constructor not visible. */ - public static void loadDriver(String driverClass) throws ClassNotFoundException, InstantiationException, IllegalAccessException { - Class.forName(driverClass).newInstance(); + static void loadDriver(String driverClass) + throws ClassNotFoundException, InstantiationException, + IllegalAccessException { + Class klass = Class.forName(driverClass); + if (Driver.class.isAssignableFrom(klass)) { + klass.newInstance(); + } else { + throw new ijException(LocalizedResource.getMessage( + "TL_notInstanceOf", driverClass, Driver.class.getName())); + } } /** Modified: db/derby/code/trunk/java/tools/org/apache/derby/impl/tools/ij/utilMain.java URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/tools/org/apache/derby/impl/tools/ij/utilMain.java?rev=1607795&r1=1607794&r2=1607795&view=diff ============================================================================== --- db/derby/code/trunk/java/tools/org/apache/derby/impl/tools/ij/utilMain.java (original) +++ db/derby/code/trunk/java/tools/org/apache/derby/impl/tools/ij/utilMain.java Fri Jul 4 08:33:31 2014 @@ -185,7 +185,9 @@ public class utilMain { JDBCDisplayUtil.ShowException(out, i); // will continue past driver failure } catch (IllegalAccessException ia) { JDBCDisplayUtil.ShowException(out, ia); // will continue past driver failure - } + } catch (ijException ie) { + JDBCDisplayUtil.ShowException(out, ie); // will continue past driver failure + } } } Modified: db/derby/code/trunk/java/tools/org/apache/derby/loc/toolsmessages.properties URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/tools/org/apache/derby/loc/toolsmessages.properties?rev=1607795&r1=1607794&r2=1607795&view=diff ============================================================================== --- db/derby/code/trunk/java/tools/org/apache/derby/loc/toolsmessages.properties (original) +++ db/derby/code/trunk/java/tools/org/apache/derby/loc/toolsmessages.properties Fri Jul 4 08:33:31 2014 @@ -253,6 +253,7 @@ TL_unknownAtt=Attribute is unknown to De TL_trueFalse=Value should be set to true/false. TL_dupAtt=Attribute is a duplicate. TL_urlLabel1=URL Attribute {0}{1}{2} +TL_notInstanceOf=The class ''{0}'' does not implement the interface ''{1}''. # Directory org/apache/derby/tools # From dblook.java DBLOOK_MissingLocale=Resources not found for current locale; switching to {0}. Modified: db/derby/code/trunk/java/tools/org/apache/derby/tools/dblook.java URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/tools/org/apache/derby/tools/dblook.java?rev=1607795&r1=1607794&r2=1607795&view=diff ============================================================================== --- db/derby/code/trunk/java/tools/org/apache/derby/tools/dblook.java (original) +++ db/derby/code/trunk/java/tools/org/apache/derby/tools/dblook.java Fri Jul 4 08:33:31 2014 @@ -27,6 +27,7 @@ import java.io.StringReader; import java.sql.DriverManager; import java.sql.ResultSet; import java.sql.Connection; +import java.sql.Driver; import java.sql.Statement; import java.sql.PreparedStatement; import java.sql.SQLException; @@ -131,6 +132,7 @@ public final class dblook { if (!loadDriver()) { // Failed when loading the driver. We already logged // the exception, so just return. + Logs.cleanup(); // Make sure the error log is flushed to disk. return; } @@ -321,7 +323,15 @@ public final class dblook { } try { - Class.forName(derbyDriver).newInstance(); + Class klass = Class.forName(derbyDriver); + if (Driver.class.isAssignableFrom(klass)) { + klass.newInstance(); + } else { + Logs.debug( + "TL_notInstanceOf", + new String[] { derbyDriver, Driver.class.getName() }); + return false; + } } catch (Exception e) {