From: | Bruce Momjian <pgman(at)candle(dot)pha(dot)pa(dot)us> |
---|---|
To: | cbrown(at)ecmarket(dot)com, pgsql-bugs(at)postgresql(dot)org |
Subject: | Re: Bug #597: ResultSet.next() throws NullPointerException |
Date: | 2002-04-14 23:04:11 |
Message-ID: | 200204142304.g3EN4Bt11189@candle.pha.pa.us |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-bugs |
This patch has been applied by someone recently. Thanks.
---------------------------------------------------------------------------
pgsql-bugs(at)postgresql(dot)org wrote:
> 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
>
>
> ---------------------------(end of broadcast)---------------------------
> TIP 4: Don't 'kill -9' the postmaster
>
--
Bruce Momjian | http://candle.pha.pa.us
pgman(at)candle(dot)pha(dot)pa(dot)us | (610) 853-3000
+ If your life is a hard drive, | 830 Blythe Avenue
+ Christ can be your backup. | Drexel Hill, Pennsylvania 19026
From | Date | Subject | |
---|---|---|---|
Next Message | Michael Loftis | 2002-04-15 07:28:52 | Re: Bug #630: date/time storage problem: timestamp parsed |
Previous Message | Sean Chittenden | 2002-04-14 21:15:34 | Re: Bug #630: date/time storage problem: timestamp parsed |