Skip to content

Calling Blob#length() on an image column causes an InputStream obtained from Blob#getBinaryStream() to close #1201

@jborgland

Description

@jborgland

Driver version

7.4.1 (appears to be valid for other versions as well)

SQL Server version

Microsoft SQL Server 2017 (RTM) - 14.0.1000.169 (X64)
Aug 22 2017 17:04:49
Copyright (C) 2017 Microsoft Corporation
Developer Edition (64-bit) on Windows Server 2016 Standard 10.0 (Build 14393: ) (Hypervisor)

(but appears to be valid for other versions as well)

Client Operating System

Windows 10

JAVA/JVM version

java version "1.8.0_171"
Java(TM) SE Runtime Environment (build 1.8.0_171-b11)
Java HotSpot(TM) 64-Bit Server VM (build 25.171-b11, mixed mode)

Table schema

create table mytable (
mydata image
);

Problem description

With the fix for #611 it's now usually possible to:

  1. Obtain an InputStream from a BLOB with myBlob.getBinaryStream().
  2. Call myBlob.length() to get the size of the BLOB.
  3. Consume the InputStream.

However, if the data type of the column is image then the following exception is thrown:

Caused by: java.io.IOException: The stream is closed.
	at com.microsoft.sqlserver.jdbc.BaseInputStream.checkClosed(SimpleInputStream.java:95) ~[mssql-jdbc.jar:?]
	at com.microsoft.sqlserver.jdbc.SimpleInputStream.read(SimpleInputStream.java:263) ~[mssql-jdbc.jar:?]
	at com.example.copyStreams(JdbcBlobStreamTester .java:41) 

This happens when the value byte array in com.microsoft.sqlserver.jdbc.SQLServerBlob is null and the first active input stream isn't an instance of PLPInputStream (the call to stream.getBytes() in getBytesFromStream() causes the stream to be closed).

Reproduction code

Use the same code as in #611.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions