You are viewing a plain text version of this content. The canonical link for it is here.
Posted to ddlutils-dev@db.apache.org by "Rijk van Haaften (JIRA)" <ji...@apache.org> on 2008/09/30 13:48:44 UTC
[jira] Created: (DDLUTILS-227) NullPointerException in
ModelBasedResultSetIterator
NullPointerException in ModelBasedResultSetIterator
---------------------------------------------------
Key: DDLUTILS-227
URL: https://issues.apache.org/jira/browse/DDLUTILS-227
Project: DdlUtils
Issue Type: Bug
Components: Core (No specific database), Core - HSQLDB
Environment: HSQLDB
Reporter: Rijk van Haaften
Assignee: Thomas Dudziak
The bug is in initFromMetaData(Database)
For subqueries in HSQLDB, tableOfColumn = metaData.getTableName(idx) = "SYSTEM_SUBQUERY", rather than null or "", so the if-block (see below) is executed.
That table, of course is not in the model, so table = model.findTable... will set table to null.
That is correct. But unlike the else-block, tableOfColumn is left unchanged.
This causes the tableName to be wrong, which later on sets the _dynaClass to be null: _dynaClass = model.getDynaClassFor(tableName); // model does not contain a "SYSTEM_SUBQUERY"-table
This finally causes a NullPointerException in the implementation of next():
DynaBean bean = _dynaClass.newInstance();
The solution is simple: Update the tableOfColumn not only in the else-block, but always (only the last few lines changed):
if ((tableOfColumn != null) && (tableOfColumn.length() > 0))
{
_log.debug("Table from metadata: " + tableOfColumn);
// jConnect might return a table name enclosed in quotes
if (tableOfColumn.startsWith("\"") && tableOfColumn.endsWith("\"") && (tableOfColumn.length() > 1))
{
tableOfColumn = tableOfColumn.substring(1, tableOfColumn.length() - 1);
}
// the JDBC driver gave us enough meta data info
table = model.findTable(tableOfColumn, _caseSensitive);
}
else
{
_log.debug("Try query hints");
// not enough info in the meta data of the result set, lets try the
// user-supplied query hints
table = (Table)_preparedQueryHints.get(_caseSensitive ? columnName : columnName.toLowerCase());
}
tableOfColumn = (table == null ? null : table.getName()); // Moved out of the else-block
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.
[jira] Updated: (DDLUTILS-227) NullPointerException in
ModelBasedResultSetIterator
Posted by "Rijk van Haaften (JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/DDLUTILS-227?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Rijk van Haaften updated DDLUTILS-227:
--------------------------------------
Attachment: (was: DDLUtilsTest.java)
> NullPointerException in ModelBasedResultSetIterator
> ---------------------------------------------------
>
> Key: DDLUTILS-227
> URL: https://issues.apache.org/jira/browse/DDLUTILS-227
> Project: DdlUtils
> Issue Type: Bug
> Components: Core (No specific database), Core - HSQLDB
> Environment: HSQLDB
> Reporter: Rijk van Haaften
> Assignee: Thomas Dudziak
> Fix For: 1.1
>
>
> The bug is in initFromMetaData(Database)
> For subqueries in HSQLDB, tableOfColumn = metaData.getTableName(idx) = "SYSTEM_SUBQUERY", rather than null or "", so the if-block (see below) is executed.
> That table, of course is not in the model, so table = model.findTable... will set table to null.
> That is correct. But unlike the else-block, tableOfColumn is left unchanged.
> This causes the tableName to be wrong, which later on sets the _dynaClass to be null: _dynaClass = model.getDynaClassFor(tableName); // model does not contain a "SYSTEM_SUBQUERY"-table
> This finally causes a NullPointerException in the implementation of next():
> DynaBean bean = _dynaClass.newInstance();
> The solution is simple: Update the tableOfColumn not only in the else-block, but always (only the last few lines changed):
> if ((tableOfColumn != null) && (tableOfColumn.length() > 0))
> {
> _log.debug("Table from metadata: " + tableOfColumn);
> // jConnect might return a table name enclosed in quotes
> if (tableOfColumn.startsWith("\"") && tableOfColumn.endsWith("\"") && (tableOfColumn.length() > 1))
> {
> tableOfColumn = tableOfColumn.substring(1, tableOfColumn.length() - 1);
> }
> // the JDBC driver gave us enough meta data info
> table = model.findTable(tableOfColumn, _caseSensitive);
> }
> else
> {
> _log.debug("Try query hints");
> // not enough info in the meta data of the result set, lets try the
> // user-supplied query hints
> table = (Table)_preparedQueryHints.get(_caseSensitive ? columnName : columnName.toLowerCase());
> }
> tableOfColumn = (table == null ? null : table.getName()); // Moved out of the else-block
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.
[jira] Resolved: (DDLUTILS-227) NullPointerException in
ModelBasedResultSetIterator
Posted by "Thomas Dudziak (JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/DDLUTILS-227?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Thomas Dudziak resolved DDLUTILS-227.
-------------------------------------
Resolution: Fixed
Please note that fetching a SQL statement like
SELECT * FROM (SELECT * FROM mytable)
does not work in DBs like MySql, Derby, PostgreSql etc. Instead they want you to use an explicit alias:
SELECT * FROM (SELECT * FROM mytable) AS mytable
> NullPointerException in ModelBasedResultSetIterator
> ---------------------------------------------------
>
> Key: DDLUTILS-227
> URL: https://issues.apache.org/jira/browse/DDLUTILS-227
> Project: DdlUtils
> Issue Type: Bug
> Components: Core (No specific database), Core - HSQLDB
> Environment: HSQLDB
> Reporter: Rijk van Haaften
> Assignee: Thomas Dudziak
> Fix For: 1.1
>
> Attachments: DDLUtilsTest.java
>
>
> The bug is in initFromMetaData(Database)
> For subqueries in HSQLDB, tableOfColumn = metaData.getTableName(idx) = "SYSTEM_SUBQUERY", rather than null or "", so the if-block (see below) is executed.
> That table, of course is not in the model, so table = model.findTable... will set table to null.
> That is correct. But unlike the else-block, tableOfColumn is left unchanged.
> This causes the tableName to be wrong, which later on sets the _dynaClass to be null: _dynaClass = model.getDynaClassFor(tableName); // model does not contain a "SYSTEM_SUBQUERY"-table
> This finally causes a NullPointerException in the implementation of next():
> DynaBean bean = _dynaClass.newInstance();
> The solution is simple: Update the tableOfColumn not only in the else-block, but always (only the last few lines changed):
> if ((tableOfColumn != null) && (tableOfColumn.length() > 0))
> {
> _log.debug("Table from metadata: " + tableOfColumn);
> // jConnect might return a table name enclosed in quotes
> if (tableOfColumn.startsWith("\"") && tableOfColumn.endsWith("\"") && (tableOfColumn.length() > 1))
> {
> tableOfColumn = tableOfColumn.substring(1, tableOfColumn.length() - 1);
> }
> // the JDBC driver gave us enough meta data info
> table = model.findTable(tableOfColumn, _caseSensitive);
> }
> else
> {
> _log.debug("Try query hints");
> // not enough info in the meta data of the result set, lets try the
> // user-supplied query hints
> table = (Table)_preparedQueryHints.get(_caseSensitive ? columnName : columnName.toLowerCase());
> }
> tableOfColumn = (table == null ? null : table.getName()); // Moved out of the else-block
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.
[jira] Updated: (DDLUTILS-227) NullPointerException in
ModelBasedResultSetIterator
Posted by "Rijk van Haaften (JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/DDLUTILS-227?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Rijk van Haaften updated DDLUTILS-227:
--------------------------------------
Attachment: DDLUtilsTest.java
Forgot data insertion in previous attachment
> NullPointerException in ModelBasedResultSetIterator
> ---------------------------------------------------
>
> Key: DDLUTILS-227
> URL: https://issues.apache.org/jira/browse/DDLUTILS-227
> Project: DdlUtils
> Issue Type: Bug
> Components: Core (No specific database), Core - HSQLDB
> Environment: HSQLDB
> Reporter: Rijk van Haaften
> Assignee: Thomas Dudziak
> Fix For: 1.1
>
> Attachments: DDLUtilsTest.java
>
>
> The bug is in initFromMetaData(Database)
> For subqueries in HSQLDB, tableOfColumn = metaData.getTableName(idx) = "SYSTEM_SUBQUERY", rather than null or "", so the if-block (see below) is executed.
> That table, of course is not in the model, so table = model.findTable... will set table to null.
> That is correct. But unlike the else-block, tableOfColumn is left unchanged.
> This causes the tableName to be wrong, which later on sets the _dynaClass to be null: _dynaClass = model.getDynaClassFor(tableName); // model does not contain a "SYSTEM_SUBQUERY"-table
> This finally causes a NullPointerException in the implementation of next():
> DynaBean bean = _dynaClass.newInstance();
> The solution is simple: Update the tableOfColumn not only in the else-block, but always (only the last few lines changed):
> if ((tableOfColumn != null) && (tableOfColumn.length() > 0))
> {
> _log.debug("Table from metadata: " + tableOfColumn);
> // jConnect might return a table name enclosed in quotes
> if (tableOfColumn.startsWith("\"") && tableOfColumn.endsWith("\"") && (tableOfColumn.length() > 1))
> {
> tableOfColumn = tableOfColumn.substring(1, tableOfColumn.length() - 1);
> }
> // the JDBC driver gave us enough meta data info
> table = model.findTable(tableOfColumn, _caseSensitive);
> }
> else
> {
> _log.debug("Try query hints");
> // not enough info in the meta data of the result set, lets try the
> // user-supplied query hints
> table = (Table)_preparedQueryHints.get(_caseSensitive ? columnName : columnName.toLowerCase());
> }
> tableOfColumn = (table == null ? null : table.getName()); // Moved out of the else-block
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.
[jira] Updated: (DDLUTILS-227) NullPointerException in
ModelBasedResultSetIterator
Posted by "Rijk van Haaften (JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/DDLUTILS-227?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Rijk van Haaften updated DDLUTILS-227:
--------------------------------------
Attachment: DDLUtilsTest.java
> NullPointerException in ModelBasedResultSetIterator
> ---------------------------------------------------
>
> Key: DDLUTILS-227
> URL: https://issues.apache.org/jira/browse/DDLUTILS-227
> Project: DdlUtils
> Issue Type: Bug
> Components: Core (No specific database), Core - HSQLDB
> Environment: HSQLDB
> Reporter: Rijk van Haaften
> Assignee: Thomas Dudziak
> Fix For: 1.1
>
> Attachments: DDLUtilsTest.java
>
>
> The bug is in initFromMetaData(Database)
> For subqueries in HSQLDB, tableOfColumn = metaData.getTableName(idx) = "SYSTEM_SUBQUERY", rather than null or "", so the if-block (see below) is executed.
> That table, of course is not in the model, so table = model.findTable... will set table to null.
> That is correct. But unlike the else-block, tableOfColumn is left unchanged.
> This causes the tableName to be wrong, which later on sets the _dynaClass to be null: _dynaClass = model.getDynaClassFor(tableName); // model does not contain a "SYSTEM_SUBQUERY"-table
> This finally causes a NullPointerException in the implementation of next():
> DynaBean bean = _dynaClass.newInstance();
> The solution is simple: Update the tableOfColumn not only in the else-block, but always (only the last few lines changed):
> if ((tableOfColumn != null) && (tableOfColumn.length() > 0))
> {
> _log.debug("Table from metadata: " + tableOfColumn);
> // jConnect might return a table name enclosed in quotes
> if (tableOfColumn.startsWith("\"") && tableOfColumn.endsWith("\"") && (tableOfColumn.length() > 1))
> {
> tableOfColumn = tableOfColumn.substring(1, tableOfColumn.length() - 1);
> }
> // the JDBC driver gave us enough meta data info
> table = model.findTable(tableOfColumn, _caseSensitive);
> }
> else
> {
> _log.debug("Try query hints");
> // not enough info in the meta data of the result set, lets try the
> // user-supplied query hints
> table = (Table)_preparedQueryHints.get(_caseSensitive ? columnName : columnName.toLowerCase());
> }
> tableOfColumn = (table == null ? null : table.getName()); // Moved out of the else-block
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.
[jira] Issue Comment Edited: (DDLUTILS-227) NullPointerException in
ModelBasedResultSetIterator
Posted by "Rijk van Haaften (JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/DDLUTILS-227?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12645195#action_12645195 ]
cordeo edited comment on DDLUTILS-227 at 11/5/08 4:22 AM:
--------------------------------------------------------------------
Forgot data insertion in previous attachment. My console output is:
DEBUG - Borrowed connection org.apache.commons.dbcp.PoolableConnection@87c268 from data source
DEBUG - About to execute SQL -- -----------------------------------------------------------------------
-- a
-- -----------------------------------------------------------------------
DROP TABLE a IF EXISTS
DEBUG - After execution, 0 row(s) have been changed
DEBUG - About to execute SQL -- -----------------------------------------------------------------------
-- a
-- -----------------------------------------------------------------------
CREATE TABLE a
(
a BOOLEAN
)
DEBUG - After execution, 0 row(s) have been changed
INFO - Executed 2 SQL command(s) with 0 error(s)
DEBUG - Returning connection org.apache.commons.dbcp.PoolableConnection@87c268 to data source.
Remaining connections: None
DEBUG - Borrowed connection org.apache.commons.dbcp.PoolableConnection@87c268 from data source
DEBUG - About to execute SQL: INSERT INTO a (a) VALUES (?)
DEBUG - Returning connection org.apache.commons.dbcp.PoolableConnection@87c268 to data source.
Remaining connections: None
DEBUG - Borrowed connection org.apache.commons.dbcp.PoolableConnection@87c268 from data source
DEBUG - Returning connection org.apache.commons.dbcp.PoolableConnection@87c268 to data source.
Remaining connections: None
Exception in thread "main" org.apache.ddlutils.DatabaseOperationException: Exception while reading the row from the resultset
at org.apache.ddlutils.platform.ModelBasedResultSetIterator.next(ModelBasedResultSetIterator.java:269)
at org.apache.ddlutils.platform.PlatformImplBase.fetch(PlatformImplBase.java:1638)
at org.apache.ddlutils.platform.PlatformImplBase.fetch(PlatformImplBase.java:1598)
at DDLUtilsTest.main(DDLUtilsTest.java:44)
Caused by: java.lang.NullPointerException
at org.apache.ddlutils.platform.ModelBasedResultSetIterator.next(ModelBasedResultSetIterator.java:237)
... 3 more
was (Author: cordeo):
Forgot data insertion in previous attachment
> NullPointerException in ModelBasedResultSetIterator
> ---------------------------------------------------
>
> Key: DDLUTILS-227
> URL: https://issues.apache.org/jira/browse/DDLUTILS-227
> Project: DdlUtils
> Issue Type: Bug
> Components: Core (No specific database), Core - HSQLDB
> Environment: HSQLDB
> Reporter: Rijk van Haaften
> Assignee: Thomas Dudziak
> Fix For: 1.1
>
> Attachments: DDLUtilsTest.java
>
>
> The bug is in initFromMetaData(Database)
> For subqueries in HSQLDB, tableOfColumn = metaData.getTableName(idx) = "SYSTEM_SUBQUERY", rather than null or "", so the if-block (see below) is executed.
> That table, of course is not in the model, so table = model.findTable... will set table to null.
> That is correct. But unlike the else-block, tableOfColumn is left unchanged.
> This causes the tableName to be wrong, which later on sets the _dynaClass to be null: _dynaClass = model.getDynaClassFor(tableName); // model does not contain a "SYSTEM_SUBQUERY"-table
> This finally causes a NullPointerException in the implementation of next():
> DynaBean bean = _dynaClass.newInstance();
> The solution is simple: Update the tableOfColumn not only in the else-block, but always (only the last few lines changed):
> if ((tableOfColumn != null) && (tableOfColumn.length() > 0))
> {
> _log.debug("Table from metadata: " + tableOfColumn);
> // jConnect might return a table name enclosed in quotes
> if (tableOfColumn.startsWith("\"") && tableOfColumn.endsWith("\"") && (tableOfColumn.length() > 1))
> {
> tableOfColumn = tableOfColumn.substring(1, tableOfColumn.length() - 1);
> }
> // the JDBC driver gave us enough meta data info
> table = model.findTable(tableOfColumn, _caseSensitive);
> }
> else
> {
> _log.debug("Try query hints");
> // not enough info in the meta data of the result set, lets try the
> // user-supplied query hints
> table = (Table)_preparedQueryHints.get(_caseSensitive ? columnName : columnName.toLowerCase());
> }
> tableOfColumn = (table == null ? null : table.getName()); // Moved out of the else-block
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.
[jira] Updated: (DDLUTILS-227) NullPointerException in
ModelBasedResultSetIterator
Posted by "Thomas Dudziak (JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/DDLUTILS-227?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Thomas Dudziak updated DDLUTILS-227:
------------------------------------
Fix Version/s: 1.1
> NullPointerException in ModelBasedResultSetIterator
> ---------------------------------------------------
>
> Key: DDLUTILS-227
> URL: https://issues.apache.org/jira/browse/DDLUTILS-227
> Project: DdlUtils
> Issue Type: Bug
> Components: Core (No specific database), Core - HSQLDB
> Environment: HSQLDB
> Reporter: Rijk van Haaften
> Assignee: Thomas Dudziak
> Fix For: 1.1
>
>
> The bug is in initFromMetaData(Database)
> For subqueries in HSQLDB, tableOfColumn = metaData.getTableName(idx) = "SYSTEM_SUBQUERY", rather than null or "", so the if-block (see below) is executed.
> That table, of course is not in the model, so table = model.findTable... will set table to null.
> That is correct. But unlike the else-block, tableOfColumn is left unchanged.
> This causes the tableName to be wrong, which later on sets the _dynaClass to be null: _dynaClass = model.getDynaClassFor(tableName); // model does not contain a "SYSTEM_SUBQUERY"-table
> This finally causes a NullPointerException in the implementation of next():
> DynaBean bean = _dynaClass.newInstance();
> The solution is simple: Update the tableOfColumn not only in the else-block, but always (only the last few lines changed):
> if ((tableOfColumn != null) && (tableOfColumn.length() > 0))
> {
> _log.debug("Table from metadata: " + tableOfColumn);
> // jConnect might return a table name enclosed in quotes
> if (tableOfColumn.startsWith("\"") && tableOfColumn.endsWith("\"") && (tableOfColumn.length() > 1))
> {
> tableOfColumn = tableOfColumn.substring(1, tableOfColumn.length() - 1);
> }
> // the JDBC driver gave us enough meta data info
> table = model.findTable(tableOfColumn, _caseSensitive);
> }
> else
> {
> _log.debug("Try query hints");
> // not enough info in the meta data of the result set, lets try the
> // user-supplied query hints
> table = (Table)_preparedQueryHints.get(_caseSensitive ? columnName : columnName.toLowerCase());
> }
> tableOfColumn = (table == null ? null : table.getName()); // Moved out of the else-block
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.
[jira] Commented: (DDLUTILS-227) NullPointerException in
ModelBasedResultSetIterator
Posted by "Thomas Dudziak (JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/DDLUTILS-227?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12645157#action_12645157 ]
Thomas Dudziak commented on DDLUTILS-227:
-----------------------------------------
I don't quite understand the problem here. Could you post a DB model and some sample code to exhibit the problem ?
> NullPointerException in ModelBasedResultSetIterator
> ---------------------------------------------------
>
> Key: DDLUTILS-227
> URL: https://issues.apache.org/jira/browse/DDLUTILS-227
> Project: DdlUtils
> Issue Type: Bug
> Components: Core (No specific database), Core - HSQLDB
> Environment: HSQLDB
> Reporter: Rijk van Haaften
> Assignee: Thomas Dudziak
> Fix For: 1.1
>
>
> The bug is in initFromMetaData(Database)
> For subqueries in HSQLDB, tableOfColumn = metaData.getTableName(idx) = "SYSTEM_SUBQUERY", rather than null or "", so the if-block (see below) is executed.
> That table, of course is not in the model, so table = model.findTable... will set table to null.
> That is correct. But unlike the else-block, tableOfColumn is left unchanged.
> This causes the tableName to be wrong, which later on sets the _dynaClass to be null: _dynaClass = model.getDynaClassFor(tableName); // model does not contain a "SYSTEM_SUBQUERY"-table
> This finally causes a NullPointerException in the implementation of next():
> DynaBean bean = _dynaClass.newInstance();
> The solution is simple: Update the tableOfColumn not only in the else-block, but always (only the last few lines changed):
> if ((tableOfColumn != null) && (tableOfColumn.length() > 0))
> {
> _log.debug("Table from metadata: " + tableOfColumn);
> // jConnect might return a table name enclosed in quotes
> if (tableOfColumn.startsWith("\"") && tableOfColumn.endsWith("\"") && (tableOfColumn.length() > 1))
> {
> tableOfColumn = tableOfColumn.substring(1, tableOfColumn.length() - 1);
> }
> // the JDBC driver gave us enough meta data info
> table = model.findTable(tableOfColumn, _caseSensitive);
> }
> else
> {
> _log.debug("Try query hints");
> // not enough info in the meta data of the result set, lets try the
> // user-supplied query hints
> table = (Table)_preparedQueryHints.get(_caseSensitive ? columnName : columnName.toLowerCase());
> }
> tableOfColumn = (table == null ? null : table.getName()); // Moved out of the else-block
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.