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 "Mamta A. Satoor (JIRA)" <de...@db.apache.org> on 2006/09/14 21:04:24 UTC

[jira] Updated: (DERBY-1706) NullPointerException occurs when trying to create a table in schema SESSION

     [ http://issues.apache.org/jira/browse/DERBY-1706?page=all ]

Mamta A. Satoor updated DERBY-1706:
-----------------------------------

    Attachment: DERBY1706NPEwithSessionSchemaV1diff.txt

I have attached a patch(DERBY1706NPEwithSessionSchemaV1diff.txt) to this Jira entry to fix the null pointer exception problem. But before going into the details of the patch, I want to provide some background information about SESSION schema and global temporary tables.

SESSION schema is a special schema which is used for global temporary tables. In order to handle global temporary table, Derby creates a in-memory SESSION schema descriptor which does not have any uuid associated with it. A physical SESSION schema(with it's uuid set properly) will be created *only* if there is a persistent object created in it by a user. Global temporary tables can only reside in SESSION schema and Derby documentation recommends that SESSION schema should not be used for other persistent objects. This is because the same object name could be referencing different objects within SESSION schema depending on in what order they got created.
For instance
create table session.t1(c11 int);
-- the following select will get data from the persistent table t1 in SESSION schema
select * from session.t1;
declare global temporary table session.t1(c11 int, c12 int) on commit delete rows not logged;
-- the following select this time will return data from the temporary table t1 rather than persistent table t1
-- This is because, at any time, if there is a global temporary table by the table referenced by a statement,
-- then Derby will always pick up the global temporary table. If no global temporary table by that name is
-- found, then Derby will look for persistent table in SESSION schema. If none found, then error will be thrown
select * from session.t1;
-- following will drop the temporary table t1 and not the persistent table t1
drop table session.t1;
-- the following select will get data from the persistent table t1 in SESSION schema because temporary table
-- doesn't exist anymore
select * from session.t1;

So, as can be seen from the example above, the statements referencing SESSION schema objects could have different meanings depending on what kind of objects exist in SESSION schema. Because of this, the compiled plans of statements referencing SESSION schema are not saved in the statement cache, rather they get compiled everytime they are executed. In order to enforce this, in the compilation phase, Derby checks if the statement at hand is referencing a SESSION schema object by calling referencesSessionSchema method. If this method returns true, the statement's compiled plan will not be saved in the statement cache. 

Now, taking the script provided by Yip which results in NPE
set schema session; 
create table t1 (i int); 

Derby calls referencesSessionSchema while compiling "create table t1 (i int); " to see if it references SESSION schema object. Since, there is no schema associated with the table t1, Derby will check for the compilation schema which in this case is SESSION schema because we used "set schema session; ". (This happens in QueryTreeNode.getSchemaDescriptor(String schemaName, boolean raiseError) line 1486). The method
then tries to call an equal method on the UUID associated with the SESSION schema descriptor but since it is null(because no physical SESSION schema has been created yet), we end up with a null pointer exception. This will happen only if no physical SESSION schema has been created yet and user tries to create a first persistent object inside SESSION schema after doing a set schema session.

Following will not give a NPE because user hand created SESSION schema before doing set schema SESSION and creating an object inside it.
create schema session;
set schema session; 
create table t1 (i int); 
The hand creation of SESSION schema causes Derby to have a schema descriptor for SESSION schema with it's uuid set correctly.

The fix for the NPE is simple and that is to check if the UUID is null. I have added test to existing lang/declareGlobalTempTableJava and ran derbyall on Windows XP with Sun jdk 1.4 and everything ran fine.

The svn stat -q o/p is as follows
M      java\engine\org\apache\derby\impl\sql\compile\QueryTreeNode.java
M      java\testing\org\apache\derbyTesting\functionTests\tests\lang\declareGlobalTempTableJava.java
M      java\testing\org\apache\derbyTesting\functionTests\master\declareGlobalTempTableJava.out

Please let me know if anyone has any comments.


> NullPointerException occurs when trying to create a table in schema SESSION
> ---------------------------------------------------------------------------
>
>                 Key: DERBY-1706
>                 URL: http://issues.apache.org/jira/browse/DERBY-1706
>             Project: Derby
>          Issue Type: Bug
>          Components: SQL
>    Affects Versions: 10.2.1.0
>         Environment: Sun JDK 1.4.2
>            Reporter: Yip Ng
>         Assigned To: Mamta A. Satoor
>            Priority: Minor
>         Attachments: DERBY1706NPEwithSessionSchemaV1diff.txt
>
>
> NPE occurs when attempting to create a table in schema session:
> ij version 10.2
> ij> connect 'jdbc:derby:wombat;create=true' user 'user1';
> WARNING 01J14: SQL authorization is being used without first enabling authentica
> tion.
> ij> set schema session;
> 0 rows inserted/updated/deleted
> ij> create table t1 (i int);
> ERROR XJ001: Java exception: ': java.lang.NullPointerException'.
> derby.log:
> ----------------------------------------------------------------
> 2006-08-16 20:49:02.765 GMT:
>  Booting Derby version The Apache Software Foundation - Apache Derby - 10.2.1.0 beta - (430903): instance c013800d-010d-18be-88cf-00000013f010
> on database directory C:\work3\derby\tests\derby-10.2.1.0\lib\wombat  
> Database Class Loader started - derby.database.classpath=''
> 2006-08-16 20:49:17.312 GMT Thread[main,5,main] (XID = 122), (SESSIONID = 0), (DATABASE = wombat), (DRDAID = null), Cleanup action starting
> 2006-08-16 20:49:17.312 GMT Thread[main,5,main] (XID = 122), (SESSIONID = 0), (DATABASE = wombat), (DRDAID = null), Failed Statement is: create table t1 (i int)
> java.lang.NullPointerException
> 	at org.apache.derby.impl.sql.compile.QueryTreeNode.getSchemaDescriptor(Unknown Source)
> 	at org.apache.derby.impl.sql.compile.DDLStatementNode.getSchemaDescriptor(Unknown Source)
> 	at org.apache.derby.impl.sql.compile.DDLStatementNode.getSchemaDescriptor(Unknown Source)
> 	at org.apache.derby.impl.sql.compile.CreateTableNode.referencesSessionSchema(Unknown Source)
> 	at org.apache.derby.impl.sql.GenericPreparedStatement.referencesSessionSchema(Unknown Source)
> 	at org.apache.derby.impl.sql.GenericStatement.prepMinion(Unknown Source)
> 	at org.apache.derby.impl.sql.GenericStatement.prepare(Unknown Source)
> 	at org.apache.derby.impl.sql.conn.GenericLanguageConnectionContext.prepareInternalStatement(Unknown Source)
> 	at org.apache.derby.impl.jdbc.EmbedStatement.execute(Unknown Source)
> 	at org.apache.derby.impl.jdbc.EmbedStatement.execute(Unknown Source)
> 	at org.apache.derby.impl.tools.ij.ij.executeImmediate(Unknown Source)
> 	at org.apache.derby.impl.tools.ij.utilMain.doCatch(Unknown Source)
> 	at org.apache.derby.impl.tools.ij.utilMain.runScriptGuts(Unknown Source)
> 	at org.apache.derby.impl.tools.ij.utilMain.go(Unknown Source)
> 	at org.apache.derby.impl.tools.ij.Main.go(Unknown Source)
> 	at org.apache.derby.impl.tools.ij.Main.mainCore(Unknown Source)
> 	at org.apache.derby.impl.tools.ij.Main14.main(Unknown Source)
> 	at org.apache.derby.tools.ij.main(Unknown Source)
> Cleanup action completed
> 2006-08-16 20:49:55.312 GMT:
> Shutting down instance c013800d-010d-18be-88cf-00000013f010
> ----------------------------------------------------------------
> sysinfo:
> ------------------ Java Information ------------------
> Java Version:    1.4.2_12
> Java Vendor:     Sun Microsystems Inc.
> Java home:       C:\Program Files\Java\j2re1.4.2_12
> Java classpath:  derby.jar;derbytools.jar;.
> OS name:         Windows XP
> OS architecture: x86
> OS version:      5.1
> Java user name:  Yip
> Java user home:  C:\Documents and Settings\Yip
> Java user dir:   C:\work3\derby\tests\derby-10.2.1.0\lib
> java.specification.name: Java Platform API Specification
> java.specification.version: 1.4
> --------- Derby Information --------
> JRE - JDBC: J2SE 1.4.2 - JDBC 3.0
> [C:\work3\derby\tests\derby-10.2.1.0\lib\derby.jar] 10.2.1.0 beta - (430903)
> [C:\work3\derby\tests\derby-10.2.1.0\lib\derbytools.jar] 10.2.1.0 beta - (430903
> )
> ------------------------------------------------------
> ----------------- Locale Information -----------------
> Current Locale :  [English/United States [en_US]]
> Found support for locale: [de_DE]
>          version: 10.2.1.0 - (430903)
> Found support for locale: [es]
>          version: 10.2.1.0 - (430903)
> Found support for locale: [fr]
>          version: 10.2.1.0 - (430903)
> Found support for locale: [it]
>          version: 10.2.1.0 - (430903)
> Found support for locale: [ja_JP]
>          version: 10.2.1.0 - (430903)
> Found support for locale: [ko_KR]
>          version: 10.2.1.0 - (430903)
> Found support for locale: [pt_BR]
>          version: 10.2.1.0 - (430903)
> Found support for locale: [zh_CN]
>          version: 10.2.1.0 - (430903)
> Found support for locale: [zh_TW]
>          version: 10.2.1.0 - (430903)
> ------------------------------------------------------

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira