Skip to content

Comments

chore: add @Blocking and @NonBlocking annotations#1192

Open
ttypic wants to merge 1 commit intomainfrom
feat/add-blocking-annotations
Open

chore: add @Blocking and @NonBlocking annotations#1192
ttypic wants to merge 1 commit intomainfrom
feat/add-blocking-annotations

Conversation

@ttypic
Copy link
Contributor

@ttypic ttypic commented Feb 19, 2026

Added @Blocking and @NonBlocking annotations for better documentation

Summary by CodeRabbit

  • Chores
    • Added blocking behavior metadata annotations to channel operations (attachment, detachment, subscription, history retrieval, messaging) and authentication methods to improve code documentation and clarity.

@ttypic ttypic requested a review from sacOO7 February 19, 2026 23:31
@coderabbitai
Copy link

coderabbitai bot commented Feb 19, 2026

Walkthrough

The changes add JetBrains @Blocking and @NonBlocking annotations to multiple public methods across three files in the Ably Java client library. These annotations indicate threading model expectations for authentication, channel operations, and subscription management without modifying method logic or signatures.

Changes

Cohort / File(s) Summary
Realtime Channel Operations
lib/src/main/java/io/ably/lib/realtime/ChannelBase.java
Added @NonBlocking annotations to channel lifecycle methods (attach, detach), subscription methods (subscribe/unsubscribe variants), async history retrieval, and option updates. Added @Blocking to synchronous history and message retrieval operations.
Authentication Operations
lib/src/main/java/io/ably/lib/rest/Auth.java
Added @Blocking annotations to authorization and token request methods (authorize, authorise, requestToken, createTokenRequest). Added @NonBlocking to token renewal methods (renew, renewAuth). Includes import statements for blocking annotations.
REST Channel Operations
lib/src/main/java/io/ably/lib/rest/ChannelBase.java
Added @Blocking annotations to synchronous history and presence methods. Added @NonBlocking annotations to async variants (publishAsync, historyAsync, Presence.getAsync, Presence.historyAsync).

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~3 minutes

Poem

🐰 Hop, hop—annotations bloom,
Blocking paths and async rooms,
Methods now wear threading threads,
Clear intent where flow is led!

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: adding @Blocking and @NonBlocking annotations to multiple methods across three files for improved documentation.
Docstring Coverage ✅ Passed Docstring coverage is 96.55% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch feat/add-blocking-annotations

Tip

Issue Planner is now in beta. Read the docs and try it out! Share your feedback on Discord.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
lib/src/main/java/io/ably/lib/rest/Auth.java (1)

1019-1024: ⚠️ Potential issue | 🟠 Major

@NonBlocking on renew() is incorrect — the method blocks on HTTP I/O.

renew() synchronously calls assertValidToken(...) (line 1021), which internally calls requestToken(...) — a method you've annotated @Blocking because it performs HTTP requests. This makes renew() a blocking method.

The same issue applies to renewAuth() on line 1034–1038: it also synchronously calls assertValidToken(...) before dispatching the async part.

Both should be @Blocking.

Proposed fix
     `@Deprecated`
-    `@NonBlocking`
+    `@Blocking`
     public TokenDetails renew() throws AblyException {
-    `@NonBlocking`
+    `@Blocking`
     public void renewAuth(RenewAuthResult result) throws AblyException {
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@lib/src/main/java/io/ably/lib/rest/Auth.java` around lines 1019 - 1024, The
`@NonBlocking` annotation on renew() (and likewise on renewAuth()) is incorrect
because renew() calls assertValidToken(...), which invokes requestToken(...) and
performs HTTP I/O; change the annotation to `@Blocking` for renew() and
renewAuth() so their declared blocking behavior matches the synchronous HTTP
calls — update the annotations on the methods renew() and renewAuth() (and any
related javadoc/comments) to `@Blocking` and ensure no `@NonBlocking` remains on
those methods that call assertValidToken(...) / requestToken(...).
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Outside diff comments:
In `@lib/src/main/java/io/ably/lib/rest/Auth.java`:
- Around line 1019-1024: The `@NonBlocking` annotation on renew() (and likewise on
renewAuth()) is incorrect because renew() calls assertValidToken(...), which
invokes requestToken(...) and performs HTTP I/O; change the annotation to
`@Blocking` for renew() and renewAuth() so their declared blocking behavior
matches the synchronous HTTP calls — update the annotations on the methods
renew() and renewAuth() (and any related javadoc/comments) to `@Blocking` and
ensure no `@NonBlocking` remains on those methods that call assertValidToken(...)
/ requestToken(...).

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This pull request adds @Blocking and @NonBlocking annotations from org.jetbrains.annotations to various public methods in the Ably Java SDK to improve documentation and clarity about thread-blocking behavior. The annotations help developers understand whether methods will block the calling thread or execute asynchronously with callbacks.

Changes:

  • Added blocking behavior annotations to REST channel operations (history retrieval, presence operations, message publishing)
  • Added blocking behavior annotations to authentication methods (authorize, requestToken, createTokenRequest, renew, renewAuth)
  • Added non-blocking behavior annotations to realtime channel operations (attach, detach, subscribe, unsubscribe, setOptions)

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
lib/src/main/java/io/ably/lib/rest/ChannelBase.java Added @Blocking and @NonBlocking annotations to REST channel methods including publish, history, and presence operations
lib/src/main/java/io/ably/lib/rest/Auth.java Added @Blocking annotations to synchronous auth methods and @NonBlocking to async renewal methods (with issues identified)
lib/src/main/java/io/ably/lib/realtime/ChannelBase.java Added @NonBlocking annotations to realtime channel operations and @Blocking to synchronous history methods

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 1019 to 1024
@NonBlocking
public TokenDetails renew() throws AblyException {
TokenDetails tokenDetails = assertValidToken(this.tokenParams, this.authOptions, true);
ably.onAuthUpdated(tokenDetails.token, false);
return tokenDetails;
}
Copy link

Copilot AI Feb 24, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The @NonBlocking annotation is incorrect for this method. The renew() method calls assertValidToken() which internally calls requestToken(), a blocking method that makes synchronous HTTP requests. This means renew() will actually block the calling thread despite being annotated as non-blocking. Consider changing the annotation to @Blocking to accurately reflect the method's behavior.

Copilot uses AI. Check for mistakes.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@coderabbitai can you check if this is correct? Also, check other public methods that should be marked Blocking / NonBlocking ?

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sacOO7, Copilot is correct. The renew() method is incorrectly annotated as @NonBlocking. It calls assertValidToken() which internally calls requestToken() (a blocking HTTP operation), so it should be @Blocking.

Here's a comprehensive review of public methods in the Auth class that need annotation corrections:

Methods with incorrect annotations:

  1. renew() - Currently @NonBlocking, should be @Blocking (calls assertValidToken()requestToken())
  2. renewAuth(RenewAuthResult) - Currently @NonBlocking, should be @Blocking (also calls assertValidToken()requestToken())

Public methods missing annotations that should be added:

Should be @Blocking:

  • getAuthParams() - calls assertValidToken() in the token auth case
  • assertAuthorizationHeader(boolean) - may call renew() or assertValidToken()

Should be @NonBlocking:

  • getAuthMethod() - simple getter
  • getBasicCredentials() - simple getter
  • getAuthOptions() - simple getter returning a copy
  • getTokenDetails() - simple getter
  • getEncodedToken() - simple getter
  • getAuthorizationHeader() - simple getter
  • onAuthError(ErrorInfo) - simple void method with local operations
  • setClientId(String) - setter with validation
  • checkClientId(BaseMessage, boolean, boolean) - validation logic only
  • serverTimestamp() - simple calculation
  • clearCachedServerTime() - simple field reset

The currently annotated methods (authorize, authorise, requestToken, createTokenRequest) are correctly marked as @Blocking.

Comment on lines 1034 to 1039
@NonBlocking
public void renewAuth(RenewAuthResult result) throws AblyException {
final TokenDetails tokenDetails = assertValidToken(this.tokenParams, this.authOptions, true);

ably.onAuthUpdatedAsync(tokenDetails.token, (success, errorInfo) -> result.onCompletion(success,tokenDetails,errorInfo));
}
Copy link

Copilot AI Feb 24, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The @NonBlocking annotation is incorrect for this method. The renewAuth() method calls assertValidToken() which internally calls requestToken(), a blocking method that makes synchronous HTTP requests. This means renewAuth() will block the calling thread before invoking the callback asynchronously. Consider changing the annotation to @Blocking to accurately reflect the method's behavior, or refactor the method to avoid blocking operations on the calling thread.

Copilot uses AI. Check for mistakes.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@coderabbitai can you check if this is correct? Also, check other public methods that should be marked Blocking / NonBlocking ?

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sacOO7, I've analyzed the annotations. Copilot is correct - the @NonBlocking annotation on renewAuth() is incorrect.

Issue with renewAuth()

The renewAuth() method calls assertValidToken() synchronously, which internally calls requestToken() (a blocking HTTP operation). This means the calling thread blocks until the token is obtained, even though the final callback is invoked asynchronously. It should be marked @Blocking.

Other methods needing annotation fixes:

1. renew() method (line ~1019) - Currently marked @NonBlocking but should be @Blocking:

`@Deprecated`
`@NonBlocking`  // ❌ Incorrect
public TokenDetails renew() throws AblyException {
    TokenDetails tokenDetails = assertValidToken(...); // This blocks!
    ably.onAuthUpdated(tokenDetails.token, false);
    return tokenDetails;
}

2. getAuthParams() method - Missing annotation, should be @Blocking:

  • In the token auth case, it calls assertValidToken() which can make blocking HTTP requests

3. assertAuthorizationHeader(boolean forceRenew) method - Missing annotation, should be @Blocking:

  • Calls renew() and assertValidToken(), both of which can block

Summary of needed changes:

  • renewAuth(): Change @NonBlocking@Blocking
  • renew(): Change @NonBlocking@Blocking
  • getAuthParams(): Add @Blocking
  • assertAuthorizationHeader(): Add @Blocking

Simple getter methods like getAuthMethod(), getAuthorizationHeader(), etc. don't need annotations since they just return fields or perform quick calculations without I/O.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants