r2dbc / r2dbc-mssql

R2DBC Driver for Microsoft SQL Server using TDS (Tabular Data Stream) Protocol
Apache License 2.0
183 stars 32 forks source link

ClassCastException when calling RowMetadata.getColumnNames().toArray(T[]) #200

Closed lukaseder closed 3 years ago

lukaseder commented 3 years ago

Bug Report

Versions

Current Behavior

A ClassCastException is thrown when calling RowMetadata.getColumnNames().toArray(T[])

Steps to reproduce

System.out.println(
Flux.from(cf.create())
    .flatMap(c -> Mono.from(c.createStatement("select 1 as a").execute()))
    .flatMap(it -> it.map((r, m) -> {
        String[] s = m.getColumnNames().toArray(new String[0]);
        return "";
    }))
    .blockFirst()
);

Possible Solution

The implementation is simply wrong:

    @Override
    @SuppressWarnings("unchecked")
    public <T> T[] toArray(T[] a) {
        return (T[]) toArray();
    }

Rather than fixing that particular implementation, I suggest that MssqlRowMetadata doesn't implement Collection<String>. I don't see why it should.

lukaseder commented 3 years ago

I'll be happy to report more of these, and maybe even send PRs, but I'd like to discuss the SPI question first: https://github.com/r2dbc/r2dbc-spi/issues/219