[ 
https://issues.apache.org/jira/browse/DERBY-5111?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13006920#comment-13006920
 ] 

Knut Anders Hatlen commented on DERBY-5111:
-------------------------------------------

Can also be seen with only one of the tables:

CREATE TABLE T1 (t1_id INTEGER NOT NULL, t0_id INTEGER NOT NULL, value 
VARCHAR(75) NOT NULL);
CREATE UNIQUE INDEX UI1 ON T1 (t1_id);
ALTER TABLE T1 ADD CONSTRAINT PK1 PRIMARY KEY (t1_id);
CREATE UNIQUE INDEX UI2 ON T1 (t0_id, value);

INSERT INTO T1 VALUES(0, 0, 'Test');
INSERT INTO T1 VALUES(1, 0, 'Test'); 

Here's the full stack trace for the NPE:

java.lang.NullPointerException
        at 
org.apache.derby.impl.sql.execute.IndexChanger.insertAndCheckDups(IndexChanger.java:463)
        at 
org.apache.derby.impl.sql.execute.IndexChanger.doInsert(IndexChanger.java:383)
        at 
org.apache.derby.impl.sql.execute.IndexChanger.insert(IndexChanger.java:590)
        at 
org.apache.derby.impl.sql.execute.IndexSetChanger.insert(IndexSetChanger.java:268)
        at 
org.apache.derby.impl.sql.execute.RowChangerImpl.insertRow(RowChangerImpl.java:453)
        at 
org.apache.derby.impl.sql.execute.InsertResultSet.normalInsertCore(InsertResultSet.java:1028)
        at 
org.apache.derby.impl.sql.execute.InsertResultSet.open(InsertResultSet.java:505)
        at 
org.apache.derby.impl.sql.GenericPreparedStatement.executeStmt(GenericPreparedStatement.java:436)
        at 
org.apache.derby.impl.sql.GenericPreparedStatement.execute(GenericPreparedStatement.java:317)
        at 
org.apache.derby.impl.jdbc.EmbedStatement.executeStatement(EmbedStatement.java:1242)
        at 
org.apache.derby.impl.jdbc.EmbedStatement.execute(EmbedStatement.java:630)
        at 
org.apache.derby.impl.jdbc.EmbedStatement.execute(EmbedStatement.java:559)
        at org.apache.derby.impl.tools.ij.ij.executeImmediate(ij.java:367)
        at org.apache.derby.impl.tools.ij.utilMain.doCatch(utilMain.java:521)
        at 
org.apache.derby.impl.tools.ij.utilMain.runScriptGuts(utilMain.java:363)
        at org.apache.derby.impl.tools.ij.utilMain.go(utilMain.java:261)
        at org.apache.derby.impl.tools.ij.Main.go(Main.java:229)
        at org.apache.derby.impl.tools.ij.Main.mainCore(Main.java:184)
        at org.apache.derby.impl.tools.ij.Main.main(Main.java:75)
        at org.apache.derby.tools.ij.main(ij.java:59)

It looks like the constraint violation is detected, but it cannot find the 
index in the list of constraints associated with the table, and it fails with a 
NullPointerException when trying to extract the name of the index for the error 
message.

> 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.6.1.0, 10.6.2.1, 10.7.1.1
>            Reporter: Mark La Rue
>
> 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 is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira

Reply via email to