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

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

I disabled the optimization in my sandbox, so that popCompilerContext() always 
removed the context from the stack, and ran the full regression test suite to 
see if we try to access the compiler context at execution time any other places 
in the code. There was one failure in 
OptionalToolsTest.test_04_customOptimizerTrace() which suggests that we need a 
similar fix in OptimizerTracer.loadTool().

I was able to reproduce that problem with a clean trunk as well:

{noformat}
ij version 10.11
ij> connect 'jdbc:derby:memory:db;create=true';
ij> call syscs_util.syscs_register_tool('optimizerTracing', true, 'custom', 
'org.apache.derbyTesting.functionTests.tests.lang.DummyOptTrace');
0 rows inserted/updated/deleted
ij> call syscs_util.syscs_register_tool('optimizerTracing', false);
0 rows inserted/updated/deleted
ij> connect 'jdbc:derby:memory:db';
ij(CONNECTION1)> call syscs_util.syscs_register_tool('optimizerTracing', true, 
'custom', 'org.apache.derbyTesting.functionTests.tests.lang.DummyOptTrace');
ERROR 38000: The exception 'java.sql.SQLException' was thrown while evaluating 
an expression.
ERROR (no SQLState): (no message)
{noformat}

derby.log tells that the root cause is a NullPointerException in 
OptimizerTracer.loadTool():

{noformat}
java.lang.NullPointerException
        at 
org.apache.derby.impl.sql.compile.OptimizerTracer.loadTool(OptimizerTracer.java:111)
        at 
org.apache.derby.catalog.Java5SystemProcedures.SYSCS_REGISTER_TOOL(Java5SystemProcedures.java:116)
        at 
org.apache.derby.exe.ac4d3680a5x0144x970cx763cx00000d4d4fe50.g0(Unknown Source)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at 
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
        at 
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:606)
        at 
org.apache.derby.impl.services.reflect.ReflectMethod.invoke(ReflectMethod.java:46)
        at 
org.apache.derby.impl.sql.execute.CallStatementResultSet.open(CallStatementResultSet.java:75)
        at 
org.apache.derby.impl.sql.GenericPreparedStatement.executeStmt(GenericPreparedStatement.java:470)
        at 
org.apache.derby.impl.sql.GenericPreparedStatement.execute(GenericPreparedStatement.java:349)
        at 
org.apache.derby.impl.jdbc.EmbedStatement.executeStatement(EmbedStatement.java:1337)
        at 
org.apache.derby.impl.jdbc.EmbedStatement.execute(EmbedStatement.java:704)
        at 
org.apache.derby.impl.jdbc.EmbedStatement.execute(EmbedStatement.java:631)
        at org.apache.derby.impl.tools.ij.ij.executeImmediate(ij.java:367)
        at org.apache.derby.impl.tools.ij.utilMain.doCatch(utilMain.java:527)
        at 
org.apache.derby.impl.tools.ij.utilMain.runScriptGuts(utilMain.java:369)
        at org.apache.derby.impl.tools.ij.utilMain.go(utilMain.java:245)
        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)
{noformat}

> Optional tool registration may fail because the CompilerContext is not always 
> available at execution time.
> ----------------------------------------------------------------------------------------------------------
>
>                 Key: DERBY-6496
>                 URL: https://issues.apache.org/jira/browse/DERBY-6496
>             Project: Derby
>          Issue Type: Bug
>          Components: SQL
>    Affects Versions: 10.11.0.0
>            Reporter: Rick Hillegas
>            Assignee: Rick Hillegas
>         Attachments: derby-6496-01-aa-useClassFactoryContext.diff, 
> derby-6496-01-ab-useClassFactoryContext.diff
>
>
> For reasons which elude me, the CompilerContext is sometimes available at 
> execution time and sometimes not. When the CompilerContext is not available 
> at execution time, optional tool loading fails on an NPE:
> Caused by: java.lang.NullPointerException
>       at 
> org.apache.derby.catalog.Java5SystemProcedures.SYSCS_REGISTER_TOOL(Java5SystemProcedures.java:104)
>       at 
> org.apache.derby.exe.ac4d3680a5x0144x93adx0136xffffe1d7aa3e0.g0(Unknown 
> Source)
>       at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
>       at 
> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
>       at 
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
>       at 
> org.apache.derby.impl.services.reflect.ReflectMethod.invoke(ReflectMethod.java:46)
>       at 
> org.apache.derby.impl.sql.execute.CallStatementResultSet.open(CallStatementResultSet.java:75)
>       at 
> org.apache.derby.impl.sql.GenericPreparedStatement.executeStmt(GenericPreparedStatement.java:470)
>       at 
> org.apache.derby.impl.sql.GenericPreparedStatement.execute(GenericPreparedStatement.java:349)
>       at 
> org.apache.derby.impl.jdbc.EmbedStatement.executeStatement(EmbedStatement.java:1338)



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

Reply via email to