[
https://issues.apache.org/jira/browse/DERBY-6863?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15131591#comment-15131591
]
Bryan Pendleton commented on DERBY-6863:
----------------------------------------
I did enough instrumentation of the code to determine that the NPE arises due to
the following situation from
o.a.d.impl.sql.execute.BaseActivation.getColumnFromRow():
protected final DataValueDescriptor getColumnFromRow(int rsNumber, int
colId)
throws StandardException {
if (row[rsNumber] == null) {
/* This actually happens. NoPutResultSetImpl.clearOrderableCache
* attempts to prefetch invariant values into a cache. This fails
* in some deeply nested joins. See Beetle 4736 and 4880.*/
/*
* Update: DERBY-4798 shows a query for which we get an NPE unless
* this escape is in place (once removed by DERBY-3097, but
* reintroduced by DERBY-4798 until we understand how we can get
* rid of this anomaly). Thus, for now,
* OuterJoinTest#testDerby_4798_NPE will provoke an NPE if this
* code is removed.
*/
return null;
}
return row[rsNumber].getColumn(colId);
}
In the situation provoked by this issue's repro script, rsNumber is 3, and
row[3] is null.
The stack trace when this occurs looks as follows:
java.lang.Exception: row[3] is NULL
at
org.apache.derby.impl.sql.execute.BaseActivation.getColumnFromRow(BaseActivation.java:1491)
at
org.apache.derby.exe.acf81e0010x0152x9980x6849x000002ef07900.e1(Unknown Source)
at
org.apache.derby.impl.services.reflect.DirectCall.invoke(ReflectGeneratedClass.java:103)
at
org.apache.derby.impl.sql.execute.ProjectRestrictResultSet.doProjection(ProjectRestrictResultSet.java:531)
at
org.apache.derby.impl.sql.execute.ProjectRestrictResultSet.getNextRowCore(ProjectRestrictResultSet.java:325)
at
org.apache.derby.impl.sql.execute.SortResultSet.getRowFromResultSet(SortResultSet.java:574)
at
org.apache.derby.impl.sql.execute.SortResultSet.getNextRowFromRS(SortResultSet.java:562)
at
org.apache.derby.impl.sql.execute.SortResultSet.loadSorter(SortResultSet.java:311)
at
org.apache.derby.impl.sql.execute.SortResultSet.openCore(SortResultSet.java:258)
at
org.apache.derby.impl.sql.execute.BasicNoPutResultSetImpl.open(BasicNoPutResultSetImpl.java:266)
at
org.apache.derby.impl.sql.GenericPreparedStatement.executeStmt(GenericPreparedStatement.java:473)
at
org.apache.derby.impl.sql.GenericPreparedStatement.execute(GenericPreparedStatement.java:352)
at
org.apache.derby.impl.jdbc.EmbedStatement.executeStatement(EmbedStatement.java:1340)
at
org.apache.derby.impl.jdbc.EmbedStatement.execute(EmbedStatement.java:706)
at
org.apache.derby.impl.jdbc.EmbedStatement.execute(EmbedStatement.java:633)
at org.apache.derby.impl.tools.ij.ij.executeImmediate(ij.java:367)
at org.apache.derby.impl.tools.ij.utilMain.doCatch(utilMain.java:529)
at
org.apache.derby.impl.tools.ij.utilMain.runScriptGuts(utilMain.java:371)
at org.apache.derby.impl.tools.ij.utilMain.go(utilMain.java:247)
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)
at org.apache.derby.iapi.tools.run.main(run.java:55)
> NPE when multiple values are contained in an IN statement within a CASE
> statement used in a GROUP BY
> ----------------------------------------------------------------------------------------------------
>
> Key: DERBY-6863
> URL: https://issues.apache.org/jira/browse/DERBY-6863
> Project: Derby
> Issue Type: Bug
> Components: SQL
> Affects Versions: 10.12.1.1
> Environment: Java 8, Mint Linux, 24G, Used within an in-memory table
> Reporter: Peter Damen
> Attachments: ac_86.decomp
>
>
> An IN statement within a CASE statement within a GROUP BY, that contains more
> than one element will cause a NPE.
> Reproduction Steps:
> ======== DATA ============
> CREATE TABLE Test (
> Region VARCHAR(20),
> Cost INTEGER
> );
> INSERT INTO Test VALUES ('Australia', 45);
> INSERT INTO Test VALUES ('Asia', 22);
> INSERT INTO Test VALUES ('North America', 33);
> INSERT INTO Test VALUES ('South America', 55);
> INSERT INTO Test VALUES ('Europe', 44);
> ======= SQL WORKS ===========
> SELECT DISTINCT
> CASE
> WHEN 1 = 0 THEN "REGION"
> WHEN "REGION" IN ('Asia') THEN 'A'
> ELSE "REGION"
> END,
> SUM("COST")
> FROM TEST
> GROUP BY
> CASE
> WHEN 1 = 0 THEN "REGION"
> WHEN "REGION" IN ('Asia') THEN 'A'
> ELSE "REGION"
> END
> ============ FAILS ===================
> SELECT DISTINCT
> CASE
> WHEN 1 = 0 THEN "REGION"
> WHEN "REGION" IN ('Asia', 'Australia') THEN 'A'
> ELSE "REGION"
> END,
> SUM("COST")
> FROM TEST
> GROUP BY
> CASE
> WHEN 1 = 0 THEN "REGION"
> WHEN "REGION" IN ('Asia','Australia') THEN 'A'
> ELSE "REGION"
> END
> ================== NPE ===================
> java.sql.SQLException: Java exception: ': java.lang.NullPointerException'.
> at
> org.apache.derby.impl.jdbc.SQLExceptionFactory.getSQLException(Unknown Source)
> at
> org.apache.derby.impl.jdbc.SQLExceptionFactory.getSQLException(Unknown Source)
> at org.apache.derby.impl.jdbc.Util.seeNextException(Unknown Source)
> at org.apache.derby.impl.jdbc.Util.javaException(Unknown Source)
> at
> org.apache.derby.impl.jdbc.TransactionResourceImpl.wrapInSQLException(Unknown
> Source)
> at
> org.apache.derby.impl.jdbc.TransactionResourceImpl.wrapInSQLException(Unknown
> Source)
> at
> org.apache.derby.impl.jdbc.TransactionResourceImpl.handleException(Unknown
> Source)
> at org.apache.derby.impl.jdbc.EmbedConnection.handleException(Unknown
> Source)
> at org.apache.derby.impl.jdbc.ConnectionChild.handleException(Unknown
> Source)
> at org.apache.derby.impl.jdbc.EmbedStatement.executeStatement(Unknown
> Source)
> at org.apache.derby.impl.jdbc.EmbedStatement.execute(Unknown Source)
> at org.apache.derby.impl.jdbc.EmbedStatement.execute(Unknown Source)
> at sun.reflect.GeneratedMethodAccessor47.invoke(Unknown Source)
> at
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
> at java.lang.reflect.Method.invoke(Method.java:622)
> at com.onseven.dbvis.b.B.B.ā(Z:2256)
> at com.onseven.dbvis.b.B.F$A.call(Z:2838)
> at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:334)
> at java.util.concurrent.FutureTask.run(FutureTask.java:166)
> at
> java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1146)
> at
> java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
> at java.lang.Thread.run(Thread.java:701)
> Caused by: ERROR XJ001: Java exception: ': java.lang.NullPointerException'.
> at org.apache.derby.iapi.error.StandardException.newException(Unknown
> Source)
> at
> org.apache.derby.impl.jdbc.SQLExceptionFactory.wrapArgsForTransportAcrossDRDA(Unknown
> Source)
> ... 22 more
> Caused by: java.lang.NullPointerException
> at
> org.apache.derby.exe.acd8cd40bax0152xa074xeeddx0000012ba0d05.e1(Unknown
> Source)
> at org.apache.derby.impl.services.reflect.DirectCall.invoke(Unknown
> Source)
> at
> org.apache.derby.impl.sql.execute.ProjectRestrictResultSet.doProjection(Unknown
> Source)
> at
> org.apache.derby.impl.sql.execute.ProjectRestrictResultSet.getNextRowCore(Unknown
> Source)
> at
> org.apache.derby.impl.sql.execute.SortResultSet.getRowFromResultSet(Unknown
> Source)
> at
> org.apache.derby.impl.sql.execute.SortResultSet.getNextRowFromRS(Unknown
> Source)
> at org.apache.derby.impl.sql.execute.SortResultSet.loadSorter(Unknown
> Source)
> at org.apache.derby.impl.sql.execute.SortResultSet.openCore(Unknown
> Source)
> at
> org.apache.derby.impl.sql.execute.BasicNoPutResultSetImpl.open(Unknown Source)
> at
> org.apache.derby.impl.sql.GenericPreparedStatement.executeStmt(Unknown Source)
> at org.apache.derby.impl.sql.GenericPreparedStatement.execute(Unknown
> Source)
> ... 13 more
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)