Skip to content

Bulk Copy with SQL Variant type fails due to null sourceResultSet #2442

Open
@hchenatsafe

Description

@hchenatsafe

Driver version

12.4.1.jre8

SQL Server version

Microsoft SQL Server 2014 (SP3-GDR) (KB5029184) - 12.0.6179.1 (X64)
Jul 27 2023 21:44:30
Copyright (c) Microsoft Corporation
Standard Edition (64-bit) on Windows NT 6.3 (Build 9600: ) (Hypervisor)

Client Operating System

Ubuntu 22.04

JAVA/JVM version

openjdk version "17.0.10" 2024-01-16
OpenJDK Runtime Environment (build 17.0.10+7-Ubuntu-122.04.1)
OpenJDK 64-Bit Server VM (build 17.0.10+7-Ubuntu-122.04.1, mixed mode, sharing)

Table schema

Provide the table schema to repro the issue.

Problem description

Our application supports inserting using bulk copy, and we call writeToServer(ISQLServerBulkData sourceData) to do so. We are trying to add support for sql_variant type (-156), but we run into a NullPointerException when we pass a sourceData object containing that type.

It appears that writeSqlVariant() relies on a sourceResultSet that is set to null in writeToServer(ISQLServerBulkData sourceData)

Expected behavior

Bulk source data is written successfully.

Actual behavior

See the following trace

Error message/stack trace

java.lang.NullPointerException: Cannot invoke "com.microsoft.sqlserver.jdbc.SQLServerResultSet.getVariantInternalType(int)" because "sourceResultSet" is null
at com.microsoft.sqlserver.jdbc.SQLServerBulkCopy.writeSqlVariant(SQLServerBulkCopy.java:2614)
at com.microsoft.sqlserver.jdbc.SQLServerBulkCopy.writeColumnToTdsWriter(SQLServerBulkCopy.java:2580)
at com.microsoft.sqlserver.jdbc.SQLServerBulkCopy.writeColumn(SQLServerBulkCopy.java:3094)
at com.microsoft.sqlserver.jdbc.SQLServerBulkCopy.writeBatchData(SQLServerBulkCopy.java:3652)
at com.microsoft.sqlserver.jdbc.SQLServerBulkCopy.doInsertBulk(SQLServerBulkCopy.java:1582)
at com.microsoft.sqlserver.jdbc.SQLServerBulkCopy.access$300(SQLServerBulkCopy.java:67)
at com.microsoft.sqlserver.jdbc.SQLServerBulkCopy$1InsertBulk.doExecute(SQLServerBulkCopy.java:673)
at com.microsoft.sqlserver.jdbc.TDSCommand.execute(IOBuffer.java:7675)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.executeCommand(SQLServerConnection.java:4137)
at com.microsoft.sqlserver.jdbc.SQLServerBulkCopy.sendBulkLoadBCP(SQLServerBulkCopy.java:707)
at com.microsoft.sqlserver.jdbc.SQLServerBulkCopy.writeToServer(SQLServerBulkCopy.java:1670)
at com.microsoft.sqlserver.jdbc.SQLServerBulkCopy.writeToServer(SQLServerBulkCopy.java:630)

Metadata

Metadata

Assignees

No one assigned

    Labels

    BacklogThe topic in question has been recognized and added to development backlogEnhancementAn 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