From: Date: March 21 2007 9:57pm Subject: Connector/J commit: r6359 - branches/branch_5_0/connector-j branches/branch_5_0/connector-j/src/com/mysql/jdbc branches/branch_5_0/connector-j/src/testsuite/regression trunk/connector-j trunk/connector-j/src/com/mysql/jdbc trunk/connector-j/src/testsuite/regression List-Archive: http://lists.mysql.com/commits/22538 X-Bug: 27137 Message-Id: <200703212057.l2LKv2in030379@bk-internal.mysql.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Modified: branches/branch_5_0/connector-j/CHANGES branches/branch_5_0/connector-j/src/com/mysql/jdbc/LocalizedErrorMessages.properties branches/branch_5_0/connector-j/src/com/mysql/jdbc/ResultSet.java branches/branch_5_0/connector-j/src/testsuite/regression/ResultSetRegressionTest.java trunk/connector-j/CHANGES trunk/connector-j/src/com/mysql/jdbc/LocalizedErrorMessages.properties trunk/connector-j/src/com/mysql/jdbc/ResultSet.java trunk/connector-j/src/testsuite/regression/ResultSetRegressionTest.java Log: - Fixed BUG#27137 - ResultSet.get*() with a column index < 1 returns misleading error message. Modified: branches/branch_5_0/connector-j/CHANGES =================================================================== --- branches/branch_5_0/connector-j/CHANGES 2007-03-21 20:01:27 UTC (rev 6358) +++ branches/branch_5_0/connector-j/CHANGES 2007-03-21 20:56:58 UTC (rev 6359) @@ -32,7 +32,10 @@ - Fixed BUG#26789 - fast date/time parsing doesn't take into account 00:00:00 as a legal value. - + + - Fixed BUG#27137 - ResultSet.get*() with a column index < 1 returns + misleading error message. + 03-01-07 - Version 5.0.5 - Fixed BUG#23645 - Some collations/character sets reported as "unknown" Modified: branches/branch_5_0/connector-j/src/com/mysql/jdbc/LocalizedErrorMessages.properties =================================================================== --- branches/branch_5_0/connector-j/src/com/mysql/jdbc/LocalizedErrorMessages.properties 2007-03-21 20:01:27 UTC (rev 6358) +++ branches/branch_5_0/connector-j/src/com/mysql/jdbc/LocalizedErrorMessages.properties 2007-03-21 20:56:58 UTC (rev 6359) @@ -5,7 +5,8 @@ ResultSet.Retrieved__1=Retrieved ResultSet.Bad_format_for_BigDecimal=Bad format for BigDecimal ''{0}'' in column {1}. ResultSet.Bad_format_for_BigInteger=Bad format for BigInteger ''{0}'' in column {1}. -ResultSet.Column_Index_out_of_range=Column Index out of range, {0} > {1}. +ResultSet.Column_Index_out_of_range_low=Column Index out of range, {0} < 1. +ResultSet.Column_Index_out_of_range_high=Column Index out of range, {0} > {1}. ResultSet.Value_is_out_of_range=Value ''{0}'' is out of range [{1}, {2}]. ResultSet.Positioned_Update_not_supported=Positioned Update not supported. ResultSet.Bad_format_for_Date=Bad format for DATE ''{0}'' in column {1}. Modified: branches/branch_5_0/connector-j/src/com/mysql/jdbc/ResultSet.java =================================================================== --- branches/branch_5_0/connector-j/src/com/mysql/jdbc/ResultSet.java 2007-03-21 20:01:27 UTC (rev 6358) +++ branches/branch_5_0/connector-j/src/com/mysql/jdbc/ResultSet.java 2007-03-21 20:56:58 UTC (rev 6359) @@ -669,12 +669,18 @@ * if the index is out of bounds */ protected final void checkColumnBounds(int columnIndex) throws SQLException { - if ((columnIndex < 1) || (columnIndex > this.fields.length)) { + if ((columnIndex < 1)) { throw SQLError.createSQLException(Messages.getString( - "ResultSet.Column_Index_out_of_range", new Object[] { + "ResultSet.Column_Index_out_of_range_low", new Object[] { new Integer(columnIndex), new Integer(this.fields.length) }), SQLError.SQL_STATE_ILLEGAL_ARGUMENT); //$NON-NLS-1$ + } else if ((columnIndex > this.fields.length)) { + throw SQLError.createSQLException(Messages.getString( + "ResultSet.Column_Index_out_of_range_high", new Object[] { + new Integer(columnIndex), + new Integer(this.fields.length) }), + SQLError.SQL_STATE_ILLEGAL_ARGUMENT); //$NON-NLS-1$ } if (this.profileSql || this.useUsageAdvisor) { @@ -1399,14 +1405,6 @@ checkRowPos(); checkColumnBounds(columnIndex); - - if ((columnIndex < 1) || (columnIndex > this.fields.length)) { - throw SQLError.createSQLException(Messages.getString( - "ResultSet.Column_Index_out_of_range", new Object[] { - new Integer(columnIndex), - new Integer(this.fields.length) }), - SQLError.SQL_STATE_ILLEGAL_ARGUMENT); //$NON-NLS-1$ - } try { if (this.thisRow[columnIndex - 1] == null) { @@ -1717,12 +1715,6 @@ } } catch (NullPointerException E) { this.wasNullFlag = true; - } catch (ArrayIndexOutOfBoundsException aioobEx) { - throw SQLError.createSQLException(Messages.getString( - "ResultSet.Column_Index_out_of_range", new Object[] { - new Integer(columnIndex), - new Integer(this.fields.length) }), - SQLError.SQL_STATE_ILLEGAL_ARGUMENT); //$NON-NLS-1$ } if (this.wasNullFlag) { @@ -1971,6 +1963,8 @@ return getDateFromString(stringVal, columnIndex); } else { + checkColumnBounds(columnIndex); + return getDateFromBytes(((byte[][])this.thisRow)[columnIndex - 1], columnIndex); } } @@ -2631,14 +2625,8 @@ } } catch (NullPointerException E) { this.wasNullFlag = true; - } catch (ArrayIndexOutOfBoundsException aioobEx) { - throw SQLError.createSQLException(Messages.getString( - "ResultSet.Column_Index_out_of_range", - new Object[] { new Integer(columnIndex), - new Integer(this.fields.length) }), - SQLError.SQL_STATE_ILLEGAL_ARGUMENT); //$NON-NLS-1$ } - + if (this.wasNullFlag) { return 0; } @@ -2874,14 +2862,8 @@ } } catch (NullPointerException E) { this.wasNullFlag = true; - } catch (ArrayIndexOutOfBoundsException aioobEx) { - throw SQLError.createSQLException(Messages.getString( - "ResultSet.Column_Index_out_of_range", - new Object[] { new Integer(columnIndex), - new Integer(this.fields.length) }), - SQLError.SQL_STATE_ILLEGAL_ARGUMENT); //$NON-NLS-1$ } - + if (this.wasNullFlag) { return 0; } @@ -4829,19 +4811,12 @@ */ public Object getObject(int columnIndex) throws SQLException { checkRowPos(); + checkColumnBounds(columnIndex); - try { - if (this.thisRow[columnIndex - 1] == null) { - this.wasNullFlag = true; + if (this.thisRow[columnIndex - 1] == null) { + this.wasNullFlag = true; - return null; - } - } catch (ArrayIndexOutOfBoundsException aioobEx) { - throw SQLError.createSQLException(Messages.getString( - "ResultSet.Column_Index_out_of_range", new Object[] { - new Integer(columnIndex), - new Integer(this.fields.length) }), - SQLError.SQL_STATE_ILLEGAL_ARGUMENT); //$NON-NLS-1$ + return null; } this.wasNullFlag = false; @@ -5119,19 +5094,12 @@ protected Object getObjectStoredProc(int columnIndex, int desiredSqlType) throws SQLException { checkRowPos(); + checkColumnBounds(columnIndex); - try { - if (this.thisRow[columnIndex - 1] == null) { - this.wasNullFlag = true; + if (this.thisRow[columnIndex - 1] == null) { + this.wasNullFlag = true; - return null; - } - } catch (ArrayIndexOutOfBoundsException aioobEx) { - throw SQLError.createSQLException(Messages.getString( - "ResultSet.Column_Index_out_of_range", new Object[] { - new Integer(columnIndex), - new Integer(this.fields.length) }), - SQLError.SQL_STATE_ILLEGAL_ARGUMENT); //$NON-NLS-1$ + return null; } this.wasNullFlag = false; @@ -5399,12 +5367,6 @@ } } catch (NullPointerException E) { this.wasNullFlag = true; - } catch (ArrayIndexOutOfBoundsException aioobEx) { - throw SQLError.createSQLException(Messages.getString( - "ResultSet.Column_Index_out_of_range", - new Object[] { new Integer(columnIndex), - new Integer(this.fields.length) }), - SQLError.SQL_STATE_ILLEGAL_ARGUMENT); //$NON-NLS-1$ } if (this.wasNullFlag) { @@ -6239,6 +6201,8 @@ return getTimeFromString(timeAsString, targetCalendar, columnIndex, tz, rollForward); } else { + checkColumnBounds(columnIndex); + return getTimeFromBytes(((byte[][])this.thisRow)[columnIndex - 1], targetCalendar, columnIndex, tz, rollForward); } @@ -6257,6 +6221,8 @@ * if a database access error occurs */ public Timestamp getTimestamp(int columnIndex) throws java.sql.SQLException { + checkColumnBounds(columnIndex); + return getTimestampInternal(columnIndex, null, this.getDefaultTimeZone(), false); } Modified: branches/branch_5_0/connector-j/src/testsuite/regression/ResultSetRegressionTest.java =================================================================== --- branches/branch_5_0/connector-j/src/testsuite/regression/ResultSetRegressionTest.java 2007-03-21 20:01:27 UTC (rev 6358) +++ branches/branch_5_0/connector-j/src/testsuite/regression/ResultSetRegressionTest.java 2007-03-21 20:56:58 UTC (rev 6359) @@ -25,6 +25,8 @@ package testsuite.regression; import java.io.Reader; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; import java.math.BigDecimal; import java.sql.CallableStatement; import java.sql.Clob; @@ -4058,4 +4060,78 @@ closeMemberJDBCResources(); } } + + /** + * Tests fix for BUG#27137 - column index < 1 returns misleading + * error message. + * + * @throws Exception if the test fails. + */ + public void testBug27317() throws Exception { + try { + this.rs = this.stmt.executeQuery("SELECT NULL"); + this.rs.next(); + String messageLowBound = null; + + Method[] getterMethods = ResultSet.class.getMethods(); + Integer zeroIndex = new Integer(0); + Integer twoIndex = new Integer(2); + + for (int i = 0; i < getterMethods.length; i++) { + Class[] parameterTypes = getterMethods[i].getParameterTypes(); + + if (getterMethods[i].getName().startsWith("get") + && parameterTypes.length == 1 + && (parameterTypes[0].equals(Integer.TYPE) || parameterTypes[0] + .equals(Integer.class))) { + try { + getterMethods[i].invoke(this.rs, + new Object[] { zeroIndex }); + } catch (InvocationTargetException invokeEx) { + Throwable ex = invokeEx.getTargetException(); + + if (ex != null && ex instanceof SQLException) { + SQLException sqlEx = (SQLException) ex; + + assertEquals(SQLError.SQL_STATE_ILLEGAL_ARGUMENT, + sqlEx.getSQLState()); + + messageLowBound = sqlEx.getMessage(); + } else { + throw new RuntimeException(ex); + } + } + + String messageHighBound = null; + + try { + getterMethods[i].invoke(this.rs, + new Object[] { twoIndex }); + } catch (InvocationTargetException invokeEx) { + Throwable ex = invokeEx.getTargetException(); + + if (ex != null && ex instanceof SQLException) { + SQLException sqlEx = (SQLException) ex; + + assertEquals(SQLError.SQL_STATE_ILLEGAL_ARGUMENT, + sqlEx.getSQLState()); + + messageHighBound = sqlEx.getMessage(); + } else { + throw new RuntimeException(ex); + } + } + + assertNotNull("Exception message null for method " + + getterMethods[i], messageHighBound); + assertNotNull("Exception message null for method " + + getterMethods[i], messageLowBound); + + assertTrue(!messageHighBound.equals(messageLowBound)); + } + } + } finally { + closeMemberJDBCResources(); + } + } } Modified: trunk/connector-j/CHANGES =================================================================== --- trunk/connector-j/CHANGES 2007-03-21 20:01:27 UTC (rev 6358) +++ trunk/connector-j/CHANGES 2007-03-21 20:56:58 UTC (rev 6359) @@ -58,6 +58,9 @@ - Fixed BUG#26789 - fast date/time parsing doesn't take into account 00:00:00 as a legal value. + - Fixed BUG#27137 - ResultSet.get*() with a column index < 1 returns + misleading error message. + 03-01-07 - Version 5.0.5 - Fixed BUG#23645 - Some collations/character sets reported as "unknown" Modified: trunk/connector-j/src/com/mysql/jdbc/LocalizedErrorMessages.properties =================================================================== --- trunk/connector-j/src/com/mysql/jdbc/LocalizedErrorMessages.properties 2007-03-21 20:01:27 UTC (rev 6358) +++ trunk/connector-j/src/com/mysql/jdbc/LocalizedErrorMessages.properties 2007-03-21 20:56:58 UTC (rev 6359) @@ -5,7 +5,8 @@ ResultSet.Retrieved__1=Retrieved ResultSet.Bad_format_for_BigDecimal=Bad format for BigDecimal ''{0}'' in column {1}. ResultSet.Bad_format_for_BigInteger=Bad format for BigInteger ''{0}'' in column {1}. -ResultSet.Column_Index_out_of_range=Column Index out of range, {0} > {1}. +ResultSet.Column_Index_out_of_range_low=Column Index out of range, {0} < 1. +ResultSet.Column_Index_out_of_range_high=Column Index out of range, {0} > {1}. ResultSet.Value_is_out_of_range=Value ''{0}'' is out of range [{1}, {2}]. ResultSet.Positioned_Update_not_supported=Positioned Update not supported. ResultSet.Bad_format_for_Date=Bad format for DATE ''{0}'' in column {1}. Modified: trunk/connector-j/src/com/mysql/jdbc/ResultSet.java =================================================================== --- trunk/connector-j/src/com/mysql/jdbc/ResultSet.java 2007-03-21 20:01:27 UTC (rev 6358) +++ trunk/connector-j/src/com/mysql/jdbc/ResultSet.java 2007-03-21 20:56:58 UTC (rev 6359) @@ -750,12 +750,18 @@ * if the index is out of bounds */ protected final void checkColumnBounds(int columnIndex) throws SQLException { - if ((columnIndex < 1) || (columnIndex > this.fields.length)) { + if ((columnIndex < 1)) { throw SQLError.createSQLException(Messages.getString( - "ResultSet.Column_Index_out_of_range", new Object[] { + "ResultSet.Column_Index_out_of_range_low", new Object[] { new Integer(columnIndex), new Integer(this.fields.length) }), SQLError.SQL_STATE_ILLEGAL_ARGUMENT); //$NON-NLS-1$ + } else if ((columnIndex > this.fields.length)) { + throw SQLError.createSQLException(Messages.getString( + "ResultSet.Column_Index_out_of_range_high", new Object[] { + new Integer(columnIndex), + new Integer(this.fields.length) }), + SQLError.SQL_STATE_ILLEGAL_ARGUMENT); //$NON-NLS-1$ } if (this.profileSql || this.useUsageAdvisor) { @@ -1480,14 +1486,6 @@ checkRowPos(); checkColumnBounds(columnIndex); - - if ((columnIndex < 1) || (columnIndex > this.fields.length)) { - throw SQLError.createSQLException(Messages.getString( - "ResultSet.Column_Index_out_of_range", new Object[] { - new Integer(columnIndex), - new Integer(this.fields.length) }), - SQLError.SQL_STATE_ILLEGAL_ARGUMENT); //$NON-NLS-1$ - } try { if (this.thisRow[columnIndex - 1] == null) { @@ -1798,12 +1796,6 @@ } } catch (NullPointerException E) { this.wasNullFlag = true; - } catch (ArrayIndexOutOfBoundsException aioobEx) { - throw SQLError.createSQLException(Messages.getString( - "ResultSet.Column_Index_out_of_range", new Object[] { - new Integer(columnIndex), - new Integer(this.fields.length) }), - SQLError.SQL_STATE_ILLEGAL_ARGUMENT); //$NON-NLS-1$ } if (this.wasNullFlag) { @@ -2052,6 +2044,8 @@ return getDateFromString(stringVal, columnIndex); } else { + checkColumnBounds(columnIndex); + return getDateFromBytes(((byte[][])this.thisRow)[columnIndex - 1], columnIndex); } } @@ -2712,12 +2706,6 @@ } } catch (NullPointerException E) { this.wasNullFlag = true; - } catch (ArrayIndexOutOfBoundsException aioobEx) { - throw SQLError.createSQLException(Messages.getString( - "ResultSet.Column_Index_out_of_range", - new Object[] { new Integer(columnIndex), - new Integer(this.fields.length) }), - SQLError.SQL_STATE_ILLEGAL_ARGUMENT); //$NON-NLS-1$ } if (this.wasNullFlag) { @@ -2955,12 +2943,6 @@ } } catch (NullPointerException E) { this.wasNullFlag = true; - } catch (ArrayIndexOutOfBoundsException aioobEx) { - throw SQLError.createSQLException(Messages.getString( - "ResultSet.Column_Index_out_of_range", - new Object[] { new Integer(columnIndex), - new Integer(this.fields.length) }), - SQLError.SQL_STATE_ILLEGAL_ARGUMENT); //$NON-NLS-1$ } if (this.wasNullFlag) { @@ -4929,21 +4911,14 @@ */ public Object getObject(int columnIndex) throws SQLException { checkRowPos(); + checkColumnBounds(columnIndex); + + if (this.thisRow[columnIndex - 1] == null) { + this.wasNullFlag = true; - try { - if (this.thisRow[columnIndex - 1] == null) { - this.wasNullFlag = true; - - return null; - } - } catch (ArrayIndexOutOfBoundsException aioobEx) { - throw SQLError.createSQLException(Messages.getString( - "ResultSet.Column_Index_out_of_range", new Object[] { - new Integer(columnIndex), - new Integer(this.fields.length) }), - SQLError.SQL_STATE_ILLEGAL_ARGUMENT); //$NON-NLS-1$ + return null; } - + this.wasNullFlag = false; Field field; @@ -5219,21 +5194,14 @@ protected Object getObjectStoredProc(int columnIndex, int desiredSqlType) throws SQLException { checkRowPos(); + checkColumnBounds(columnIndex); - try { - if (this.thisRow[columnIndex - 1] == null) { - this.wasNullFlag = true; + if (this.thisRow[columnIndex - 1] == null) { + this.wasNullFlag = true; - return null; - } - } catch (ArrayIndexOutOfBoundsException aioobEx) { - throw SQLError.createSQLException(Messages.getString( - "ResultSet.Column_Index_out_of_range", new Object[] { - new Integer(columnIndex), - new Integer(this.fields.length) }), - SQLError.SQL_STATE_ILLEGAL_ARGUMENT); //$NON-NLS-1$ + return null; } - + this.wasNullFlag = false; Field field; @@ -5499,14 +5467,8 @@ } } catch (NullPointerException E) { this.wasNullFlag = true; - } catch (ArrayIndexOutOfBoundsException aioobEx) { - throw SQLError.createSQLException(Messages.getString( - "ResultSet.Column_Index_out_of_range", - new Object[] { new Integer(columnIndex), - new Integer(this.fields.length) }), - SQLError.SQL_STATE_ILLEGAL_ARGUMENT); //$NON-NLS-1$ } - + if (this.wasNullFlag) { return 0; } @@ -6339,6 +6301,8 @@ return getTimeFromString(timeAsString, targetCalendar, columnIndex, tz, rollForward); } else { + checkColumnBounds(columnIndex); + return getTimeFromBytes(((byte[][])this.thisRow)[columnIndex - 1], targetCalendar, columnIndex, tz, rollForward); } @@ -6357,6 +6321,8 @@ * if a database access error occurs */ public Timestamp getTimestamp(int columnIndex) throws java.sql.SQLException { + checkColumnBounds(columnIndex); + return getTimestampInternal(columnIndex, null, this.getDefaultTimeZone(), false); } Modified: trunk/connector-j/src/testsuite/regression/ResultSetRegressionTest.java =================================================================== --- trunk/connector-j/src/testsuite/regression/ResultSetRegressionTest.java 2007-03-21 20:01:27 UTC (rev 6358) +++ trunk/connector-j/src/testsuite/regression/ResultSetRegressionTest.java 2007-03-21 20:56:58 UTC (rev 6359) @@ -25,6 +25,8 @@ package testsuite.regression; import java.io.Reader; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; import java.math.BigDecimal; import java.sql.CallableStatement; import java.sql.Clob; @@ -4058,4 +4060,78 @@ closeMemberJDBCResources(); } } + + /** + * Tests fix for BUG#27137 - column index < 1 returns misleading + * error message. + * + * @throws Exception if the test fails. + */ + public void testBug27317() throws Exception { + try { + this.rs = this.stmt.executeQuery("SELECT NULL"); + this.rs.next(); + String messageLowBound = null; + + Method[] getterMethods = ResultSet.class.getMethods(); + Integer zeroIndex = new Integer(0); + Integer twoIndex = new Integer(2); + + for (int i = 0; i < getterMethods.length; i++) { + Class[] parameterTypes = getterMethods[i].getParameterTypes(); + + if (getterMethods[i].getName().startsWith("get") + && parameterTypes.length == 1 + && (parameterTypes[0].equals(Integer.TYPE) || parameterTypes[0] + .equals(Integer.class))) { + try { + getterMethods[i].invoke(this.rs, + new Object[] { zeroIndex }); + } catch (InvocationTargetException invokeEx) { + Throwable ex = invokeEx.getTargetException(); + + if (ex != null && ex instanceof SQLException) { + SQLException sqlEx = (SQLException) ex; + + assertEquals(SQLError.SQL_STATE_ILLEGAL_ARGUMENT, + sqlEx.getSQLState()); + + messageLowBound = sqlEx.getMessage(); + } else { + throw new RuntimeException(ex); + } + } + + String messageHighBound = null; + + try { + getterMethods[i].invoke(this.rs, + new Object[] { twoIndex }); + } catch (InvocationTargetException invokeEx) { + Throwable ex = invokeEx.getTargetException(); + + if (ex != null && ex instanceof SQLException) { + SQLException sqlEx = (SQLException) ex; + + assertEquals(SQLError.SQL_STATE_ILLEGAL_ARGUMENT, + sqlEx.getSQLState()); + + messageHighBound = sqlEx.getMessage(); + } else { + throw new RuntimeException(ex); + } + } + + assertNotNull("Exception message null for method " + + getterMethods[i], messageHighBound); + assertNotNull("Exception message null for method " + + getterMethods[i], messageLowBound); + + assertTrue(!messageHighBound.equals(messageLowBound)); + } + } + } finally { + closeMemberJDBCResources(); + } + } }