execute empty sql causing IndexOutOfBoundsException
trung opened this issue · 0 comments
trung commented
Bug Report
Versions
- Driver: io.r2dbc.h2
- Database: H2
- Java: 17
- OS: MacOS
Current Behavior
Stack trace
Caused by: java.lang.IndexOutOfBoundsException: Index 0 out of bounds for length 0
at java.base/jdk.internal.util.Preconditions.outOfBounds(Preconditions.java:64) ~[na:na]
Suppressed: reactor.core.publisher.FluxOnAssembly$OnAssemblyException:
Assembly trace from producer [reactor.core.publisher.FluxIterable] :
reactor.core.publisher.Flux.fromIterable(Flux.java:1117)
io.r2dbc.h2.H2Statement.execute(H2Statement.java:140)
Error has been observed at the following site(s):
*_______________________Flux.fromIterable ⇢ at io.r2dbc.h2.H2Statement.execute(H2Statement.java:140)
|_ Flux.map ⇢ at io.r2dbc.h2.H2Statement.execute(H2Statement.java:141)
*____________________________Flux.flatMap ⇢ at io.r2dbc.h2.H2Statement.execute(H2Statement.java:105)
|_ Flux.cast ⇢ at org.springframework.r2dbc.core.ResultFunction.apply(ResultFunction.java:66)
|_ checkpoint ⇢ SQL ..<snip>..
Table schema
Input Code
insert xyz; \n
Steps to reproduce
This unit test doesn't produce the IndexOutOfBoundsException
but to demonstrate that empty sql is allowed to execute.
This creates a root issue in the SessionClient.createCommand()
.
Input Code
@Test
void executeMultipleCommandsIgnoringEmptyOne() {
CommandInterface insertCommand1 = mock(CommandInterface.class);
when(this.client.prepareCommand("insert test-query-1", Collections.emptyList())).thenReturn(Collections.singleton(insertCommand1).iterator());
when(this.client.update(insertCommand1, false)).thenReturn(new ResultWithGeneratedKeys.WithKeys(0, new LocalResult()));
new H2Statement(this.client, this.codecs, "insert test-query-1;\n ")
.execute()
.as(StepVerifier::create)
.expectNextCount(1)
.verifyComplete();
}
Expected behavior/code
Empty SQL should be filtered
Possible Solution
N/A
Additional context
When using Spring Data and """-quoted string query as below:
@Query("""
insert test-query-1;
""")
Mono<Void> insert();