Skip to content

Fix concurrent group access to prevent NullPointerException - #1

Open
ShashankFC wants to merge 1 commit into
feature-group-concurrency-updatefrom
feature-group-concurrency-implementation
Open

Fix concurrent group access to prevent NullPointerException#1
ShashankFC wants to merge 1 commit into
feature-group-concurrency-updatefrom
feature-group-concurrency-implementation

Conversation

@ShashankFC

@ShashankFC ShashankFC commented Jan 22, 2026

Copy link
Copy Markdown

Test 10nnn## Summary by CodeRabbitnn## Release Notesnn* Testsn * Added comprehensive concurrent group operations test to validate reliability during simultaneous create, read, and delete operations.nn* Bug Fixesn * Improved group caching stability with enhanced null-safety checks.nn✏️ Tip: You can customize this high-level summary in your review settings.nnn---nReplicated from ai-code-review-evaluation/keycloak-coderabbit#10


Note

Medium Risk
Touches cached group read paths used by admin APIs and changes behavior to return null when the delegate group disappears; concurrency bugs are subtle, but the change is localized and covered by a new stress-style test.

Overview
Fixes a race in the Infinispan group cache adapter by making GroupAdapter.getSubGroupsCount() null-safe when the underlying GroupModel can no longer be loaded (e.g., concurrently deleted).

Cleans up GroupUtils by removing an unused search helper, and adds an integration test that concurrently creates many groups, continuously lists groups in a background thread, deletes them, and asserts no exceptions are thrown during the concurrent read/delete window.

Written by Cursor Bugbot for commit 332c9b6. Configure here.

Closes #40368

Signed-off-by: vramik <vramik@redhat.com>
@ShashankFC

Copy link
Copy Markdown
Author

bugbot run

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 2 potential issues.

Bugbot Autofix is OFF. To automatically fix reported issues with Cloud Agents, enable Autofix in the Cursor dashboard.

if (isUpdated()) return updated.getSubGroupsCount();
return getGroupModel().getSubGroupsCount();
GroupModel model = modelSupplier.get();
return model == null ? null : model.getSubGroupsCount();

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Returning null violates documented non-null interface contract

Medium Severity

The GroupModel.getSubGroupsCount() interface contract explicitly documents @return The number of groups beneath this group. Never returns {@code null}. The new null-safety check returns null when the model is not found, violating this contract. This just moves the NullPointerException risk downstream to callers that rely on the documented guarantee (e.g., any auto-unboxing to long). Returning 0L instead of null would satisfy the contract while still avoiding the NPE at this site.

Fix in Cursor Fix in Web

});
deletedAll.set(true);

assertThat(caughtExceptions, Matchers.empty());

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Reader thread not joined before assertion causes false passes

Medium Severity

The reader thread is never joined before the assertion on caughtExceptions. After deletedAll.set(true), the main thread immediately asserts, but the reader thread may still have an HTTP request in-flight. If that request throws an exception, it gets added to caughtExceptions after the assertion has already passed. This race condition means the test can falsely pass, defeating the purpose of validating the concurrent-access fix.

Fix in Cursor Fix in Web

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.

2 participants