This was a method change FilterOutputStream.close()in Java 8, which caused some problems. (See http://hg.openjdk.java.net/jdk8/jdk8/jdk/rev/759aa847dcaf )
In previous versions of Java, the following code worked without exception. However, in Java 8, we always get an exception when the try-with-resources mechanism closes threads.
try( InputStream bis = new BufferedInputStream( inputStream );
OutputStream outStream = payloadData.setBinaryStream( 0 );
BufferedOutputStream bos = new BufferedOutputStream( outStream );
DeflaterOutputStream deflaterStream = new DeflaterOutputStream(
bos, new Deflater( 3 ) ) )
{
fileSize = IOUtil.copy( bis, deflaterStream );
}
The try-with-resources mechanism will first call close()on deflaterStream. Since deflaterStreamwraps boswhich wraps outStream, deflaterStream.close()is bos.close()that calls outStream.close(), which closes the base flow in the database.
The try-with-resources mechanism will then call close()on bos. As it boscontinues FilterOutputStream, it flush()will first be called on outStream. However, since it is outStreamalready closed, it outStream.flush()throws an exception:java.sql.SQLException: Closed LOB
caused by: java.io.IOException: Closed LOB
at oracle.jdbc.driver.OracleBlobOutputStream.ensureOpen(OracleBlobOutputStream.java:265)
at oracle.jdbc.driver.OracleBlobOutputStream.flush(OracleBlobOutputStream.java:167)
at java.io.BufferedOutputStream.flush(BufferedOutputStream.java:141)
at java.io.FilterOutputStream.close(FilterOutputStream.java:158)
at com.blah.uploadFile(CustomerUploadFacade.java:162)
... 38 more
Caused by: java.sql.SQLException: Closed LOB
at oracle.jdbc.driver.OracleBlobOutputStream.ensureOpen(OracleBlobOutputStream.java:257)
... 42 more
Has anyone else experienced this issue? If so, how did you manage? Is there something wrong with the way we use try-with-resources?
source
share