diff --git a/src/share/classes/javax/sql/rowset/serial/SerialClob.java b/src/share/classes/javax/sql/rowset/serial/SerialClob.java index ff482082e7c76e937d38be6a865d7753e71df03c..ad7238d1baf8dafbd8a7bf2c670dc09b9316b2c4 100644 --- a/src/share/classes/javax/sql/rowset/serial/SerialClob.java +++ b/src/share/classes/javax/sql/rowset/serial/SerialClob.java @@ -57,10 +57,10 @@ public class SerialClob implements Clob, Serializable, Cloneable { private char buf[]; /** - * Internal Clob representation if SerialClob is intialized with a - * Clob + * Internal Clob representation if SerialClob is initialized with a + * Clob. Null if SerialClob is initialized with a char[]. */ - private Clob clob; + private final Clob clob; /** * The length in characters of this SerialClob object's @@ -71,12 +71,12 @@ public class SerialClob implements Clob, Serializable, Cloneable { private long len; /** - * The original length in characters of tgus SerialClob - * objects internal array of characters. + * The original length in characters of this SerialClob + * object's internal array of characters. * * @serial */ - private long origLen; + private final long origLen; /** * Constructs a SerialClob object that is a serialized version of @@ -104,6 +104,7 @@ public class SerialClob implements Clob, Serializable, Cloneable { buf[i] = ch[i]; } origLen = len; + clob = null; } /** @@ -117,19 +118,19 @@ public class SerialClob implements Clob, Serializable, Cloneable { * the database. Otherwise, the new SerialClob object * object will contain no data. *

- * Note: The Clob object supplied to this constructor cannot - * return null for the Clob.getCharacterStream() + * Note: The Clob object supplied to this constructor must + * return non-null for both the Clob.getCharacterStream() * and Clob.getAsciiStream methods. This SerialClob - * constructor cannot serialize a Clob object in this instance + * constructor cannot serialize a Clob object in this instance * and will throw an SQLException object. * * @param clob the Clob object from which this * SerialClob object is to be constructed; cannot be null * @throws SerialException if an error occurs during serialization * @throws SQLException if a SQL error occurs in capturing the CLOB; - * if the Clob object is a null; or if both the + * if the Clob object is a null; or if either of the * Clob.getCharacterStream() and Clob.getAsciiStream() - * methods on the Clob return a null + * methods on the Clob returns a null * @see java.sql.Clob */ public SerialClob(Clob clob) throws SerialException, SQLException { @@ -144,19 +145,27 @@ public class SerialClob implements Clob, Serializable, Cloneable { int read = 0; int offset = 0; - BufferedReader reader; - if ( (((reader = new BufferedReader(clob.getCharacterStream())) == null)) && - (clob.getAsciiStream() == null)) { - throw new SQLException("Invalid Clob object. Calls to getCharacterStream " + - "and getAsciiStream return null which cannot be serialized."); - } + try (Reader charStream = clob.getCharacterStream()) { + if (charStream == null) { + throw new SQLException("Invalid Clob object. The call to getCharacterStream " + + "returned null which cannot be serialized."); + } - try { - do { - read = reader.read(buf, offset, (int)(len - offset)); - offset += read; - } while (read > 0); + // Note: get an ASCII stream in order to null-check it, + // even though we don't do anything with it. + try (InputStream asciiStream = clob.getAsciiStream()) { + if (asciiStream == null) { + throw new SQLException("Invalid Clob object. The call to getAsciiStream " + + "returned null which cannot be serialized."); + } + } + try (Reader reader = new BufferedReader(charStream)) { + do { + read = reader.read(buf, offset, (int)(len - offset)); + offset += read; + } while (read > 0); + } } catch (java.io.IOException ex) { throw new SerialException("SerialClob: " + ex.getMessage()); } @@ -207,13 +216,13 @@ public class SerialClob implements Clob, Serializable, Cloneable { * used to create this SerialClob object */ public java.io.InputStream getAsciiStream() throws SerialException, SQLException { - if (this.clob != null) { - return this.clob.getAsciiStream(); - } else { - throw new SerialException("Unsupported operation. SerialClob cannot " + + if (this.clob != null) { + return this.clob.getAsciiStream(); + } else { + throw new SerialException("Unsupported operation. SerialClob cannot " + "return a the CLOB value as an ascii stream, unless instantiated " + "with a fully implemented Clob object."); - } + } } /** diff --git a/src/share/classes/javax/sql/rowset/spi/SyncFactory.java b/src/share/classes/javax/sql/rowset/spi/SyncFactory.java index f3358e0fb12b43805526fb3135c563a722484f5b..b52f345caf5b45d3e22194742113453ebac9207c 100644 --- a/src/share/classes/javax/sql/rowset/spi/SyncFactory.java +++ b/src/share/classes/javax/sql/rowset/spi/SyncFactory.java @@ -32,6 +32,7 @@ import java.sql.*; import javax.sql.*; import java.io.FileInputStream; +import java.io.InputStream; import java.io.IOException; import java.io.FileNotFoundException; @@ -366,7 +367,9 @@ public class SyncFactory { // Load user's implementation of SyncProvider // here. -Drowset.properties=/abc/def/pqr.txt ROWSET_PROPERTIES = strRowsetProperties; - properties.load(new FileInputStream(ROWSET_PROPERTIES)); + try (FileInputStream fis = new FileInputStream(ROWSET_PROPERTIES)) { + properties.load(fis); + } parseProperties(properties); } @@ -376,12 +379,19 @@ public class SyncFactory { ROWSET_PROPERTIES = "javax" + strFileSep + "sql" + strFileSep + "rowset" + strFileSep + "rowset.properties"; - // properties.load( - // ClassLoader.getSystemResourceAsStream(ROWSET_PROPERTIES)); ClassLoader cl = Thread.currentThread().getContextClassLoader(); - properties.load(cl.getResourceAsStream(ROWSET_PROPERTIES)); + try (InputStream stream = + (cl == null) ? ClassLoader.getSystemResourceAsStream(ROWSET_PROPERTIES) + : cl.getResourceAsStream(ROWSET_PROPERTIES)) { + if (stream == null) { + throw new SyncFactoryException( + "Resource " + ROWSET_PROPERTIES + " not found"); + } + properties.load(stream); + } + parseProperties(properties); // removed else, has properties should sum together