Return-Path: Delivered-To: apmail-harmony-commits-archive@www.apache.org Received: (qmail 15615 invoked from network); 11 May 2007 20:35:23 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 11 May 2007 20:35:23 -0000 Received: (qmail 72321 invoked by uid 500); 11 May 2007 20:35:29 -0000 Delivered-To: apmail-harmony-commits-archive@harmony.apache.org Received: (qmail 72302 invoked by uid 500); 11 May 2007 20:35:29 -0000 Mailing-List: contact commits-help@harmony.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@harmony.apache.org Delivered-To: mailing list commits@harmony.apache.org Received: (qmail 72289 invoked by uid 99); 11 May 2007 20:35:29 -0000 Received: from herse.apache.org (HELO herse.apache.org) (140.211.11.133) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 11 May 2007 13:35:29 -0700 X-ASF-Spam-Status: No, hits=-99.5 required=10.0 tests=ALL_TRUSTED,NO_REAL_NAME X-Spam-Check-By: apache.org Received: from [140.211.11.3] (HELO eris.apache.org) (140.211.11.3) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 11 May 2007 13:35:22 -0700 Received: by eris.apache.org (Postfix, from userid 65534) id 0193D1A9838; Fri, 11 May 2007 13:35:01 -0700 (PDT) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r537283 - in /harmony/enhanced/classlib/trunk/modules/sql/src: main/java/javax/sql/rowset/serial/ main/java/org/apache/harmony/sql/internal/nls/ test/java/org/apache/harmony/sql/tests/javax/sql/rowset/serial/ Date: Fri, 11 May 2007 20:35:01 -0000 To: commits@harmony.apache.org From: tellison@apache.org X-Mailer: svnmailer-1.1.0 Message-Id: <20070511203502.0193D1A9838@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: tellison Date: Fri May 11 13:35:01 2007 New Revision: 537283 URL: http://svn.apache.org/viewvc?view=rev&rev=537283 Log: Apply patch HARMONY-3826 ([classlib][sql] SQLInputImpl throws NullPointerException when the param of readXXX is null) Modified: harmony/enhanced/classlib/trunk/modules/sql/src/main/java/javax/sql/rowset/serial/SQLInputImpl.java harmony/enhanced/classlib/trunk/modules/sql/src/main/java/org/apache/harmony/sql/internal/nls/messages.properties harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/javax/sql/rowset/serial/SQLInputImplTest.java Modified: harmony/enhanced/classlib/trunk/modules/sql/src/main/java/javax/sql/rowset/serial/SQLInputImpl.java URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/sql/src/main/java/javax/sql/rowset/serial/SQLInputImpl.java?view=diff&rev=537283&r1=537282&r2=537283 ============================================================================== --- harmony/enhanced/classlib/trunk/modules/sql/src/main/java/javax/sql/rowset/serial/SQLInputImpl.java (original) +++ harmony/enhanced/classlib/trunk/modules/sql/src/main/java/javax/sql/rowset/serial/SQLInputImpl.java Fri May 11 13:35:01 2007 @@ -77,12 +77,9 @@ */ public Array readArray() throws SQLException { if(readPosition >= attributes.length) { - throw new SQLException(Messages.getString("sql.35")); - } - Object o = attributes[readPosition++]; - if(o == null) { - return null; + throw new SQLException(Messages.getString("sql.35")); //$NON-NLS-1$ } + Object o = attributes[readPosition++]; return (Array) o; } @@ -93,12 +90,9 @@ */ public InputStream readAsciiStream() throws SQLException { if(readPosition >= attributes.length) { - throw new SQLException(Messages.getString("sql.35")); + throw new SQLException(Messages.getString("sql.35")); //$NON-NLS-1$ } Object o = attributes[readPosition++]; - if(o == null) { - return null; - } return (InputStream) o; } @@ -109,12 +103,9 @@ */ public BigDecimal readBigDecimal() throws SQLException { if(readPosition >= attributes.length) { - throw new SQLException(Messages.getString("sql.35")); + throw new SQLException(Messages.getString("sql.35")); //$NON-NLS-1$ } Object o = attributes[readPosition++]; - if(o == null) { - return null; - } return (BigDecimal) o; } @@ -125,12 +116,9 @@ */ public InputStream readBinaryStream() throws SQLException { if(readPosition >= attributes.length) { - throw new SQLException(Messages.getString("sql.35")); + throw new SQLException(Messages.getString("sql.35")); //$NON-NLS-1$ } Object o = attributes[readPosition++]; - if(o == null) { - return null; - } return (InputStream) o; } @@ -141,12 +129,9 @@ */ public Blob readBlob() throws SQLException { if(readPosition >= attributes.length) { - throw new SQLException(Messages.getString("sql.35")); + throw new SQLException(Messages.getString("sql.35")); //$NON-NLS-1$ } Object o = attributes[readPosition++]; - if(o == null) { - return null; - } return (Blob) o; } @@ -157,10 +142,10 @@ */ public boolean readBoolean() throws SQLException, NotImplementedException { if(readPosition >= attributes.length) { - throw new SQLException(Messages.getString("sql.35")); + throw new SQLException(Messages.getString("sql.35")); //$NON-NLS-1$ } Object o = attributes[readPosition++]; - return (Boolean) o; + return o == null ? false : ((Boolean) o).booleanValue(); } /** @@ -170,10 +155,10 @@ */ public byte readByte() throws SQLException { if(readPosition >= attributes.length) { - throw new SQLException(Messages.getString("sql.35")); + throw new SQLException(Messages.getString("sql.35")); //$NON-NLS-1$ } - Object o = attributes[readPosition++]; - return (Byte) o; + Object o = attributes[readPosition++]; + return o == null ? (byte) 0 : ((Byte) o).byteValue(); } /** @@ -183,12 +168,9 @@ */ public byte[] readBytes() throws SQLException { if(readPosition >= attributes.length) { - throw new SQLException(Messages.getString("sql.35")); - } - Object o = attributes[readPosition++]; - if(o == null) { - return null; + throw new SQLException(Messages.getString("sql.35")); //$NON-NLS-1$ } + Object o = attributes[readPosition++]; return (byte[]) o; } @@ -199,28 +181,22 @@ */ public Reader readCharacterStream() throws SQLException { if(readPosition >= attributes.length) { - throw new SQLException(Messages.getString("sql.35")); + throw new SQLException(Messages.getString("sql.35")); //$NON-NLS-1$ } Object o = attributes[readPosition++]; - if(o == null) { - return null; - } return (Reader) o; } - /** + /** * {@inheritDoc} * * @see java.sql.SQLInput#readClob() */ public Clob readClob() throws SQLException { if(readPosition >= attributes.length) { - throw new SQLException(Messages.getString("sql.35")); - } - Object o = attributes[readPosition++]; - if(o == null) { - return null; + throw new SQLException(Messages.getString("sql.35")); //$NON-NLS-1$ } + Object o = attributes[readPosition++]; return (Clob) o; } @@ -231,12 +207,9 @@ */ public Date readDate() throws SQLException { if(readPosition >= attributes.length) { - throw new SQLException(Messages.getString("sql.35")); + throw new SQLException(Messages.getString("sql.35")); //$NON-NLS-1$ } Object o = attributes[readPosition++]; - if(o == null) { - return null; - } return (Date) o; } @@ -247,10 +220,10 @@ */ public double readDouble() throws SQLException { if(readPosition >= attributes.length) { - throw new SQLException(Messages.getString("sql.35")); + throw new SQLException(Messages.getString("sql.35")); //$NON-NLS-1$ } Object o = attributes[readPosition++]; - return (Double) o; + return o == null ? 0 : ((Double) o).doubleValue(); } /** @@ -260,10 +233,10 @@ */ public float readFloat() throws SQLException { if(readPosition >= attributes.length) { - throw new SQLException(Messages.getString("sql.35")); + throw new SQLException(Messages.getString("sql.35")); //$NON-NLS-1$ } Object o = attributes[readPosition++]; - return (Float) o; + return o == null ? 0f : ((Float) o).floatValue(); } /** @@ -273,10 +246,10 @@ */ public int readInt() throws SQLException { if(readPosition >= attributes.length) { - throw new SQLException(Messages.getString("sql.35")); + throw new SQLException(Messages.getString("sql.35")); //$NON-NLS-1$ } Object o = attributes[readPosition++]; - return (Integer) o; + return o == null ? 0 : ((Integer) o).intValue(); } /** @@ -286,10 +259,10 @@ */ public long readLong() throws SQLException { if(readPosition >= attributes.length) { - throw new SQLException(Messages.getString("sql.35")); + throw new SQLException(Messages.getString("sql.35")); //$NON-NLS-1$ } Object o = attributes[readPosition++]; - return (Long) o; + return o == null ? 0 : ((Long) o).longValue(); } /** @@ -299,13 +272,13 @@ */ public Object readObject() throws SQLException { if(readPosition >= attributes.length) { - throw new SQLException(Messages.getString("sql.35")); + throw new SQLException(Messages.getString("sql.35")); //$NON-NLS-1$ } Object o = attributes[readPosition++]; if (o instanceof Struct) { Struct structuredType = (Struct)o; String typeName = structuredType.getSQLTypeName(); - Class c = map.get(typeName); + Class c = map.get(typeName); if(c != null) { try { SQLData data = (SQLData)c.newInstance(); @@ -330,12 +303,9 @@ */ public Ref readRef() throws SQLException { if(readPosition >= attributes.length) { - throw new SQLException(Messages.getString("sql.35")); - } - Object o = attributes[readPosition++]; - if(o == null) { - return null; + throw new SQLException(Messages.getString("sql.35")); //$NON-NLS-1$ } + Object o = attributes[readPosition++]; return (Ref) o; } @@ -346,10 +316,10 @@ */ public short readShort() throws SQLException { if(readPosition >= attributes.length) { - throw new SQLException(Messages.getString("sql.35")); + throw new SQLException(Messages.getString("sql.35")); //$NON-NLS-1$ } Object o = attributes[readPosition++]; - return (Short) o; + return o == null ? (short) 0 : ((Short) o).shortValue(); } /** @@ -359,12 +329,9 @@ */ public String readString() throws SQLException { if(readPosition >= attributes.length) { - throw new SQLException(Messages.getString("sql.35")); - } - Object o = attributes[readPosition++]; - if(o == null) { - return null; + throw new SQLException(Messages.getString("sql.35")); //$NON-NLS-1$ } + Object o = attributes[readPosition++]; return (String) o; } @@ -375,12 +342,9 @@ */ public Time readTime() throws SQLException { if(readPosition >= attributes.length) { - throw new SQLException(Messages.getString("sql.35")); + throw new SQLException(Messages.getString("sql.35")); //$NON-NLS-1$ } Object o = attributes[readPosition++]; - if(o == null) { - return null; - } return (Time) o; } @@ -391,12 +355,9 @@ */ public Timestamp readTimestamp() throws SQLException { if(readPosition >= attributes.length) { - throw new SQLException(Messages.getString("sql.35")); + throw new SQLException(Messages.getString("sql.35")); //$NON-NLS-1$ } Object o = attributes[readPosition++]; - if(o == null) { - return null; - } return (Timestamp) o; } @@ -407,10 +368,9 @@ */ public URL readURL() throws SQLException { if(readPosition >= attributes.length) { - throw new SQLException(Messages.getString("sql.35")); - } else { - throw new SQLException(Messages.getString("sql.37")); - } + throw new SQLException(Messages.getString("sql.35")); //$NON-NLS-1$ + } + throw new SQLException(Messages.getString("sql.37")); //$NON-NLS-1$ } /** @@ -419,10 +379,10 @@ * @see java.sql.SQLInput#wasNull() */ public boolean wasNull() throws SQLException, NotImplementedException { - if(readPosition > attributes.length) { - throw new SQLException(Messages.getString("sql.35")); + if (readPosition > attributes.length) { + throw new SQLException(Messages.getString("sql.35")); //$NON-NLS-1$ } - return attributes[readPosition - 1] == null; + return readPosition == 0 ? false : attributes[readPosition - 1] == null; } } Modified: harmony/enhanced/classlib/trunk/modules/sql/src/main/java/org/apache/harmony/sql/internal/nls/messages.properties URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/sql/src/main/java/org/apache/harmony/sql/internal/nls/messages.properties?view=diff&rev=537283&r1=537282&r2=537283 ============================================================================== --- harmony/enhanced/classlib/trunk/modules/sql/src/main/java/org/apache/harmony/sql/internal/nls/messages.properties (original) +++ harmony/enhanced/classlib/trunk/modules/sql/src/main/java/org/apache/harmony/sql/internal/nls/messages.properties Fri May 11 13:35:01 2007 @@ -46,4 +46,8 @@ sql.29=Invalid nullable constant set. Must be either columnNoNulls, columnNullable or columnNullableUnknown sql.30=Invalid column display size. Cannot be less than zero sql.31=Invalid precision value. Cannot be less than zero -sql.32=Invalid scale size. Cannot be less than zero \ No newline at end of file +sql.32=Invalid scale size. Cannot be less than zero +sql.33=Cannot instantiate a SQLOutputImpl instance with null parameters +sql.34=Cannot instantiate a SQLInputImpl instance with null parameters +sql.35=SQLInputImpl exception: Invalid read position +sql.37=Operation not supported \ No newline at end of file Modified: harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/javax/sql/rowset/serial/SQLInputImplTest.java URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/javax/sql/rowset/serial/SQLInputImplTest.java?view=diff&rev=537283&r1=537282&r2=537283 ============================================================================== --- harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/javax/sql/rowset/serial/SQLInputImplTest.java (original) +++ harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/javax/sql/rowset/serial/SQLInputImplTest.java Fri May 11 13:35:01 2007 @@ -40,6 +40,7 @@ import java.util.Map; import javax.sql.rowset.serial.SQLInputImpl; +import javax.sql.rowset.serial.SerialDatalink; import junit.framework.TestCase; @@ -91,9 +92,13 @@ try { impl.readArray(); fail("should throw SQLException"); - } catch (SQLException e) { + } catch (SQLException e) { // expected } + + attributes = new Object[] {null}; + impl = new SQLInputImpl(attributes, new HashMap>()); + assertNull(impl.readArray()); } /** @@ -111,6 +116,10 @@ } catch (SQLException e) { // expected } + + attributes = new Object[] {null}; + impl = new SQLInputImpl(attributes, new HashMap>()); + assertNull(impl.readAsciiStream()); } /** @@ -128,6 +137,10 @@ } catch (SQLException e) { // expected } + + attributes = new Object[] {null}; + impl = new SQLInputImpl(attributes, new HashMap>()); + assertNull(impl.readBigDecimal()); } /** @@ -138,6 +151,10 @@ Object[] attributes = new Object[] {stream}; SQLInputImpl impl = new SQLInputImpl(attributes, new HashMap>()); assertEquals(stream, impl.readBinaryStream()); + + attributes = new Object[] {null}; + impl = new SQLInputImpl(attributes, new HashMap>()); + assertNull(impl.readBinaryStream()); } /** @@ -155,6 +172,10 @@ } catch (SQLException e) { // expected } + + attributes = new Object[] {null}; + impl = new SQLInputImpl(attributes, new HashMap>()); + assertNull(impl.readBlob()); } /** @@ -171,6 +192,10 @@ } catch (SQLException e) { // expected } + + attributes = new Object[] {null}; + impl = new SQLInputImpl(attributes, new HashMap>()); + assertFalse(impl.readBoolean()); } /** @@ -187,6 +212,10 @@ } catch (SQLException e) { // expected } + + attributes = new Object[] {null}; + impl = new SQLInputImpl(attributes, new HashMap>()); + assertEquals((byte)0, impl.readByte()); } /** @@ -204,6 +233,10 @@ } catch (SQLException e) { // expected } + + attributes = new Object[] {null}; + impl = new SQLInputImpl(attributes, new HashMap>()); + assertNull(impl.readBytes()); } /** @@ -221,6 +254,10 @@ } catch (SQLException e) { // expected } + + attributes = new Object[] {null}; + impl = new SQLInputImpl(attributes, new HashMap>()); + assertNull(impl.readCharacterStream()); } /** @@ -238,6 +275,10 @@ } catch (SQLException e) { // expected } + + attributes = new Object[] {null}; + impl = new SQLInputImpl(attributes, new HashMap>()); + assertNull(impl.readClob()); } /** @@ -255,6 +296,10 @@ } catch (SQLException e) { // expected } + + attributes = new Object[] {null}; + impl = new SQLInputImpl(attributes, new HashMap>()); + assertNull(impl.readDate()); } /** @@ -271,6 +316,10 @@ } catch (SQLException e) { // expected } + + attributes = new Object[] {null}; + impl = new SQLInputImpl(attributes, new HashMap>()); + assertEquals(0, impl.readDouble(), 0); } /** @@ -287,6 +336,10 @@ } catch (SQLException e) { // expected } + + attributes = new Object[] {null}; + impl = new SQLInputImpl(attributes, new HashMap>()); + assertEquals(0f, impl.readFloat(), 0); } /** @@ -303,6 +356,10 @@ } catch (SQLException e) { // expected } + + attributes = new Object[] {null}; + impl = new SQLInputImpl(attributes, new HashMap>()); + assertEquals(0, impl.readInt()); } /** @@ -319,6 +376,10 @@ } catch (SQLException e) { // expected } + + attributes = new Object[] {null}; + impl = new SQLInputImpl(attributes, new HashMap>()); + assertEquals(0, impl.readLong()); } /** @@ -362,6 +423,10 @@ } catch (SQLException e) { // expected } + + attributes = new Object[] {null}; + impl = new SQLInputImpl(attributes, new HashMap>()); + assertNull(impl.readRef()); } /** @@ -378,6 +443,10 @@ } catch (SQLException e) { // expected } + + attributes = new Object[] {null}; + impl = new SQLInputImpl(attributes, new HashMap>()); + assertEquals((short)0, impl.readShort()); } /** @@ -394,6 +463,10 @@ } catch (SQLException e) { // expected } + + attributes = new Object[] {null}; + impl = new SQLInputImpl(attributes, new HashMap>()); + assertNull(impl.readString()); } /** @@ -411,6 +484,10 @@ } catch (SQLException e) { // expected } + + attributes = new Object[] {null}; + impl = new SQLInputImpl(attributes, new HashMap>()); + assertNull(impl.readTime()); } /** @@ -435,7 +512,8 @@ */ public void testReadURL() throws SQLException, MalformedURLException { URL url = new URL("http://www.apache.org"); - Object[] attributes = new Object[] {url}; + SerialDatalink link = new SerialDatalink(url); + Object[] attributes = new Object[] {link}; SQLInputImpl impl = new SQLInputImpl(attributes, new HashMap>()); try { impl.readURL(); @@ -458,6 +536,7 @@ public void testWasNull() throws SQLException { Object[] attributes = new Object[] {null, "hello"}; SQLInputImpl impl = new SQLInputImpl(attributes, new HashMap>()); + assertFalse(impl.wasNull()); assertEquals(null, impl.readString()); assertTrue(impl.wasNull()); assertEquals("hello", impl.readString()); @@ -468,6 +547,7 @@ } catch (SQLException e) { // expected } + assertFalse(impl.wasNull()); assertFalse(impl.wasNull()); }