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

execute empty sql causing IndexOutOfBoundsException #245

Open
trung opened this issue Jan 4, 2024 · 0 comments · May be fixed by #246
Open

execute empty sql causing IndexOutOfBoundsException #245

trung opened this issue Jan 4, 2024 · 0 comments · May be fixed by #246

Comments

@trung
Copy link

trung commented Jan 4, 2024

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();
@trung trung linked a pull request Jan 4, 2024 that will close this issue
4 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant