Skip to content

Conversation

@SoulPancake
Copy link
Member

@SoulPancake SoulPancake commented Dec 4, 2025

Description

What problem is being solved?

How is it being solved?

What changes are made to solve it?

References

Review Checklist

  • I have clicked on "allow edits by maintainers".
  • I have added documentation for new/changed functionality in this PR or in a PR to openfga.dev [Provide a link to any relevant PRs in the references section above]
  • The correct base branch is being used, if not main
  • I have added tests to validate that the change in functionality is working as expected

Summary by CodeRabbit

  • Bug Fixes
    • Fixed a potential crash when fetching the latest authorization model if no models are available. The system now gracefully handles empty responses.

✏️ Tip: You can customize this high-level summary in your review settings.

Copilot AI review requested due to automatic review settings December 4, 2025 14:48
@SoulPancake SoulPancake requested a review from a team as a code owner December 4, 2025 14:48
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Dec 4, 2025

Walkthrough

Added defensive programming to prevent IndexOutOfBoundsException when reading authorization models. The latestOf method now checks if the authorization models list is empty before accessing its first element. A test case verifies this behavior.

Changes

Cohort / File(s) Change Summary
Null-safety guard in latestOf method
src/main/java/dev/openfga/sdk/api/client/model/ClientReadAuthorizationModelResponse.java
Added isEmpty check before accessing response.getAuthorizationModels().get(0) to guard against IndexOutOfBoundsException
Test case for empty models list
src/test/java/dev/openfga/sdk/api/client/OpenFgaClientTest.java
Added readLatestAuthorizationModelTest_emptyList() test to verify that empty authorization models list results in null authorizationModel in response

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

  • Straightforward defensive guard pattern added in a single location
  • Single test method covering the edge case with clear assertions
  • Limited scope with no complex logic or architectural changes

Possibly related issues

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 25.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title directly addresses the main change: adding a guard to handle empty authorization models list in the readLatestAuthorizationModel method to prevent IndexOutOfBoundsException, which matches the core fix in the changeset.
✨ 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 fix/index-oob-empty-authmodel

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 ast-grep (0.40.0)
src/test/java/dev/openfga/sdk/api/client/OpenFgaClientTest.java

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.

@dosubot
Copy link

dosubot bot commented Dec 4, 2025

Related Documentation

Checked 7 published document(s) in 1 knowledge base(s). No updates required.

How did I do? Any feedback?  Join Discord

@codecov-commenter
Copy link

codecov-commenter commented Dec 4, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 37.14%. Comparing base (fa6845c) to head (b47292a).

Additional details and impacted files
@@             Coverage Diff              @@
##               main     #265      +/-   ##
============================================
+ Coverage     37.12%   37.14%   +0.01%     
- Complexity     1195     1196       +1     
============================================
  Files           192      192              
  Lines          7472     7474       +2     
  Branches        862      863       +1     
============================================
+ Hits           2774     2776       +2     
  Misses         4568     4568              
  Partials        130      130              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Contributor

@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.

Actionable comments posted: 0

🧹 Nitpick comments (1)
src/main/java/dev/openfga/sdk/api/client/model/ClientReadAuthorizationModelResponse.java (1)

37-40: Consider also guarding against a null authorizationModels list

The new check avoids IndexOutOfBoundsException for empty lists, which is good. If response.getAuthorizationModels() can ever be null (e.g., field missing or older server), models.isEmpty() would still throw a NullPointerException. A small tweak would make this fully defensive:

-        List<dev.openfga.sdk.api.model.AuthorizationModel> models = response.getAuthorizationModels();
-        if (!models.isEmpty()) {
+        List<dev.openfga.sdk.api.model.AuthorizationModel> models = response.getAuthorizationModels();
+        if (models != null && !models.isEmpty()) {
             clientResponse.setAuthorizationModel(models.get(0));
         }

This preserves existing behavior for non-null lists while handling both empty and absent lists safely.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between fa6845c and b47292a.

📒 Files selected for processing (2)
  • src/main/java/dev/openfga/sdk/api/client/model/ClientReadAuthorizationModelResponse.java (1 hunks)
  • src/test/java/dev/openfga/sdk/api/client/OpenFgaClientTest.java (1 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
src/test/java/dev/openfga/sdk/api/client/OpenFgaClientTest.java (1)
src/main/java/dev/openfga/sdk/constants/FgaConstants.java (1)
  • FgaConstants (19-104)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (6)
  • GitHub Check: CodeQL analysis (java)
  • GitHub Check: Agent
  • GitHub Check: Test and Build OpenFGA (17)
  • GitHub Check: Test and Build OpenFGA (11)
  • GitHub Check: Test and Build OpenFGA (21)
  • GitHub Check: Analyze (java)
🔇 Additional comments (1)
src/test/java/dev/openfga/sdk/api/client/OpenFgaClientTest.java (1)

749-764: Empty-list regression test looks correct and consistent

The test accurately exercises the empty authorization_models case, verifies the correct URL and call count, and asserts the new contract (authorizationModel is null rather than throwing). Fits well with existing test patterns.

Copilot finished reviewing on behalf of SoulPancake December 4, 2025 14:52
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 PR fixes a bug where readLatestAuthorizationModel() would throw an IndexOutOfBoundsException when attempting to access the first element of an empty authorization models list. The fix adds a null-safety check before accessing the list, and includes a test case to verify the behavior.

Key changes:

  • Added empty list check in ClientReadAuthorizationModelResponse.latestOf() to prevent IndexOutOfBoundsException
  • Added test case readLatestAuthorizationModelTest_emptyList to verify null is returned when no models exist

Reviewed changes

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

File Description
src/main/java/dev/openfga/sdk/api/client/model/ClientReadAuthorizationModelResponse.java Added null-safety check before accessing the first authorization model from the list
src/test/java/dev/openfga/sdk/api/client/OpenFgaClientTest.java Added test case to verify empty list handling returns null authorization model

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

@SoulPancake SoulPancake added this pull request to the merge queue Dec 4, 2025
Merged via the queue into main with commit 806fc05 Dec 4, 2025
28 of 31 checks passed
@SoulPancake SoulPancake deleted the fix/index-oob-empty-authmodel branch December 4, 2025 15:34
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 this pull request may close these issues.

Index Out Of Bound Exception on getting Authorization Model when collection is empty

4 participants