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

java: correctly raise asynchronous assertion error #1575

Merged
merged 1 commit into from Feb 20, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
16 changes: 9 additions & 7 deletions src/clients/java/src/main/java/com/tigerbeetle/Request.java
Expand Up @@ -109,30 +109,30 @@ void endRequest(final byte receivedOperation, final byte status) {
case CREATE_ACCOUNTS: {
result = replyBuffer == null ? CreateAccountResultBatch.EMPTY
: new CreateAccountResultBatch(ByteBuffer.wrap(replyBuffer));
checkResultLength(result);
exception = checkResultLength(result);
break;
}

case CREATE_TRANSFERS: {
result = replyBuffer == null ? CreateTransferResultBatch.EMPTY
: new CreateTransferResultBatch(ByteBuffer.wrap(replyBuffer));
checkResultLength(result);
exception = checkResultLength(result);
break;
}

case ECHO_ACCOUNTS:
case LOOKUP_ACCOUNTS: {
result = replyBuffer == null ? AccountBatch.EMPTY
: new AccountBatch(ByteBuffer.wrap(replyBuffer));
checkResultLength(result);
exception = checkResultLength(result);
break;
}

case ECHO_TRANSFERS:
case LOOKUP_TRANSFERS: {
result = replyBuffer == null ? TransferBatch.EMPTY
: new TransferBatch(ByteBuffer.wrap(replyBuffer));
checkResultLength(result);
exception = checkResultLength(result);
break;
}

Expand Down Expand Up @@ -165,11 +165,13 @@ void endRequest(final byte receivedOperation, final byte status) {
}
}

final void checkResultLength(Batch result) {
private AssertionError checkResultLength(Batch result) {
if (result.getLength() > requestLen) {
setException(new AssertionError(
return new AssertionError(
"Amount of results is greater than the amount of requests: resultLen=%d, requestLen=%d",
result.getLength(), requestLen));
result.getLength(), requestLen);
} else {
return null;
}
}

Expand Down