You are viewing a plain text version of this content. The canonical link for it is here.
Posted to derby-dev@db.apache.org by "Dag H. Wanvik (JIRA)" <ji...@apache.org> on 2014/03/18 19:55:54 UTC

[jira] [Updated] (DERBY-5111) NullPointerException on unique constraint violation with unique index

     [ https://issues.apache.org/jira/browse/DERBY-5111?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Dag H. Wanvik updated DERBY-5111:
---------------------------------

    Attachment: derby-5111.diff

Uploading a patch which fixes the repro. It looks like plain wrong code (copy & paste perhaps) in the method here:

{code:Title=IndexLister#getDistinctIndexNames} 
public String[] getDistinctIndexNames() throws StandardException 
{ 
    if ( indexNames == null ) { getAllIndexes(); }
    return ArrayUtil.copy( indexNames ); 
}
{code}

By substituting distinctIndexNames for indexName, the repro works.  The reason is that otherwise, the array indexNames used to pass the indexName to IndexChanger, cf. the code in IndexSetChanger#openIndexes, will contain

{code}
["UI1", null, "UI2"]
{code}

where the null represents the constraint. But since the constraint PK1 and UI1 shared the index, there are really only two indexes in play, so the index of index (sic) UI2 is 1 in the array if distinct indexes on the table, not 2. So, when the duplicate error happens and IndexChanger is about to create an exception, the name of the index passed in is null instead of "UI2", giving the NPE.


> NullPointerException on unique constraint violation with unique index
> ---------------------------------------------------------------------
>
>                 Key: DERBY-5111
>                 URL: https://issues.apache.org/jira/browse/DERBY-5111
>             Project: Derby
>          Issue Type: Bug
>          Components: SQL
>    Affects Versions: 10.1.3.1, 10.2.2.0, 10.3.3.0, 10.4.2.0, 10.5.3.0, 10.6.1.0, 10.6.2.1, 10.7.1.1, 10.11.0.0
>            Reporter: Mark La Rue
>            Assignee: Dag H. Wanvik
>              Labels: derby_triage10_11
>         Attachments: derby-5111.diff
>
>
> Given the below DDL, violations of the unique constraint (an example follows the DDL) specified on table t1 will result in a NullPointerException that terminates the active connection.  The root cause appears to be related to the unique indexes; removing them results in the correct constraint violation.
> CREATE TABLE s.t0 (t0_id INTEGER NOT NULL, value VARCHAR(75) NOT NULL);
> ALTER TABLE s.t0 ADD CONSTRAINT pk_1 PRIMARY KEY (t0_id);
> CREATE TABLE s.t1 (t1_id INTEGER NOT NULL, t0_id INTEGER NOT NULL, value VARCHAR(75) NOT NULL);
> CREATE UNIQUE INDEX s.ui_1 ON s.t1 (t1_id);
> ALTER TABLE s.t1 ADD CONSTRAINT pk_2 PRIMARY KEY (t1_id);
> ALTER TABLE s.t1 ADD CONSTRAINT fk_1 FOREIGN KEY (t0_id) REFERENCES s.t0 (t0_id) ON DELETE CASCADE;
> CREATE UNIQUE INDEX s.ui_2 ON s.t1 (t0_id, value);
> ALTER TABLE s.t1 ADD CONSTRAINT uc_1 UNIQUE (t0_id, value);
> Minimal DML to trigger the constraint violation:
> INSERT INTO s.t0 VALUES (0, 'foobar');
> INSERT INTO s.t1 VALUES(0, 0, 'Test');
> INSERT INTO s.t1 VALUES(1, 0, 'Test');



--
This message was sent by Atlassian JIRA
(v6.2#6252)