Skip to content

SQLServerCallableStatement::getBoolean throws unhandled ClassCastException when getting bit output parameter #2351

Open
@ChrisVinall

Description

@ChrisVinall

Driver version: 12.6.1.jre11, but 12.5 versions also exhibit the bug.

SQL Server version: Microsoft SQL Server 2017 (RTM-CU23) (KB5000685) - 14.0.3381.3 (X64) Feb 9 2021 12:08:50 Developer Edition (64-bit)

OS: Linux (Ubuntu 18.04.6 LTS)

JVM: Oracle OpenJDK 21.0.2

Issue reproduction:

CREATE PROCEDURE [dbo].[test_jdbc_bug]
AS
BEGIN
	DECLARE @TestReturn BIT
	SET @TestReturn = 0
	RETURN @TestReturn
END
try (final Connection con = [get some connection]) {
    try(final CallableStatement proc = con.prepareCall("{? = call dbo.test_jdbc_bug}")) {
        proc.registerOutParameter( 1, Types.BIT );
        proc.execute();
        boolean booleanPlease = proc.getBoolean(1);
    }
}

Expected behaviour: the driver returns false, this is what happens in versions prior to 12.5.

Actual behaviour: A ClassCastException is thrown at SQLServerCallableStatement:665. From debugging, in DTVImpl::getValue, this.jdbcType and the requested jdbcType are both BIT, therefore the value object is returned. However, as the value object is an Integer, the subsequent explicit cast to Boolean fails. That's as far as I got.

Log at FINE:

Mar 19, 2024 5:26:41 PM com.microsoft.sqlserver.jdbc.SQLServerConnection <init>
FINE: ConnectionID:42 created by (SQLServerDataSource:1)
Mar 19, 2024 5:26:41 PM com.microsoft.sqlserver.jdbc.SQLServerConnection connectHelper
FINE: ConnectionID:42 Connecting with server: 35.189.29.87 port: 4112 Timeout slice: 3750 Timeout Full: 30
Mar 19, 2024 5:26:41 PM com.microsoft.sqlserver.jdbc.SQLServerConnection prelogin
FINE: ConnectionID:42 ClientConnectionId: 95c0e5df-a290-425a-990a-63b822bc7fea Server returned major version:14
Mar 19, 2024 5:26:46 PM com.microsoft.sqlserver.jdbc.SQLServerStatement <init>
FINE: SQLServerStatement:3 created by (ConnectionID:1 ClientConnectionId: 6b9737c9-4a03-41f1-b642-1adcba6fdbe9)
Mar 19, 2024 5:26:46 PM com.microsoft.sqlserver.jdbc.SQLServerStatement doExecuteStatement
FINE: SQLServerStatement:3 Executing (not server cursor) SELECT 1
Mar 19, 2024 5:26:46 PM com.microsoft.sqlserver.jdbc.SQLServerResultSet <init>
FINE: SQLServerResultSet:3 created by (SQLServerStatement:3)
Mar 19, 2024 5:26:46 PM com.microsoft.sqlserver.jdbc.SQLServerStatement <init>
FINE: sp_executesql SQL: null created by (ConnectionID:1 ClientConnectionId: 6b9737c9-4a03-41f1-b642-1adcba6fdbe9)
Mar 19, 2024 5:26:46 PM com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement buildRPCExecParams
FINE: sp_executesql SQL: EXEC  @P0 = dbo.test_jdbc_bug: calling PROC, SQL:EXEC  @P0 = dbo.test_jdbc_bug

Metadata

Metadata

Assignees

Labels

As designedThe issue in question is as designed, and will not be addressedEnhancementAn enhancement to the driver. Lower priority than bugs.

Type

No type

Projects

Status

Backlog

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions