The method in question is AuthorizationStateReadyGetMe#onUpdate(UpdateAuthorizationState update)
|
public void onUpdate(UpdateAuthorizationState update) { |
The issue is at this line
|
this.meReceived.complete(null); |
Description:
I think there's a potential issue.
client.send(new GetMe(), me -> {
try {
if (me.getConstructor() == Error.CONSTRUCTOR) {
throw new TelegramError((Error) me);
}
this.me.set((User) me);
} finally {
this.meReceived.complete(null);
}
When me.getConstructor() returns Error, TelegramError is thrown. But despite the failure, the code still completes the CompletableFuture successfully: this.meReceived.complete(null);
This seems inconsistent because the caller may receive a stale or incorrect value of me. The error is currently only visible through logger.warn("Failed to execute TdApi.GetMe()") in the logs, which is not sufficient because callers cannot programmatically detect the failure.
Instead, the logic could be split into success and failure paths using completeExceptionally():
try {
if (me.getConstructor() == Error.CONSTRUCTOR) {
throw new TelegramError((Error) me);
}
this.me.set((User) me);
-} finally {
this.meReceived.complete(null);
+} catch (Throwable t) {
+ this.meReceived.completeExceptionally(t);
}
The method in question is
AuthorizationStateReadyGetMe#onUpdate(UpdateAuthorizationState update)tdlight-java/tdlight-java/src/main/java/it/tdlight/client/AuthorizationStateReadyGetMe.java
Line 34 in 8dc7311
The issue is at this line
tdlight-java/tdlight-java/src/main/java/it/tdlight/client/AuthorizationStateReadyGetMe.java
Line 43 in 8dc7311
Description:
I think there's a potential issue.
When
me.getConstructor()returnsError,TelegramErroris thrown. But despite the failure, the code still completes theCompletableFuturesuccessfully:this.meReceived.complete(null);This seems inconsistent because the caller may receive a stale or incorrect value of
me. The error is currently only visible throughlogger.warn("Failed to execute TdApi.GetMe()")in the logs, which is not sufficient because callers cannot programmatically detect the failure.Instead, the logic could be split into success and failure paths using
completeExceptionally():try { if (me.getConstructor() == Error.CONSTRUCTOR) { throw new TelegramError((Error) me); } this.me.set((User) me); -} finally { this.meReceived.complete(null); +} catch (Throwable t) { + this.meReceived.completeExceptionally(t); }