Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
ChrisVinall opened this issue Mar 19, 2024 · 3 comments
Assignees
Labels
As designed The issue in question is as designed, and will not be addressed Enhancement An enhancement to the driver. Lower priority than bugs.

Comments

@ChrisVinall
Copy link

ChrisVinall commented Mar 19, 2024

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
@tkyc
Copy link
Contributor

tkyc commented Mar 19, 2024

Looking into it... I'll get back to you.

@tkyc
Copy link
Contributor

tkyc commented Mar 20, 2024

So, prior to 12.5 the behaviour of returning false is incorrect. This was corrected in 12.5+. For sprocs, the RETURN keyword is used to return an integer expression eg. RETURN is meant to return a status code (more info here and here on RETURN). For your case, you'll want to use an output parameter to return the boolean.

@ChrisVinall
Copy link
Author

OK, thanks for that. Will leave the issue open for you to figure out how the driver should respond under these circumstances.

@lilgreenbird lilgreenbird added As designed The issue in question is as designed, and will not be addressed Enhancement An enhancement to the driver. Lower priority than bugs. labels Mar 21, 2024
@lilgreenbird lilgreenbird added this to the 12.7.0 milestone Mar 27, 2024
@Jeffery-Wasty Jeffery-Wasty removed this from the 12.7.0 milestone Apr 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
As designed The issue in question is as designed, and will not be addressed Enhancement An enhancement to the driver. Lower priority than bugs.
Projects
Status: Backlog
Development

No branches or pull requests

4 participants