fix: EXPOSED-123 ExposedBlob.getBytes() fails on Oracle with IOException #1824
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The following tests fail when run using Oracle:
DDLTests/testBlob()
DDLTests/testBlobDefault()
EntityTests/testBlobField()
They all fail with the same error:
This exception is thrown by
inputStream.reset()
:Because the
InputStream
retrieved by the DB is of typeoracle.jdbc.driver.OracleBlobInputStream
, which throws, as per the documentation:Possible Solutions:
ByteArray
instead of anInputStream
:This fixes the issue because an
ExposedBlob
is created using the secondary constructor:which instantiates a
java.io.ByteArrayInputStream
, with areset()
override that doesn't throw.This works fine, but seems less than ideal especially since most recommendations about reading BLOBs from Oracle suggest using
getBlob()
orgetBinaryStream()
because of the potential size of a BLOB. The current code usesgetBinaryStream()
:InputStream
, but ensuremark()
is invoked:Using
it.inputStream.available()
as thereadlimit
value tells the input stream to allow that many bytes to be read before the mark position gets invalidated. This works, but seems like a step too far especially since documentation shows this warning:readObject()
and instead handle theIOException
insideExposedBlob.getBytes()
. This ensures that the BLOB value is still being retrieved as a stream and does not affect the returnedByteArray
value.