Bug #597: ResultSet.next() throws NullPointerException

From: pgsql-bugs(at)postgresql(dot)org
To: pgsql-bugs(at)postgresql(dot)org
Subject: Bug #597: ResultSet.next() throws NullPointerException
Date: 2002-02-20 01:20:33
Message-ID: 200202200120.g1K1KXO75383@postgresql.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

Craig Brown (cbrown(at)ecmarket(dot)com) reports a bug with a severity of 2
The lower the number the more severe it is.

Short Description
ResultSet.next() throws NullPointerException

Long Description
When invoking the next() method on a ResultSet that has been closed a NullPointerException is thrown. Ideally, an SQLException stating that the ResultSet has been closed should be thrown.

This bug affects several other methods within the jdbc2/ResultSet class.

Sample Code
This patch fixes the above described problem.

*** ./src/interfaces/jdbc/org/postgresql/errors.properties.orig Tue Feb 19 17:54:02 2002
--- ./src/interfaces/jdbc/org/postgresql/errors.properties Tue Feb 19 17:49:55 2002
***************
*** 54,59 ****
--- 54,60 ----
postgresql.res.badshort:Bad Short {0}
postgresql.res.badtime:Bad Time {0}
postgresql.res.badtimestamp:Bad Timestamp Format at {0} in {1}
+ postgresql.res.closed:The ResultSet has been closed.
postgresql.res.colname:The column name {0} not found.
postgresql.res.colrange:The column index is out of range.
postgresql.serial.interface:You cannot serialize an interface.
*** ./src/interfaces/jdbc/org/postgresql/jdbc2/ResultSet.java.orig Tue Feb 19 17:53:46 2002
--- ./src/interfaces/jdbc/org/postgresql/jdbc2/ResultSet.java Tue Feb 19 17:50:12 2002
***************
*** 110,115 ****
--- 110,118 ----
*/
public boolean next() throws SQLException
{
+ if (rows == null)
+ throw new PSQLException("postgresql.res.closed");
+
if (++current_row >= rows.size())
return false;
this_row = (byte [][])rows.elementAt(current_row);
***************
*** 702,707 ****
--- 705,713 ----
*/
public java.sql.ResultSetMetaData getMetaData() throws SQLException
{
+ if (rows == null)
+ throw new PSQLException("postgresql.res.closed");
+
return new ResultSetMetaData(rows, fields);
}

***************
*** 828,833 ****
--- 834,841 ----
// index is 1-based, but internally we use 0-based indices
int internalIndex;

+ if (rows == null)
+ throw new PSQLException("postgresql.res.closed");
if (index == 0)
throw new SQLException("Cannot move to index of 0");

***************
*** 866,871 ****
--- 874,882 ----

public void afterLast() throws SQLException
{
+ if (rows == null)
+ throw new PSQLException("postgresql.res.closed");
+
final int rows_size = rows.size();
if (rows_size > 0)
current_row = rows_size;
***************
*** 873,878 ****
--- 884,892 ----

public void beforeFirst() throws SQLException
{
+ if (rows == null)
+ throw new PSQLException("postgresql.res.closed");
+
if (rows.size() > 0)
current_row = -1;
}
***************
*** 891,896 ****
--- 905,913 ----

public boolean first() throws SQLException
{
+ if (rows == null)
+ throw new PSQLException("postgresql.res.closed");
+
if (rows.size() <= 0)
return false;
current_row = 0;
***************
*** 1035,1040 ****
--- 1052,1060 ----

public int getFetchSize() throws SQLException
{
+ if (rows == null)
+ throw new PSQLException("postgresql.res.closed");
+
// new in 7.1: In this implementation we return the entire result set, so
// here return the number of rows we have. Sub-classes can return a proper
// value
***************
*** 1078,1083 ****
--- 1098,1106 ----

public int getRow() throws SQLException
{
+ if (rows == null)
+ throw new PSQLException("postgresql.res.closed");
+
final int rows_size = rows.size();

if (current_row < 0 || current_row >= rows_size)
***************
*** 1108,1135 ****
--- 1131,1173 ----

public boolean isAfterLast() throws SQLException
{
+ if (rows == null)
+ throw new PSQLException("postgresql.res.closed");
+
final int rows_size = rows.size();
return (current_row >= rows_size && rows_size > 0);
}

public boolean isBeforeFirst() throws SQLException
{
+ if (rows == null)
+ throw new PSQLException("postgresql.res.closed");
+
return (current_row < 0 && rows.size() > 0);
}

public boolean isFirst() throws SQLException
{
+ if (rows == null)
+ throw new PSQLException("postgresql.res.closed");
+
return (current_row == 0 && rows.size() >= 0);
}
public boolean isLast() throws SQLException
{
+ if (rows == null)
+ throw new PSQLException("postgresql.res.closed");
+
final int rows_size = rows.size();
return (current_row == rows_size - 1 && rows_size > 0);
}

public boolean last() throws SQLException
{
+ if (rows == null)
+ throw new PSQLException("postgresql.res.closed");
+
final int rows_size = rows.size();
if (rows_size <= 0)
return false;
***************
*** 1152,1157 ****

--- 1190,1198 ----

public boolean previous() throws SQLException
{
+ if (rows == null)
+ throw new PSQLException("postgresql.res.closed");
+
if (--current_row < 0)
return false;
this_row = (byte [][])rows.elementAt(current_row);

No file was uploaded with this report

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message Lee Kindness 2002-02-20 09:21:12 ecpg did not precompile declare cursor
Previous Message Alain Picard 2002-02-20 00:43:43 Re: Postgresql 7.1.3 not thread safe