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 rh...@apache.org on 2014/06/09 20:25:35 UTC
svn commit: r1601465 - in /db/derby/code/trunk/java:
engine/org/apache/derby/loc/ optional/org/apache/derby/optional/lucene/
shared/org/apache/derby/shared/common/reference/
testing/org/apache/derbyTesting/functionTests/tests/lang/
Author: rhillegas
Date: Mon Jun 9 18:25:34 2014
New Revision: 1601465
URL: http://svn.apache.org/r1601465
Log:
DERBY-6596: Forbid null args to lucene support routines; derby-6596-01-aa-checkNotNull.diff.
Modified:
db/derby/code/trunk/java/engine/org/apache/derby/loc/messages.xml
db/derby/code/trunk/java/optional/org/apache/derby/optional/lucene/LuceneQueryVTI.java
db/derby/code/trunk/java/optional/org/apache/derby/optional/lucene/LuceneSupport.java
db/derby/code/trunk/java/shared/org/apache/derby/shared/common/reference/SQLState.java
db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/LuceneSupportPermsTest.java
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=1601465&r1=1601464&r2=1601465&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 Mon Jun 9 18:25:34 2014
@@ -2417,6 +2417,12 @@ Guide.
<text>Lucene indexes cannot be created in an encrypted database and, conversely, a database containing a Lucene index cannot be encrypted.</text>
</msg>
+ <msg>
+ <name>42XBM</name>
+ <text>Argument '{0}' may not be null.</text>
+ <arg>argumentName</arg>
+ </msg>
+
<msg>
<name>42Y00</name>
<text>Class '{0}' does not implement org.apache.derby.iapi.db.AggregateDefinition and thus cannot be used as an aggregate expression.</text>
Modified: db/derby/code/trunk/java/optional/org/apache/derby/optional/lucene/LuceneQueryVTI.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/optional/org/apache/derby/optional/lucene/LuceneQueryVTI.java?rev=1601465&r1=1601464&r2=1601465&view=diff
==============================================================================
--- db/derby/code/trunk/java/optional/org/apache/derby/optional/lucene/LuceneQueryVTI.java (original)
+++ db/derby/code/trunk/java/optional/org/apache/derby/optional/lucene/LuceneQueryVTI.java Mon Jun 9 18:25:34 2014
@@ -125,6 +125,8 @@ public class LuceneQueryVTI extends Stri
throws SQLException
{
super( null );
+
+ LuceneSupport.checkNotNull( "QUERY", queryText );
_connection = LuceneSupport.getDefaultConnection();
_queryText = queryText;
Modified: db/derby/code/trunk/java/optional/org/apache/derby/optional/lucene/LuceneSupport.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/optional/org/apache/derby/optional/lucene/LuceneSupport.java?rev=1601465&r1=1601464&r2=1601465&view=diff
==============================================================================
--- db/derby/code/trunk/java/optional/org/apache/derby/optional/lucene/LuceneSupport.java (original)
+++ db/derby/code/trunk/java/optional/org/apache/derby/optional/lucene/LuceneSupport.java Mon Jun 9 18:25:34 2014
@@ -367,6 +367,8 @@ public class LuceneSupport implements Op
Connection conn = getDefaultConnection();
+ vetIdentifiers( schema, table, textcol );
+
// only the dbo or the schema owner can perform this function
mustBeOwner( conn, schema );
@@ -410,6 +412,8 @@ public class LuceneSupport implements Op
Connection conn = getDefaultConnection();
DatabaseMetaData dbmd = conn.getMetaData();
+ vetIdentifiers( schema, table, textcol );
+
// First make sure that the text column exists and is a String type
vetTextColumn( dbmd, schema, table, textcol );
@@ -570,6 +574,20 @@ public class LuceneSupport implements Op
}
}
+ /** Verify that the schema, table, and column names aren't null */
+ private static void vetIdentifiers
+ (
+ String schema,
+ String table,
+ String textcol
+ )
+ throws SQLException
+ {
+ checkNotNull( "SCHEMANAME", schema );
+ checkNotNull( "TABLENAME", table );
+ checkNotNull( "TEXTCOLUMN", textcol );
+ }
+
/////////////////////////////////////////////////////////////////////
//
// DROP INDEX
@@ -590,6 +608,8 @@ public class LuceneSupport implements Op
{
forbidReadOnlyConnections();
+ vetIdentifiers( schema, table, textcol );
+
getDefaultConnection().prepareStatement
(
"drop function " + makeTableFunctionName( schema, table, textcol )
@@ -1356,6 +1376,16 @@ public class LuceneSupport implements Op
catch (StandardException se) { throw sqlException( se ); }
}
+ /** Raise an error if an argument is being given a null value */
+ static void checkNotNull( String argumentName, String argumentValue )
+ throws SQLException
+ {
+ if ( argumentValue == null )
+ {
+ throw newSQLException( SQLState.ARGUMENT_MAY_NOT_BE_NULL, argumentName );
+ }
+ }
+
/**
* Return the primary key columns for a table, sorted by key position.
*/
@@ -1474,6 +1504,8 @@ public class LuceneSupport implements Op
int counter = 0;
for ( String key : keyColumns )
{
+ checkNotNull( "KEYCOLUMNS", key );
+
if ( counter > 0 ) { buffer.append( ", " ); }
counter++;
buffer.append( derbyIdentifier( key ) );
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=1601465&r1=1601464&r2=1601465&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 Mon Jun 9 18:25:34 2014
@@ -1192,6 +1192,7 @@ public interface SQLState {
String LUCENE_BAD_COLUMN_NAME = "42XBJ";
String LUCENE_BAD_VERSION = "42XBK";
String LUCENE_ENCRYPTED_DB = "42XBL";
+ String ARGUMENT_MAY_NOT_BE_NULL = "42XBM";
// org.apache.derby.impl.sql.execute.rts
String RTS_ATTACHED_TO = "43X00.U";
Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/LuceneSupportPermsTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/LuceneSupportPermsTest.java?rev=1601465&r1=1601464&r2=1601465&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/LuceneSupportPermsTest.java (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/LuceneSupportPermsTest.java Mon Jun 9 18:25:34 2014
@@ -100,6 +100,8 @@ public class LuceneSupportPermsTest exte
private static final String BAD_COLUMN_NAME = "42XBJ";
private static final String NONEXISTENT_TABLE_FUNCTION ="42ZB4";
private static final String INCOMPATIBLE_ENCRYPTION = "42XBL";
+ private static final String ILLEGAL_NULL_ARG = "42XBM";
+ private static final String NULL_PRIMITIVE_ARG = "39004";
private static final String POLICY_FILE = "org/apache/derbyTesting/functionTests/tests/lang/luceneSupport.policy";
@@ -1087,6 +1089,86 @@ public class LuceneSupportPermsTest exte
goodStatement( conn, "call lucenesupport.dropIndex( 'TEST_DBO', 't_6602', 'textcol' )" );
}
+ /**
+ * <p>
+ * Test that nulls are not allowed as the values of certain arguments. See DERBY-6596.
+ * </p>
+ */
+ public void test_6596_null_args()
+ throws Exception
+ {
+ Connection dboConnection = openUserConnection( TEST_DBO );
+
+ goodStatement( dboConnection, LOAD_TOOL );
+ goodStatement( dboConnection, "create table t_6596( x int primary key, c clob )" );
+ goodStatement( dboConnection, "insert into t_6596 values ( 1, 'abc' ), ( 2, 'def' )" );
+
+ // create index errors
+ expectExecutionError
+ ( dboConnection, ILLEGAL_NULL_ARG,
+ "call lucenesupport.createindex( null, 't_6596', 'c', 'org.apache.derby.optional.api.LuceneUtils.standardAnalyzer' )" );
+ expectExecutionError
+ ( dboConnection, ILLEGAL_NULL_ARG,
+ "call lucenesupport.createindex( 'TEST_DBO', null, 'c', 'org.apache.derby.optional.api.LuceneUtils.standardAnalyzer' )" );
+ expectExecutionError
+ ( dboConnection, ILLEGAL_NULL_ARG,
+ "call lucenesupport.createindex( 'TEST_DBO', 't_6596', null, 'org.apache.derby.optional.api.LuceneUtils.standardAnalyzer' )" );
+ expectExecutionError
+ ( dboConnection, ILLEGAL_NULL_ARG,
+ "call lucenesupport.createindex( 'TEST_DBO', 't_6596', 'c', 'org.apache.derby.optional.api.LuceneUtils.standardAnalyzer', null )" );
+ expectExecutionError
+ ( dboConnection, ILLEGAL_NULL_ARG,
+ "call lucenesupport.createindex( 'TEST_DBO', 't_6596', 'c', 'org.apache.derby.optional.api.LuceneUtils.standardAnalyzer', 'x', null )" );
+
+ goodStatement( dboConnection, "call lucenesupport.createindex( 'TEST_DBO', 't_6596', 'c', 'org.apache.derby.optional.api.LuceneUtils.standardAnalyzer' )" );
+ assertResults
+ (
+ dboConnection,
+ "select * from table( t_6596__c( 'abc or def', null, 3, null ) ) tc order by documentid",
+ new String[][]
+ {
+ { "1", "0", "0.35355338" },
+ { "2", "1", "0.35355338" },
+ },
+ false
+ );
+ goodStatement( dboConnection, "call lucenesupport.updateindex( 'TEST_DBO', 't_6596', 'c', 'org.apache.derby.optional.api.LuceneUtils.standardAnalyzer' )" );
+
+ // update index errors
+ expectExecutionError
+ ( dboConnection, ILLEGAL_NULL_ARG,
+ "call lucenesupport.updateindex( null, 't_6596', 'c', 'org.apache.derby.optional.api.LuceneUtils.standardAnalyzer' )" );
+ expectExecutionError
+ ( dboConnection, ILLEGAL_NULL_ARG,
+ "call lucenesupport.updateindex( 'TEST_DBO', null, 'c', 'org.apache.derby.optional.api.LuceneUtils.standardAnalyzer' )" );
+ expectExecutionError
+ ( dboConnection, ILLEGAL_NULL_ARG,
+ "call lucenesupport.updateindex( 'TEST_DBO', 't_6596', null, 'org.apache.derby.optional.api.LuceneUtils.standardAnalyzer' )" );
+
+ // query errors
+ expectExecutionError
+ ( dboConnection, ILLEGAL_NULL_ARG,
+ "select * from table( t_6596__c( null, null, 3, null ) ) tc order by documentid" );
+ expectExecutionError
+ ( dboConnection, NULL_PRIMITIVE_ARG,
+ "select * from table( t_6596__c( 'abc or def', null, null, null ) ) tc order by documentid" );
+
+ // drop index errors
+ expectExecutionError
+ ( dboConnection, ILLEGAL_NULL_ARG,
+ "call lucenesupport.dropindex( null, 't_6596', 'c' )" );
+ expectExecutionError
+ ( dboConnection, ILLEGAL_NULL_ARG,
+ "call lucenesupport.dropindex( 'TEST_DBO', null, 'c' )" );
+ expectExecutionError
+ ( dboConnection, ILLEGAL_NULL_ARG,
+ "call lucenesupport.dropindex( 'TEST_DBO', 't_6596', null )" );
+
+ goodStatement( dboConnection, "call lucenesupport.dropindex( 'TEST_DBO', 't_6596', 'c' )" );
+ goodStatement( dboConnection, "drop table t_6596" );
+ goodStatement( dboConnection, UNLOAD_TOOL );
+ }
+
///////////////////////////////////////////////////////////////////////////////////
//
// MINIONS