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 8331A17D8C for ; Wed, 8 Oct 2014 21:53:03 +0000 (UTC) Received: (qmail 86121 invoked by uid 500); 8 Oct 2014 21:53:03 -0000 Delivered-To: apmail-db-derby-commits-archive@db.apache.org Received: (qmail 86097 invoked by uid 500); 8 Oct 2014 21:53:03 -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 86087 invoked by uid 99); 8 Oct 2014 21:53:03 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 08 Oct 2014 21:53:03 +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; Wed, 08 Oct 2014 21:52:37 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id 040FF23889E0; Wed, 8 Oct 2014 21:52:35 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: 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/ Date: Wed, 08 Oct 2014 21:52:34 -0000 To: derby-commits@db.apache.org From: mikem@apache.org X-Mailer: svnmailer-1.0.9 Message-Id: <20141008215235.040FF23889E0@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org 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){} + } + } }