java.sql2 Connection.connect(Function<Throwable, Void>) should be connect(Consumer<Throwable>)
Lukas Eder
lukas.eder at gmail.com
Wed Oct 4 10:47:08 UTC 2017
Hello,
I'm referring to this version:
http://hg.openjdk.java.net/jdk10/sandbox/jdk/file/a31057bda7c5/src/java.sql/share/classes/java/sql2
Which I believe to be the latest version on that branch. There's a method
Connection.connect(Function<Throwable, Void>) which I think has two issues:
1. It should accept a Consumer<Throwable>, just like Operation.onError(). I
don't see the point of having a Function<Throwable, Void> here. It looks
like this is just because of an implementation detail leaking into the API.
The implementation should be:
public default Connection connect(Consumer<Throwable> onError) {
this.holdForMoreMembers()
.submit();
this.connectOperation()
.submit()
.toCompletableFuture()
.exceptionally(t -> { onError.accept(t); return null; });
return this;
}
Instead of:
public default Connection connect(Function<Throwable, Void> onError) {
this.holdForMoreMembers()
.submit();
this.connectOperation()
.submit()
.toCompletableFuture()
.exceptionally(onError);
return this;
}
2. This may be my incomplete understanding of the API in general, but from
what I understand, there might be a race condition between the submit()
operation, and the transformation to a CompletableFuture and the error
interception. Can this API really *guarantee* that all errors will be
passed to the "onError" handler even if submit() terminates super fast?
If not, this might be a flaw in the Submission.toCompletableFuture() method.
Thanks,
Lukas
More information about the jdbc-spec-discuss
mailing list