Обсуждение: Bug #597: ResultSet.next() throws NullPointerException
Craig Brown (cbrown@ecmarket.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
SQLExceptionstating 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
This has been saved for the 7.3 release:
http://candle.pha.pa.us/cgi-bin/pgpatches2
---------------------------------------------------------------------------
pgsql-bugs@postgresql.org wrote:
> Craig Brown (cbrown@ecmarket.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
SQLExceptionstating 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
>
>
> ---------------------------(end of broadcast)---------------------------
> TIP 4: Don't 'kill -9' the postmaster
>
--
Bruce Momjian | http://candle.pha.pa.us
pgman@candle.pha.pa.us | (610) 853-3000
+ If your life is a hard drive, | 830 Blythe Avenue
+ Christ can be your backup. | Drexel Hill, Pennsylvania 19026
Your patch has been added to the PostgreSQL unapplied patches list at:
http://candle.pha.pa.us/cgi-bin/pgpatches
I will try to apply it within the next 48 hours. Requires jdbc
maintainers approval.
---------------------------------------------------------------------------
pgsql-bugs@postgresql.org wrote:
> Craig Brown (cbrown@ecmarket.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
SQLExceptionstating 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
>
>
> ---------------------------(end of broadcast)---------------------------
> TIP 4: Don't 'kill -9' the postmaster
>
--
Bruce Momjian | http://candle.pha.pa.us
pgman@candle.pha.pa.us | (610) 853-3000
+ If your life is a hard drive, | 830 Blythe Avenue
+ Christ can be your backup. | Drexel Hill, Pennsylvania 19026
This patch has been applied by someone recently. Thanks.
---------------------------------------------------------------------------
pgsql-bugs@postgresql.org wrote:
> Craig Brown (cbrown@ecmarket.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
SQLExceptionstating 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
>
>
> ---------------------------(end of broadcast)---------------------------
> TIP 4: Don't 'kill -9' the postmaster
>
--
Bruce Momjian | http://candle.pha.pa.us
pgman@candle.pha.pa.us | (610) 853-3000
+ If your life is a hard drive, | 830 Blythe Avenue
+ Christ can be your backup. | Drexel Hill, Pennsylvania 19026