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 mi...@apache.org on 2014/10/08 23:52:34 UTC
svn commit: r1630239 - in /db/derby/code/branches/10.10: ./
java/engine/org/apache/derby/iapi/services/io/
java/engine/org/apache/derby/iapi/sql/dictionary/
java/testing/org/apache/derbyTesting/functionTests/tests/lang/
Author: mikem
Date: Wed Oct 8 21:52:34 2014
New Revision: 1630239
URL: http://svn.apache.org/r1630239
Log:
DERBY-5111 NullPointerException on unique constraint violation with unique index
backported change #1579766 and #1582819 from trunk to 10.10 branch. Some
manual changes and merging was necessary.
Patch derby-5111 and
Patch derby-5111-test, which adds the repro for this issue as a new test case.
Modified:
db/derby/code/branches/10.10/ (props changed)
db/derby/code/branches/10.10/java/engine/org/apache/derby/iapi/services/io/ArrayUtil.java
db/derby/code/branches/10.10/java/engine/org/apache/derby/iapi/sql/dictionary/IndexLister.java
db/derby/code/branches/10.10/java/testing/org/apache/derbyTesting/functionTests/tests/lang/PrimaryKeyTest.java
Propchange: db/derby/code/branches/10.10/
------------------------------------------------------------------------------
Merged /db/derby/code/trunk:r1579766,1582819
Modified: db/derby/code/branches/10.10/java/engine/org/apache/derby/iapi/services/io/ArrayUtil.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.10/java/engine/org/apache/derby/iapi/services/io/ArrayUtil.java?rev=1630239&r1=1630238&r2=1630239&view=diff
==============================================================================
--- db/derby/code/branches/10.10/java/engine/org/apache/derby/iapi/services/io/ArrayUtil.java (original)
+++ db/derby/code/branches/10.10/java/engine/org/apache/derby/iapi/services/io/ArrayUtil.java Wed Oct 8 21:52:34 2014
@@ -37,6 +37,18 @@ public abstract class ArrayUtil
{
///////////////////////////////////////////////////////////////////
//
+ // Methods to copy arrays.
+ //
+ ///////////////////////////////////////////////////////////////////
+
+ /** Copy a (possibly null) array of booleans */
+ public static String[] copy( String[] original )
+ {
+ return (original == null) ? null : (String[]) original.clone();
+ }
+
+ ///////////////////////////////////////////////////////////////////
+ //
// Methods for Arrays of OBJECTS. Cannot be used for an
// array of primitives, see below for something for primitives
//
Modified: db/derby/code/branches/10.10/java/engine/org/apache/derby/iapi/sql/dictionary/IndexLister.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.10/java/engine/org/apache/derby/iapi/sql/dictionary/IndexLister.java?rev=1630239&r1=1630238&r2=1630239&view=diff
==============================================================================
--- db/derby/code/branches/10.10/java/engine/org/apache/derby/iapi/sql/dictionary/IndexLister.java (original)
+++ db/derby/code/branches/10.10/java/engine/org/apache/derby/iapi/sql/dictionary/IndexLister.java Wed Oct 8 21:52:34 2014
@@ -23,11 +23,14 @@ package org.apache.derby.iapi.sql.dictio
import org.apache.derby.iapi.error.StandardException;
+import org.apache.derby.iapi.services.io.ArrayUtil;
+
import org.apache.derby.iapi.sql.dictionary.TableDescriptor;
import org.apache.derby.iapi.sql.dictionary.ConglomerateDescriptor;
import org.apache.derby.iapi.sql.dictionary.IndexRowGenerator;
+
/**
* This interface gathers up some tasty information about the indices on a
* table from the DataDictionary.
@@ -103,19 +106,6 @@ public class IndexLister
}
/**
- * Returns an array of all the index names on a table.
- *
- * @return an array of index names
- *
- * @exception StandardException Thrown on error
- */
- public String[] getIndexNames() throws StandardException
- {
- if ( indexNames == null ) { getAllIndexes(); }
- return indexNames;
- }
-
- /**
* Returns an array of distinct index row generators on a table,
* erasing entries for duplicate indexes (which share same conglomerate).
*
@@ -155,8 +145,8 @@ public class IndexLister
*/
public String[] getDistinctIndexNames() throws StandardException
{
- if ( indexNames == null ) { getAllIndexes(); }
- return indexNames;
+ if ( distinctIndexNames == null ) { getAllIndexes(); }
+ return ArrayUtil.copy( distinctIndexNames );
}
////////////////////////////////////////////////////////////////////////
Modified: db/derby/code/branches/10.10/java/testing/org/apache/derbyTesting/functionTests/tests/lang/PrimaryKeyTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.10/java/testing/org/apache/derbyTesting/functionTests/tests/lang/PrimaryKeyTest.java?rev=1630239&r1=1630238&r2=1630239&view=diff
==============================================================================
--- db/derby/code/branches/10.10/java/testing/org/apache/derbyTesting/functionTests/tests/lang/PrimaryKeyTest.java (original)
+++ db/derby/code/branches/10.10/java/testing/org/apache/derbyTesting/functionTests/tests/lang/PrimaryKeyTest.java Wed Oct 8 21:52:34 2014
@@ -25,13 +25,10 @@ import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import java.sql.Statement;
-
import junit.framework.Test;
import junit.framework.TestSuite;
-
import org.apache.derbyTesting.junit.BaseJDBCTestCase;
import org.apache.derbyTesting.junit.JDBC;
-import org.apache.derbyTesting.junit.Utilities;
public class PrimaryKeyTest extends BaseJDBCTestCase
{
@@ -41,13 +38,11 @@ public class PrimaryKeyTest extends Base
public static Test suite() {
return new TestSuite(PrimaryKeyTest.class);
}
+
protected void setUp() throws Exception {
super.setUp();
getConnection().setAutoCommit(false);
}
- protected void tearDown() throws Exception {
- super.tearDown();
- }
/************ NEGATIVE TESTS ************/
/**
@@ -278,5 +273,27 @@ public class PrimaryKeyTest extends Base
assertUpdateCount(s , 0 , "drop table B5420_5.t5");
assertUpdateCount(s , 0 , "drop table B5420_6.t6");
}
+
+ public void testDerby5111() throws SQLException {
+ final Statement s = createStatement();
+ s.executeUpdate("create table t1 (t1_id integer not null, " +
+ "t0_id integer not null, value varchar(75) not null)");
+
+ try {
+ s.executeUpdate("create unique index ui1 on t1 (t1_id)");
+ s.executeUpdate("alter table t1 add constraint pk1 " +
+ " primary key (t1_id)");
+ s.executeUpdate("create unique index ui2 on t1 (t0_id, value)");
+
+ s.executeUpdate("insert into t1 values(0, 0, 'Test')");
+
+ // The next statement tries to insert a duplicate. It used to
+ // throw an NPE before the fix.
+ assertStatementError(
+ "23505", s, "insert into t1 values(1, 0, 'Test')");
+ } finally {
+ try { s.executeUpdate("drop table t1"); } catch (SQLException e){}
+ }
+ }
}