Skip to content

Wrong parameter count after CallableStatement#setObject(String, Object, int) #1871

@coladict

Description

@coladict

Driver version

All current, including 11.1.2. Discovered when using 9.2.1

SQL Server version

irrelevant

Client Operating System

Debian 11.4

JAVA/JVM version

11.0.15

Problem description

Calling a method with 10 parameters. Getting this error when setting the 8th.

com.microsoft.sqlserver.jdbc.SQLServerException: The index 11 is out of range.

I've located the problem occurs when a method calls findColumn(parameterName) multiple times.
the problem is inside private int findColumn(String columnName)

map.putIfAbsent(columnName, ai.incrementAndGet());
return map.get(columnName);// attempting to look up the first column will return no access exception

The ai.incrementAndGet() is called even though the parameter is already present.
This is fine if there are no more parameters after it, but there are this time.
suggested correction:

return map.computeIfAbsent(columnName, ignored -> ai.incrementAndGet());

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