From f40d1f5d55ef9e119380c88fd843cd5da58cc097 Mon Sep 17 00:00:00 2001 From: lancea Date: Wed, 10 Aug 2011 16:23:56 -0400 Subject: [PATCH] 7077451: SerialLob, SerialClob have the wrong checks for setStream methods Reviewed-by: alanb Contributed-by: Patrick Reinhart --- .../javax/sql/rowset/serial/SerialBlob.java | 4 +- .../javax/sql/rowset/serial/SerialClob.java | 4 +- .../serial/SerialBlob/SetBinaryStream.java | 42 +++++++++++++++++++ .../serial/SerialClob/SetAsciiStream.java | 42 +++++++++++++++++++ .../serial/SerialClob/SetCharacterStream.java | 42 +++++++++++++++++++ 5 files changed, 130 insertions(+), 4 deletions(-) create mode 100644 test/javax/sql/rowset/serial/SerialBlob/SetBinaryStream.java create mode 100644 test/javax/sql/rowset/serial/SerialClob/SetAsciiStream.java create mode 100644 test/javax/sql/rowset/serial/SerialClob/SetCharacterStream.java diff --git a/src/share/classes/javax/sql/rowset/serial/SerialBlob.java b/src/share/classes/javax/sql/rowset/serial/SerialBlob.java index aed11246d..795e404fd 100644 --- a/src/share/classes/javax/sql/rowset/serial/SerialBlob.java +++ b/src/share/classes/javax/sql/rowset/serial/SerialBlob.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2003, 2011, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -382,7 +382,7 @@ public class SerialBlob implements Blob, Serializable, Cloneable { */ public java.io.OutputStream setBinaryStream(long pos) throws SerialException, SQLException { - if (this.blob.setBinaryStream(pos) != null) { + if (this.blob != null) { return this.blob.setBinaryStream(pos); } else { throw new SerialException("Unsupported operation. SerialBlob cannot " + diff --git a/src/share/classes/javax/sql/rowset/serial/SerialClob.java b/src/share/classes/javax/sql/rowset/serial/SerialClob.java index 3792ebd3b..97e899508 100644 --- a/src/share/classes/javax/sql/rowset/serial/SerialClob.java +++ b/src/share/classes/javax/sql/rowset/serial/SerialClob.java @@ -436,7 +436,7 @@ public class SerialClob implements Clob, Serializable, Cloneable { */ public java.io.OutputStream setAsciiStream(long pos) throws SerialException, SQLException { - if (this.clob.setAsciiStream(pos) != null) { + if (this.clob != null) { return this.clob.setAsciiStream(pos); } else { throw new SerialException("Unsupported operation. SerialClob cannot " + @@ -466,7 +466,7 @@ public class SerialClob implements Clob, Serializable, Cloneable { */ public java.io.Writer setCharacterStream(long pos) throws SerialException, SQLException { - if (this.clob.setCharacterStream(pos) != null) { + if (this.clob != null) { return this.clob.setCharacterStream(pos); } else { throw new SerialException("Unsupported operation. SerialClob cannot " + diff --git a/test/javax/sql/rowset/serial/SerialBlob/SetBinaryStream.java b/test/javax/sql/rowset/serial/SerialBlob/SetBinaryStream.java new file mode 100644 index 000000000..a2d7ea2f8 --- /dev/null +++ b/test/javax/sql/rowset/serial/SerialBlob/SetBinaryStream.java @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +import javax.sql.rowset.serial.SerialBlob; +import javax.sql.rowset.serial.SerialException; + +/** + * @test + * @bug 7077451 + * @summary tests if the correct exception is thrown when calling method setBinaryStream() on SerialBlob + */ +public class SetBinaryStream { + + public static void main(String[] args) throws Exception { + SerialBlob blob = new SerialBlob(new byte[0]); + try { + blob.setBinaryStream(0); + } catch (SerialException e) { + System.out.println("Test PASSED"); + } + } + +} diff --git a/test/javax/sql/rowset/serial/SerialClob/SetAsciiStream.java b/test/javax/sql/rowset/serial/SerialClob/SetAsciiStream.java new file mode 100644 index 000000000..10deaf523 --- /dev/null +++ b/test/javax/sql/rowset/serial/SerialClob/SetAsciiStream.java @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +import javax.sql.rowset.serial.SerialClob; +import javax.sql.rowset.serial.SerialException; + +/** + * @test + * @bug 7077451 + * @summary tests if the correct exception is thrown when calling method setAsciiStream() on SerialClob + */ +public class SetAsciiStream { + + public static void main(String[] args) throws Exception { + SerialClob clob = new SerialClob(new char[0]); + try { + clob.setAsciiStream(0); + } catch (SerialException e) { + System.out.println("Test PASSED"); + } + } + +} diff --git a/test/javax/sql/rowset/serial/SerialClob/SetCharacterStream.java b/test/javax/sql/rowset/serial/SerialClob/SetCharacterStream.java new file mode 100644 index 000000000..be861e437 --- /dev/null +++ b/test/javax/sql/rowset/serial/SerialClob/SetCharacterStream.java @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +import javax.sql.rowset.serial.SerialClob; +import javax.sql.rowset.serial.SerialException; + +/** + * @test + * @bug 7077451 + * @summary tests if the correct exception is thrown when calling method setCharacterStream() on SerialClob + */ +public class SetCharacterStream { + + public static void main(String[] args) throws Exception { + SerialClob clob = new SerialClob(new char[0]); + try { + clob.setCharacterStream(0); + } catch (SerialException e) { + System.out.println("Test PASSED"); + } + } + +} -- GitLab