Fix concurrent group access to prevent NullPointerException
Tier 2 easy java · local · real merged PR from keycloak/keycloak #40940
Ground-truth defects
The reader thread isn’t waited for; flipping deletedAll to true and asserting immediately can race and miss exceptions added just after the flag change, making this test flaky.
The change under review
diff
@@ -271,7 +271,8 @@ public class GroupAdapter implements GroupModel { @Override public Long getSubGroupsCount() { if (isUpdated()) return updated.getSubGroupsCount(); - return getGroupModel().getSubGroupsCount(); + GroupModel model = modelSupplier.get(); + return model == null ? null : model.getSubGroupsCount(); } @Override @@ -58,6 +58,7 @@ public class CachedGroup extends AbstractRevisioned implements InRealm { this.type = group.getType(); } + @Override public String getRealm() { return realm; } @@ -98,14 +98,4 @@ public class GroupUtils { rep.setAccess(groupsEvaluator.getAccess(groupTree)); return rep; } - - private static boolean groupMatchesSearchOrIsPathElement(GroupModel group, String search) { - if (StringUtil.isBlank(search)) { - return true; - } - if (group.getName().contains(search)) { - return true; - } - return group.getSubGroupsStream().findAny().isPresent(); - } } @@ -25,6 +25,7 @@ import jakarta.ws.rs.core.Response.Status; import org.apache.http.client.methods.CloseableHttpResponse; import org.apache.http.client.methods.HttpGet; import org.apache.http.impl.client.CloseableHttpClient; +import org.hamcrest.Matchers; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import org.keycloak.admin.client.Keycloak; @@ -76,6 +77,9 @@ import java.util.LinkedList; import java.util.List; import java.util.Map; import java.util.UUID; +import java.util.concurrent.CopyOnWriteArrayList; +import java.util.concurrent.atomic.AtomicBoolean; +import java.util.stream.IntStream; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.anEmptyMap; @@ -90,6 +94,7 @@ import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertNull; import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; /** * @author <a href="mailto:mstrukel@redhat.com">Marko Strukelj</a> @@ -109,6 +114,49 @@ public class GroupTest extends AbstractGroupTest { @InjectHttpClient CloseableHttpClient httpClient; + + @Test + public void createMultiDeleteMultiReadMulti() { + // create multiple groups + List<String> groupUuuids = new ArrayList<>(); + IntStream.range(0, 100).forEach(groupIndex -> { + GroupRepresentation group = new GroupRepresentation(); + group.setName("Test Group " + groupIndex); + try (Response response = managedRealm.admin().groups().add(group)) { + boolean created = response.getStatusInfo().getFamily() == Response.Status.Family.SUCCESSFUL; + if (created) { + final String groupUuid = ApiUtil.getCreatedId(response); + groupUuuids.add(groupUuid); + } else { + fail("Failed to create group: " + response.getStatusInfo().getReasonPhrase()); + } + } + }); + + AtomicBoolean deletedAll = new AtomicBoolean(false); + List<Exception> caughtExceptions = new CopyOnWriteArrayList<>(); + // read groups in a separate thread + new Thread(() -> { + while (!deletedAll.get()) { + try { + // just loading briefs + managedRealm.admin().groups().groups(null, 0, Integer.MAX_VALUE, true); + } catch (Exception e) { + + caughtExceptions.add(e); + } + } + }).start(); + + // delete groups + groupUuuids.forEach(groupUuid -> { + managedRealm.admin().groups().group(groupUuid).remove(); + }); + deletedAll.set(true); + + assertThat(caughtExceptions, Matchers.empty()); + } + // KEYCLOAK-2716 Can't delete client if its role is assigned to a group @Test public void testClientRemoveWithClientRoleGroupMapping() {
Leaderboard for this case
easy · 8 of 9 bots fully caught it (89% solve rate) · 89% avg coverage.
| # | Bot | Result | Caught | Coverage | Findings | False alarms |
|---|---|---|---|---|---|---|
| 1 | Claude Code (Opus 5.5) | solved | 1/1 | 100.0% | 2 | 0 |
| 2 | Cubic | solved | 1/1 | 100.0% | 3 | 0 |
| 3 | cursor | solved | 1/1 | 100.0% | 1 | 0 |
| 4 | Drape (Deep Review) | solved | 1/1 | 100.0% | 2 | 0 |
| 5 | Drape (Review) | solved | 1/1 | 100.0% | 3 | 0 |
| 6 | greptile | solved | 1/1 | 100.0% | 2 | 0 |
| 7 | Mjolnir (Opus 5.5) | solved | 1/1 | 100.0% | 2 | 0 |
| 8 | qodo | solved | 1/1 | 100.0% | 3 | 0 |
| 9 | Mjolnir (Sonnet 5.5) | miss | 0/1 | 0.0% | 0 | 0 |
Bot results
Claude Code (Opus 5.5) · cross-file engine perris 0.11.1+proven.tiered0.25.call.read.subclass.type
| Defect | Severity | Found | Grade |
|---|---|---|---|
| d2 | low | ✓ | exact |
The new test sets deletedAll only after every remove() succeeds, and that call is not in a finally block. If any delete throws, the reader thread started with `new Thread(...).start()` (a non-daemon thread) loops forever. The groups that were not yet deleted were never registered with managedRealm.cleanup(), so they stay in the realm. [grounded: diff] [consensus 3/3: valid=3]
raw comments (2)
The reader thread is never joined. Once deletion finishes, `deletedAll` is set and `caughtExceptions` is checked right away, while a `groups()` call may still be running. An exception thrown during the final reads (the window where the race happens) can be added after the assertion has already passed. Also, nothing ensures the reader ran even once before the deletes finished. So the test can pass even when the regression is present. Keep a reference to the thread, join it before asserting, and consider waiting until at least one read has started before deleting.
The test creates 100 groups. If a delete fails partway through, the remaining groups are left in the managed realm, and the reader thread keeps running because `deletedAll` is never set. That leaves a non-daemon thread spinning against the server and can affect later tests. Set the flag in a `finally` block.
Cubic · cross-file engine perris 0.11.1+proven.tiered0.25.call.read.subclass.type
| Defect | Severity | Found | Grade |
|---|---|---|---|
| d2 | low | ✓ | off by one |
The new test sets the stop flag only after the delete loop finishes. If a remove() throws, the flag is never set and the non-daemon reader thread keeps polling. At best that leaks a busy thread that keeps hitting the server; at worst it hangs the run. It only bites when a delete fails. [grounded: diff] [consensus 5/5: valid=5]
The GroupModel Javadoc says getSubGroupsCount() 'Never returns {@code null}', but the new code returns null when the delegate model is missing. The current caller (populateSubGroupCount) stores the result in a Long field, so nothing crashes today. It is still a real contract violation that this change introduced. [grounded: diff] [consensus 5/5: valid=5]
raw comments (4)
<!-- cubic:v=5b8b11bb-e4cb-4115-a271-93eb93c5cd9b -->
<!-- cubic:review-run=ec323a0b-ecc0-5af9-ab81-176ee4cd55b8 -->
<!-- metadata:{"confidence":8} -->
P2: The reader thread is never joined before `assertThat(caughtExceptions, Matchers.empty())`. Deletions run concurrently with reads, so when `deletedAll.set(true)` fires an in-flight read request may still be executing, and if that read throws the exception this test is meant to reproduce it is added to `caughtExceptions` only after the assertion has already read the list. The test then passes while the regression is present, making it a flaky/ineffective regression test. Save the Thread reference and `join()` it (with a timeout) before asserting.
<details>
<summary>Prompt for AI agents</summary>
```text
Check if this issue is valid — if so, understand the root cause and fix it. At tests/base/src/test/java/org/keycloak/tests/admin/group/GroupTest.java, line 157:
<comment>The reader thread is never joined before `assertThat(caughtExceptions, Matchers.empty())`. Deletions run concurrently with reads, so when `deletedAll.set(true)` fires an in-flight read request may still be executing, and if that read throws the exception this test is meant to reproduce it is added to `caughtExceptions` only after the assertion has already read the list. The test then passes while the regression is present, making it a flaky/ineffective regression test. Save the Thread reference and `join()` it (with a timeout) before asserting.</comment>
<file context>
@@ -109,6 +114,49 @@ public class GroupTest extends AbstractGroupTest {
+ });
+ deletedAll.set(true);
+
+ assertThat(caughtExceptions, Matchers.empty());
+ }
+
</file context>
```
</details>
<!-- cubic:v=9f825e11-85b6-46d2-80fc-a7371992d454 -->
<!-- cubic:review-run=ec323a0b-ecc0-5af9-ab81-176ee4cd55b8 -->
<!-- metadata:{"confidence":8} -->
P2: `deletedAll.set(true)` is reachable only after the delete loop completes. If any `groupUuid.remove()` throws (e.g. a 5xx from the admin endpoint), the method exits before setting the flag, leaving the non-daemon reader thread looping forever on `while (!deletedAll.get())` and hanging the test suite. Set `deletedAll` in a `finally` block so the reader always terminates even when a delete fails.
<details>
<summary>Prompt for AI agents</summary>
```text
Check if this issue is valid — if so, understand the root cause and fix it. At tests/base/src/test/java/org/keycloak/tests/admin/group/GroupTest.java, line 155:
<comment>`deletedAll.set(true)` is reachable only after the delete loop completes. If any `groupUuid.remove()` throws (e.g. a 5xx from the admin endpoint), the method exits before setting the flag, leaving the non-daemon reader thread looping forever on `while (!deletedAll.get())` and hanging the test suite. Set `deletedAll` in a `finally` block so the reader always terminates even when a delete fails.</comment>
<file context>
@@ -109,6 +114,49 @@ public class GroupTest extends AbstractGroupTest {
+ groupUuuids.forEach(groupUuid -> {
+ managedRealm.admin().groups().group(groupUuid).remove();
+ });
+ deletedAll.set(true);
+
+ assertThat(caughtExceptions, Matchers.empty());
</file context>
```
</details>
<!-- cubic:v=9359566f-542d-4f55-9a06-39aefb0e5f3b -->
<!-- cubic:review-run=ec323a0b-ecc0-5af9-ab81-176ee4cd55b8 -->
<!-- metadata:{"confidence":6} -->
P3: `getSubGroupsCount()` now returns `null` when the lazy model cannot be loaded, which violates the `GroupModel.getSubGroupsCount()` contract documented as "Never returns {@code null}". Current callers tolerate it (`GroupUtils.populateSubGroupCount` sets it on a `Long` field, the admin client types it optional, and tests assert `nullValue()`), so there is no immediate crash, but any caller that trusts the documented non-null contract and unboxes the result will NPE later. Align the contract: either return this null deliberately and update the interface Javadoc to say the value may be absent, or return a sentinel and null-check at the caller.
<details>
<summary>Prompt for AI agents</summary>
```text
Check if this issue is valid — if so, understand the root cause and fix it. At model/infinispan/src/main/java/org/keycloak/models/cache/infinispan/GroupAdapter.java, line 275:
<comment>`getSubGroupsCount()` now returns `null` when the lazy model cannot be loaded, which violates the `GroupModel.getSubGroupsCount()` contract documented as "Never returns {@code null}". Current callers tolerate it (`GroupUtils.populateSubGroupCount` sets it on a `Long` field, the admin client types it optional, and tests assert `nullValue()`), so there is no immediate crash, but any caller that trusts the documented non-null contract and unboxes the result will NPE later. Align the contract: either return this null deliberately and update the interface Javadoc to say the value may be absent, or return a sentinel and null-check at the caller.</comment>
<file context>
@@ -271,7 +271,8 @@ public Stream<GroupModel> getSubGroupsStream(String search, Boolean exact, Integ
if (isUpdated()) return updated.getSubGroupsCount();
- return getGroupModel().getSubGroupsCount();
+ GroupModel model = modelSupplier.get();
+ return model == null ? null : model.getSubGroupsCount();
}
</file context>
```
</details>
<!-- cubic:review-summary:start -->
**3 issues found** across 4 files
<!-- cubic:review-summary:end -->
<details>
<summary>Prompt for AI agents (unresolved issues)</summary>
```text
Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="tests/base/src/test/java/org/keycloak/tests/admin/group/GroupTest.java">
<violation number="1" location="tests/base/src/test/java/org/keycloak/tests/admin/group/GroupTest.java:155">
P2: `deletedAll.set(true)` is reachable only after the delete loop completes. If any `groupUuid.remove()` throws (e.g. a 5xx from the admin endpoint), the method exits before setting the flag, leaving the non-daemon reader thread looping forever on `while (!deletedAll.get())` and hanging the test suite. Set `deletedAll` in a `finally` block so the reader always terminates even when a delete fails.</violation>
<violation number="2" location="tests/base/src/test/java/org/keycloak/tests/admin/group/GroupTest.java:157">
P2: The reader thread is never joined before `assertThat(caughtExceptions, Matchers.empty())`. Deletions run concurrently with reads, so when `deletedAll.set(true)` fires an in-flight read request may still be executing, and if that read throws the exception this test is meant to reproduce it is added to `caughtExceptions` only after the assertion has already read the list. The test then passes while the regression is present, making it a flaky/ineffective regression test. Save the Thread reference and `join()` it (with a timeout) before asserting.</violation>
</file>
<file name="model/infinispan/src/main/java/org/keycloak/models/cache/infinispan/GroupAdapter.java">
<violation number="1" location="model/infinispan/src/main/java/org/keycloak/models/cache/infinispan/GroupAdapter.java:275">
P3: `getSubGroupsCount()` now returns `null` when the lazy model cannot be loaded, which violates the `GroupModel.getSubGroupsCount()` contract documented as "Never returns {@code null}". Current callers tolerate it (`GroupUtils.populateSubGroupCount` sets it on a `Long` field, the admin client types it optional, and tests assert `nullValue()`), so there is no immediate crash, but any caller that trusts the documented non-null contract and unboxes the result will NPE later. Align the contract: either return this null deliberately and update the interface Javadoc to say the value may be absent, or return a sentinel and null-check at the caller.</violation>
</file>
```
</details>
<sub>Reply with feedback, questions, or to request a fix.<br /><br />[Re-trigger cubic](https://www.cubic.dev/action/re-review/pr/drape-io/crbench-cubic-2026-09/56/ai_pr_review_github_delivery_06923d5b0ab36598331a7c4818174eb8c0f4d234e839c90a6b70f157a3d8b088?returnTo=https%3A%2F%2Fgithub.com%2Fdrape-io%2Fcrbench-cubic-2026-09%2Fpull%2F56)</sub>
<!-- cubic:review-post:ai_pr_review_github_delivery_06923d5b0ab36598331a7c4818174eb8c0f4d234e839c90a6b70f157a3d8b088:4f2a9597fc514c75992617c4f1836688c0daf1ca:ec323a0b-ecc0-5af9-ab81-176ee4cd55b8 -->
cursor · cross-file engine perris 0.11.1+proven.tiered0.25.call.read.subclass.type
| Defect | Severity | Found | Grade |
|---|---|---|---|
| d2 | low | ✓ | off by one |
raw comments (2)
### Concurrent test misses exceptions and hangs
**Medium Severity**
<!-- DESCRIPTION START -->
The new concurrent test never joins the reader thread before asserting, so exceptions from an in-flight listing can be missed and the test can pass incorrectly. If a delete throws, `deletedAll` is never set and the reader loops forever. Created groups are also not registered with `managedRealm.cleanup()`, so leftovers can leak into later tests that share this class-scoped realm.
<!-- DESCRIPTION END -->
<!-- BUGBOT_BUG_ID: 0aa4b422-b91b-43c7-8100-838a05a87512 -->
<!-- LOCATIONS START
tests/base/src/test/java/org/keycloak/tests/admin/group/GroupTest.java#L135-L157
LOCATIONS END -->
<div><a href="https://cursor.com/open?link=eyJ2ZXJzaW9uIjoxLCJ0eXBlIjoiQlVHQk9UX0ZJWF9JTl9DVVJTT1IiLCJkYXRhIjp7InJlZGlzS2V5IjoiYnVnYm90OjIxN2E1MDRmLWM3MjgtNDNkNy1hNTYzLWNhYmM0MGU4ZDA1ZCIsImVuY3J5cHRpb25LZXkiOiJERHdFSTlPODNrV1ZHdUdVWE41QnBIcW56QU9NUS1BLVpURlFJbzBvei1BIiwiYnJhbmNoIjoidDIta2V5Y2xvYWstNDA5NDAiLCJyZXBvT3duZXIiOiJkcmFwZS1pbyIsInJlcG9OYW1lIjoiY3JiZW5jaC1jdXJzb3ItMjAyNi0wOSIsInByb3ZpZGVyIjoiZ2l0aHViIn19" target="_blank" rel="noopener noreferrer"><picture><source media="(prefers-color-scheme: dark)" srcset="https://cursor.com/assets/images/fix-in-cursor-dark.png"><source media="(prefers-color-scheme: light)" srcset="https://cursor.com/assets/images/fix-in-cursor-light.png"><img alt="Fix in Cursor" width="115" height="28" src="https://cursor.com/assets/images/fix-in-cursor-dark.png"></picture></a> <a href="https://cursor.com/agents?link=eyJ2ZXJzaW9uIjoxLCJ0eXBlIjoiQlVHQk9UX0ZJWF9JTl9XRUIiLCJkYXRhIjp7InJlZGlzS2V5IjoiYnVnYm90OjIxN2E1MDRmLWM3MjgtNDNkNy1hNTYzLWNhYmM0MGU4ZDA1ZCIsImVuY3J5cHRpb25LZXkiOiJERHdFSTlPODNrV1ZHdUdVWE41QnBIcW56QU9NUS1BLVpURlFJbzBvei1BIiwiYnJhbmNoIjoidDIta2V5Y2xvYWstNDA5NDAiLCJyZXBvT3duZXIiOiJkcmFwZS1pbyIsInJlcG9OYW1lIjoiY3JiZW5jaC1jdXJzb3ItMjAyNi0wOSIsInByTnVtYmVyIjo1OCwiY29tbWl0U2hhIjoiMzUyODMyNDdjMWU4Y2E4MDE3YTg5NzFkMTJmNjYzY2Q1ZTMzZmY3MCIsInByb3ZpZGVyIjoiZ2l0aHViIn19" target="_blank" rel="noopener noreferrer"><picture><source media="(prefers-color-scheme: dark)" srcset="https://cursor.com/assets/images/fix-in-web-dark.png"><source media="(prefers-color-scheme: light)" srcset="https://cursor.com/assets/images/fix-in-web-light.png"><img alt="Fix in Web" width="99" height="28" src="https://cursor.com/assets/images/fix-in-web-dark.png"></picture></a></div>
<sup>Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit 35283247c1e8ca8017a8971d12f663cd5e33ff70. Configure [here](https://www.cursor.com/dashboard/bugbot).</sup>
<!-- BUGBOT_REVIEW -->
Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.
<!-- BUGBOT_FIX_ALL -->
<a href="https://cursor.com/open?link=eyJ2ZXJzaW9uIjoxLCJ0eXBlIjoiQlVHQk9UX0ZJWF9BTExfSU5fQ1VSU09SIiwiZGF0YSI6eyJyZWRpc0tleSI6ImJ1Z2JvdC1tdWx0aTo4N2FiZDBlMi1iZWUxLTQ5MjItOTQ2Ny03MTQzZjVmYmNjMGEiLCJlbmNyeXB0aW9uS2V5IjoiVVBVRXlMMmphd252WFV5clBTdWc3TVJzbGZBTndNTldZN3gwNEg3bHRWSSIsImJyYW5jaCI6InQyLWtleWNsb2FrLTQwOTQwIiwicmVwb093bmVyIjoiZHJhcGUtaW8iLCJyZXBvTmFtZSI6ImNyYmVuY2gtY3Vyc29yLTIwMjYtMDkiLCJwcm92aWRlciI6ImdpdGh1YiJ9fQ" target="_blank" rel="noopener noreferrer"><picture><source media="(prefers-color-scheme: dark)" srcset="https://cursor.com/assets/images/fix-in-cursor-dark.png"><source media="(prefers-color-scheme: light)" srcset="https://cursor.com/assets/images/fix-in-cursor-light.png"><img alt="Fix All in Cursor" width="115" height="28" src="https://cursor.com/assets/images/fix-in-cursor-dark.png"></picture></a>
<!-- /BUGBOT_FIX_ALL -->
<!-- BUGBOT_AUTOFIX_REVIEW_FOOTNOTE_BEGIN -->
<sup>❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the [Cursor dashboard](https://www.cursor.com/dashboard/bugbot).</sup>
<!-- BUGBOT_AUTOFIX_REVIEW_FOOTNOTE_END -->
<sup>Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit 35283247c1e8ca8017a8971d12f663cd5e33ff70. Configure [here](https://www.cursor.com/dashboard/bugbot).</sup>
Drape (Deep Review) · cross-file engine perris 0.11.1+proven.tiered0.25.call.read.subclass.type
| Defect | Severity | Found | Grade |
|---|---|---|---|
| d2 | low | ✓ | exact |
The change does make getSubGroupsCount return null, which breaks the documented contract "Never returns {@code null}" in GroupModel. But the only caller is GroupUtils.populateSubGroupCount, and it passes the value to setSubGroupCount(Long), so nothing unboxes it today. Before this change the same case threw an NPE, so the practical impact is low: a deleted group is returned without a count. [grounded: diff] [consensus 3/3: valid=3]
raw comments (2)
**Subgroup count can now be null, breaking contract**
If a cached group is deleted, `getSubGroupsCount` now returns null. `GroupModel.getSubGroupsCount` documents it never does, so callers that unbox it fail, and the REST response quietly drops the count. Return 0L, or have the caller skip deleted groups.
```
model/infinispan/src/main/java/org/keycloak/models/cache/infinispan/GroupAdapter.java:274 GroupModel model = modelSupplier.get();
model/infinispan/src/main/java/org/keycloak/models/cache/infinispan/GroupAdapter.java:275 return model == null ? null : model.getSubGroupsCount();
server-spi/src/main/java/org/keycloak/models/GroupModel.java:293 /**
server-spi/src/main/java/org/keycloak/models/GroupModel.java:294 * Returns the number of groups contained beneath this group.
server-spi/src/main/java/org/keycloak/models/GroupModel.java:295 *
server-spi/src/main/java/org/keycloak/models/GroupModel.java:296 * @return The number of groups beneath this group. Never returns {@code null}.
server-spi/src/main/java/org/keycloak/models/GroupModel.java:297 */
server-spi/src/main/java/org/keycloak/models/GroupModel.java:298 default Long getSubGroupsCount() {
server-spi/src/main/java/org/keycloak/models/GroupModel.java:299 return getSubGroupsStream().count();
server-spi/src/main/java/org/keycloak/models/GroupModel.java:300 }
```
**Reader thread not joined before asserting**
The reader thread is never joined, so `caughtExceptions` can be checked while a read is still in flight; its exception is missed and the thread outlives the test. Keep the thread and join() it after setting deletedAll, before asserting.
```
tests/base/src/test/java/org/keycloak/tests/admin/group/GroupTest.java:137 List<Exception> caughtExceptions = new CopyOnWriteArrayList<>();
tests/base/src/test/java/org/keycloak/tests/admin/group/GroupTest.java:138 // read groups in a separate thread
tests/base/src/test/java/org/keycloak/tests/admin/group/GroupTest.java:139 new Thread(() -> {
tests/base/src/test/java/org/keycloak/tests/admin/group/GroupTest.java:140 while (!deletedAll.get()) {
tests/base/src/test/java/org/keycloak/tests/admin/group/GroupTest.java:141 try {
tests/base/src/test/java/org/keycloak/tests/admin/group/GroupTest.java:142 // just loading briefs
tests/base/src/test/java/org/keycloak/tests/admin/group/GroupTest.java:143 managedRealm.admin().groups().groups(null, 0, Integer.MAX_VALUE, true);
tests/base/src/test/java/org/keycloak/tests/admin/group/GroupTest.java:144 } catch (Exception e) {
tests/base/src/test/java/org/keycloak/tests/admin/group/GroupTest.java:146 caughtExceptions.add(e);
tests/base/src/test/java/org/keycloak/tests/admin/group/GroupTest.java:147 }
```
Drape (Review) · cross-file engine perris 0.11.1+proven.tiered0.25.call.read.subclass.type
| Defect | Severity | Found | Grade |
|---|---|---|---|
| d2 | low | ✓ | exact |
The change adds a null guard only to getSubGroupsCount(). The parallel getSubGroupsStream overloads still dereference modelSupplier.get() without a check, so they throw an NPE in the same deleted-group race. GroupResource.getSubGroups reaches one of these overloads. This is an incomplete fix across sibling methods. [grounded: tree model/infinispan/src/main/java/org/keycloak/models/cache/infinispan/GroupAdapter.java] [consensus 3/3: valid=3]
GroupModel.getSubGroupsCount() is documented as "Never returns {@code null}", but the new code returns null when the group has been deleted. That breaks the contract, and populateSubGroupCount then sets a null count in the listing. The practical impact is small, since before this change the same case threw an NPE. [grounded: diff] [consensus 3/3: valid=3]
raw comments (3)
**Test doesn't wait for reader thread to finish**
The reader thread is never joined. The test asserts `caughtExceptions` is empty right after `deletedAll.set(true)`, while the thread may still be mid-request. Exceptions from that last read can be added after the assertion, so a regression can pass unnoticed. Keep the Thread reference, call join() after setting deletedAll, then assert.
```
tests/base/src/test/java/org/keycloak/tests/admin/group/GroupTest.java:136 AtomicBoolean deletedAll = new AtomicBoolean(false);
tests/base/src/test/java/org/keycloak/tests/admin/group/GroupTest.java:137 List<Exception> caughtExceptions = new CopyOnWriteArrayList<>();
tests/base/src/test/java/org/keycloak/tests/admin/group/GroupTest.java:138 // read groups in a separate thread
tests/base/src/test/java/org/keycloak/tests/admin/group/GroupTest.java:139 new Thread(() -> {
```
**Other subgroup getters still NPE on deleted group**
The null guard was added only to getSubGroupsCount(). The three getSubGroupsStream(...) overloads still call modelSupplier.get().getSubGroupsStream(...) with no null check, so they throw an NPE when the group was deleted after the adapter was cached. Apply the same null handling to the getSubGroupsStream overloads, for example returning Stream.empty().
```
model/infinispan/src/main/java/org/keycloak/models/cache/infinispan/GroupAdapter.java:272 public Long getSubGroupsCount() {
model/infinispan/src/main/java/org/keycloak/models/cache/infinispan/GroupAdapter.java:273 if (isUpdated()) return updated.getSubGroupsCount();
model/infinispan/src/main/java/org/keycloak/models/cache/infinispan/GroupAdapter.java:274 GroupModel model = modelSupplier.get();
model/infinispan/src/main/java/org/keycloak/models/cache/infinispan/GroupAdapter.java:275 return model == null ? null : model.getSubGroupsCount();
```
**Deleted group listed with null subgroup count**
When a cached group is deleted mid-request, getSubGroupsCount() returns null, breaking GroupModel's documented "never returns null" contract. GroupUtils.populateSubGroupCount then puts a null subGroupCount into the listing for the deleted group. Skip or handle the deleted group in the caller instead of returning null.
```
model/infinispan/src/main/java/org/keycloak/models/cache/infinispan/GroupAdapter.java:274 GroupModel model = modelSupplier.get();
model/infinispan/src/main/java/org/keycloak/models/cache/infinispan/GroupAdapter.java:275 return model == null ? null : model.getSubGroupsCount();
model/infinispan/src/main/java/org/keycloak/models/cache/infinispan/GroupAdapter.java:254 public Stream<GroupModel> getSubGroupsStream(String search, Integer firstResult, Integer maxResults) {
model/infinispan/src/main/java/org/keycloak/models/cache/infinispan/GroupAdapter.java:255 if (isUpdated()) return updated.getSubGroupsStream(search, firstResult, maxResults);
model/infinispan/src/main/java/org/keycloak/models/cache/infinispan/GroupAdapter.java:256 return modelSupplier.get().getSubGroupsStream(search, firstResult, maxResults);
model/infinispan/src/main/java/org/keycloak/models/cache/infinispan/GroupAdapter.java:257 }
model/infinispan/src/main/java/org/keycloak/models/cache/infinispan/GroupAdapter.java:259 @Override
model/infinispan/src/main/java/org/keycloak/models/cache/infinispan/GroupAdapter.java:260 public Stream<GroupModel> getSubGroupsStream(Integer firstResult, Integer maxResults) {
model/infinispan/src/main/java/org/keycloak/models/cache/infinispan/GroupAdapter.java:261 if (isUpdated()) return updated.getSubGroupsStream(firstResult, maxResults);
model/infinispan/src/main/java/org/keycloak/models/cache/infinispan/GroupAdapter.java:262 return modelSupplier.get().getSubGroupsStream(firstResult, maxResults);
```
greptile · cross-file engine perris 0.11.1+proven.tiered0.25.call.read.subclass.type
| Defect | Severity | Found | Grade |
|---|---|---|---|
| d2 | low | ✓ | off by one |
GroupModel.getSubGroupsCount() is documented as "Never returns {@code null}" (server-spi GroupModel.java:296). The change now returns null when the group is deleted concurrently, so it breaks that documented contract. The old code threw an NPE instead, and the only caller shown, populateSubGroupCount, passes the Long straight to a setter without unboxing it. So the real-world impact is limited, but the contract break is real. [grounded: diff] [consensus 3/3: valid=3]
raw comments (3)
<a href="#"><img alt="P1" src="https://greptile-static-assets.s3.amazonaws.com/badges/p1.svg?v=9" align="top"></a> **Nullable Count Breaks Contract**
During concurrent deletion, `modelSupplier.get()` can return `null`, so this method now returns `null` even though `GroupModel.getSubGroupsCount()` guarantees a non-null result. Callers that rely on this contract or unbox the returned `Long` can fail with a `NullPointerException`. Preserve the non-null contract while handling the missing delegate.
<a href="#"><img alt="P2" src="https://greptile-static-assets.s3.amazonaws.com/badges/p2.svg?v=9" align="top"></a> **Reader Thread Is Not Awaited**
The test signals the reader to stop and immediately checks `caughtExceptions` without retaining or joining the thread. The assertion can run before the reader starts, overlaps a deletion, or records a late exception, allowing the regression test to pass without exercising the failure. The thread can also continue into test teardown. Synchronize the start of concurrent reads and join the reader before asserting.
<h3>Greptile Summary</h3>
This PR changes cached subgroup-count handling when a backing group disappears concurrently, removes an unused group-search helper, clarifies an implemented interface method, and adds a concurrent group deletion/read regression test.
- Avoids dereferencing an unavailable backing `GroupModel`, but exposes a nullable value contrary to the model contract.
- Adds concurrent read/delete coverage, though the reader is not synchronized or joined.
- Removes dead utility code and adds a valid override annotation.
<h3>Confidence Score: 4/5</h3>
The PR is not yet safe to merge because the production change violates the non-null `GroupModel` contract during concurrent deletion.
The missing backing group is a realistic concurrent-deletion state, and the changed adapter propagates that state as null to callers whose interface contract guarantees a count; the accompanying test can also miss the regression because it does not synchronize with the reader thread.
**Files Needing Attention:** model/infinispan/src/main/java/org/keycloak/models/cache/infinispan/GroupAdapter.java; tests/base/src/test/java/org/keycloak/tests/admin/group/GroupTest.java
<details><summary><h3>Important Files Changed</h3></summary>
| Filename | Overview |
|----------|----------|
| model/infinispan/src/main/java/org/keycloak/models/cache/infinispan/GroupAdapter.java | Handles an unavailable backing group during subgroup counting by returning null, violating the declared non-null model contract. |
| model/infinispan/src/main/java/org/keycloak/models/cache/infinispan/entities/CachedGroup.java | Adds a valid `@Override` annotation to the realm accessor. |
| services/src/main/java/org/keycloak/utils/GroupUtils.java | Removes an unused private helper without leaving dangling references or imports. |
| tests/base/src/test/java/org/keycloak/tests/admin/group/GroupTest.java | Adds concurrent group read/delete coverage, but does not coordinate or await the reader thread. |
</details>
<!-- greptile_other_comments_section -->
<sub>Reviews (1): Last reviewed commit: ["Update model/infinispan/src/main/java/or..."](https://github.com/drape-io/crbench-greptile-2026-09/commit/1cf9efc5b3ec48e21b9c6b26bfca83d42043661f) | [Re-trigger Greptile](https://app.greptile.com/api/retrigger?id=64284640)</sub>
Mjolnir (Opus 5.5) · cross-file engine perris 0.11.1+proven.tiered0.25.call.read.subclass.type
| Defect | Severity | Found | Grade |
|---|---|---|---|
| d2 | low | ✓ | exact |
The new test starts a thread and never joins it. It sets deletedAll and asserts right away, so exceptions from a read still in flight can be missed. The flag is not set in a finally block, so if a remove call throws, the thread keeps looping. [grounded: diff] [consensus 3/3: valid=3]
raw comments (2)
[P3] Reader thread is never joined or stopped if the test fails
tests/base/src/test/java/org/keycloak/tests/admin/group/GroupTest.java:139-157 The background reader thread is started and then left running. The test sets `deletedAll` and checks `caughtExceptions` right away without calling `join()`, so an exception thrown by a read that is still in flight when deletion finishes is never seen. That can hide the race this test is meant to catch. Also, if `remove()` or group creation throws (for example, a failed delete), `deletedAll` is never set. The non-daemon thread then keeps sending full group-list requests to the server for the rest of the suite and can stop the test JVM from exiting. Setting the flag in a `finally` block and joining the thread before the assertion would fix both problems.
[P3] Reader thread is never joined before asserting on its exceptions
The test sets `deletedAll` and checks `caughtExceptions` right away, without waiting for the reader thread to finish. That thread can still be running a `groups(...)` call when the assertion executes, which is exactly when it would read a group deleted near the end. An exception from that call is added after the assertion has already passed, so this regression test can pass even when the bug is present. The thread can also outlive the test and keep calling the shared admin client while the realm is cleaned up or the next test starts. Keep a reference to the `Thread` and call `join()` after setting `deletedAll` and before the `assertThat`. That makes the result deterministic.
Mjolnir (Sonnet 5.5) · cross-file engine perris 0.11.1+proven.tiered0.25.call.read.subclass.type
| Defect | Severity | Found | Grade |
|---|---|---|---|
| d2 | low | ✗ | — |
qodo · cross-file engine perris 0.11.1+proven.tiered0.25.call.read.subclass.type
| Defect | Severity | Found | Grade |
|---|---|---|---|
| d2 | low | ✓ | wrong severity |
GroupModel.getSubGroupsCount() is documented as 'Never returns {@code null}', and the new code returns null when the backing group was deleted concurrently. Before this change the same case threw an NPE. The fix trades the crash for a null subGroupCount in admin API representations, which still breaks the documented contract. [grounded: diff] [consensus 3/3: valid=3]
deletedAll is set only after every removal succeeds, and nothing calls join or a finally block. So if any remove() throws, the non-daemon reader thread keeps looping forever and keeps sending requests. The new test code added this. [grounded: diff] [consensus 3/3: valid=3]
raw comments (5)
<img src="https://img.shields.io/badge/High-634FD1?style=flat-square" height="20px" alt="Action required">
1\. Group responses expose a null count <code>🐞 Bug</code> <code>≡ Correctness</code>
<pre>
<b><i>GroupAdapter.getSubGroupsCount()</i></b> returns <b><i>null</i></b> when <b><i>modelSupplier</i></b> cannot resolve a backing
group, despite the model method's explicit non-null contract. A concurrent deletion can trigger this
branch while a cached group is being converted, and <b><i>GroupUtils.populateSubGroupCount()</i></b> propagates
the value directly into the admin API representation.
</pre>
<details>
<summary><strong>Agent Prompt</strong></summary>
```
## Issue description
`GroupAdapter.getSubGroupsCount()` now returns `null` when its backing group disappears, violating `GroupModel#getSubGroupsCount()`'s documented non-null contract and propagating a null count into group representations.
## Fix Focus Areas
- model/infinispan/src/main/java/org/keycloak/models/cache/infinispan/GroupAdapter.java[274-275]
- server-spi/src/main/java/org/keycloak/models/GroupModel.java[293-300]
- services/src/main/java/org/keycloak/utils/GroupUtils.java[89-91]
## Recommended Fix
Handle an absent backing group without returning null, such as returning `0L` for the concurrently deleted group or excluding that stale group before representation conversion, while preserving the non-null model contract.
```
<code>ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools</code>
</details>
<img src="https://img.shields.io/badge/High-634FD1?style=flat-square" height="20px" alt="Action required">
2\. Concurrent read failures escape the test <code>🐞 Bug</code> <code>☼ Reliability</code>
<pre>
<b><i>createMultiDeleteMultiReadMulti()</i></b> starts an unretained reader thread and checks <b><i>caughtExceptions</i></b>
without waiting for that thread's in-flight request to finish. If the final request fails after
<b><i>deletedAll</i></b> is set, the assertion can run before the exception is recorded and the regression still
passes.
</pre>
<details>
<summary><strong>Agent Prompt</strong></summary>
```
## Issue description
The concurrent group test asserts its exception list without joining the reader thread, so an exception from the final in-flight request can be recorded after the assertion.
## Fix Focus Areas
- tests/base/src/test/java/org/keycloak/tests/admin/group/GroupTest.java[136-157]
## Recommended Fix
Store the reader `Thread` in a variable, signal it to stop after deletion, join it with a bounded timeout, assert that it terminated, and only then inspect `caughtExceptions`.
```
<code>ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools</code>
</details>
<img src="https://img.shields.io/badge/Medium-634FD1?style=flat-square" height="20px" alt="Remediation recommended">
3\. A failed deletion leaves a runaway thread <code>🐞 Bug</code> <code>☼ Reliability</code>
<pre>
<b><i>createMultiDeleteMultiReadMulti()</i></b> sets <b><i>deletedAll</i></b> only after every removal succeeds, and the
newly created reader is a non-daemon thread with no other termination path. If any removal throws,
control skips the flag update while the reader continues issuing requests, allowing it to overlap
cleanup or keep the test process alive.
</pre>
<details>
<summary><strong>Agent Prompt</strong></summary>
```
## Issue description
An exception during group deletion bypasses the reader's stop signal, leaving the non-daemon worker loop running after the test fails.
## Fix Focus Areas
- tests/base/src/test/java/org/keycloak/tests/admin/group/GroupTest.java[136-155]
## Recommended Fix
Retain the reader thread and place the stop signal plus bounded join in a `finally` block so every success or failure path terminates the worker before the test returns.
```
<code>ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools</code>
</details>
<h3>PR Summary by Qodo</h3>
Handle concurrent group deletion during cached subgroup counts
<code>🐞 Bug fix</code> <code>🧪 Tests</code> <code>🕐 10-20 Minutes</code>
<img src="https://www.qodo.ai/wp-content/uploads/2025/11/light-grey-line.svg" height="10%" alt="Grey Divider">
<details>
<summary>AI Description</summary>
<dl>
<dd>
<br/>
><pre>
>• Prevent subgroup-count reads from failing when cached groups are concurrently deleted.
>• Add concurrent create, list, and delete coverage for group administration.
>• Remove obsolete group-search logic and clarify the cached realm accessor override.
></pre>
</dd>
</dl>
</details>
<details>
<summary>Diagram</summary>
<dl>
<dd>
<br/>
```mermaid
sequenceDiagram
actor Test as Concurrent Test
participant API as Group API
participant Cache as Realm Cache
participant Adapter as Group Adapter
participant Store as Group Store
Test->>API: Create groups
par Read brief groups
Test->>API: List groups
API->>Cache: Load cached groups
Cache->>Adapter: Get subgroup count
Adapter->>Store: Resolve model
Store-->>Adapter: Model or null
Adapter-->>Cache: Count or null
Cache-->>API: Group representations
and Delete groups
Test->>API: Delete groups
API->>Store: Remove groups
API->>Cache: Invalidate entries
end
```
</dd>
</dl>
</details>
<details>
<summary>High-Level Assessment</summary>
<dl>
<dd>
<br/>
>The focused null-safe supplier lookup is appropriate because it addresses the deletion race without changing cache contents or subgroup-count semantics. Caching subgroup counts directly or suppressing API exceptions more broadly would introduce stale data or hide unrelated failures.
</dd>
</dl>
</details>
<details>
<summary> Files changed (4) <code> +51 / -11 </code> </summary>
<dl>
<dd>
<br/>
<details>
<summary>Bug fix (1) <code> +2 / -1 </code></summary>
<dl>
<dd>
<details>
<summary>GroupAdapter.java<code>Make subgroup count lookup safe after concurrent deletion</code> <code>+2/-1</code></summary>
<br/>
>Make subgroup count lookup safe after concurrent deletion
>
><pre>
>• Resolves the backing group through the existing lazy model supplier and returns null when the group has already disappeared. This prevents a null dereference while listing cached groups during concurrent deletion.
></pre>
>
><a href='https://github.com/drape-io/crbench-qodo-2026-09/pull/54/files#diff-6acfec0791f55ce62274d36d5f4d764dfbcd3c763a3aae839651218d1086e99a'>model/infinispan/src/main/java/org/keycloak/models/cache/infinispan/GroupAdapter.java</a>
</details>
</dd>
</dl>
</details>
<details>
<summary>Refactor (2) <code> +1 / -10 </code></summary>
<dl>
<dd>
<details>
<summary>CachedGroup.java<code>Mark the realm accessor as an interface override</code> <code>+1/-0</code></summary>
<br/>
>Mark the realm accessor as an interface override
>
><pre>
>• Adds the missing Override annotation to the cached group's InRealm contract implementation.
></pre>
>
><a href='https://github.com/drape-io/crbench-qodo-2026-09/pull/54/files#diff-f3a3eb383624b5d638b62318e1e5f7ea23de4c767f367812413a76f3a464f6ed'>model/infinispan/src/main/java/org/keycloak/models/cache/infinispan/entities/CachedGroup.java</a>
</details>
<details>
<summary>GroupUtils.java<code>Remove obsolete group search helper</code> <code>+0/-10</code></summary>
<br/>
>Remove obsolete group search helper
>
><pre>
>• Deletes an unused helper that previously checked whether a group matched a search term or contained subgroups.
></pre>
>
><a href='https://github.com/drape-io/crbench-qodo-2026-09/pull/54/files#diff-d736e7222ccd6e0f0be577ab04ab10a3dbab54ff41fff7873c235223b71ab6ae'>services/src/main/java/org/keycloak/utils/GroupUtils.java</a>
</details>
</dd>
</dl>
</details>
<details>
<summary>Tests (1) <code> +48 / -0 </code></summary>
<dl>
<dd>
<details>
<summary>GroupTest.java<code>Cover concurrent group listing and deletion</code> <code>+48/-0</code></summary>
<br/>
>Cover concurrent group listing and deletion
>
><pre>
>• Adds an integration test that creates 100 groups, repeatedly requests brief group listings from a background thread, and deletes the groups concurrently. The test asserts that group reads complete without client-visible exceptions.
></pre>
>
><a href='https://github.com/drape-io/crbench-qodo-2026-09/pull/54/files#diff-09029369f6dcb59247af73ecf684d308388b0203d39b59afc7916d5b805de152'>tests/base/src/test/java/org/keycloak/tests/admin/group/GroupTest.java</a>
</details>
</dd>
</dl>
</details>
</dd>
</dl>
</details>
<h3>Code Review by Qodo</h3>
<code>🐞 Bugs (3)</code> <code>📘 Rule violations (0)</code> <code>📜 Skill insights (0)</code>
<img src="https://www.qodo.ai/wp-content/uploads/2025/11/light-grey-line.svg" height="10%" alt="Grey Divider">
<br/>
<img src="https://img.shields.io/badge/High-634FD1?style=flat-square" height="20px" alt="Action required">
<details>
<summary> 1. Group responses expose a null count <code>🐞 Bug</code> <code>≡ Correctness</code></summary>
<br/>
> <details open>
><summary>Description</summary>
><br/>
>
><pre>
><b><i>GroupAdapter.getSubGroupsCount()</i></b> returns <b><i>null</i></b> when <b><i>modelSupplier</i></b> cannot resolve a backing
>group, despite the model method's explicit non-null contract. A concurrent deletion can trigger this
>branch while a cached group is being converted, and <b><i>GroupUtils.populateSubGroupCount()</i></b> propagates
>the value directly into the admin API representation.
></pre>
></details>
> <details>
><summary>Code</summary>
><br/>
>
><code>[model/infinispan/src/main/java/org/keycloak/models/cache/infinispan/GroupAdapter.java[R274-275]](https://github.com/drape-io/crbench-qodo-2026-09/pull/54/files#diff-6acfec0791f55ce62274d36d5f4d764dfbcd3c763a3aae839651218d1086e99aR274-R275)</code>
>
>```diff
>+ GroupModel model = modelSupplier.get();
>+ return model == null ? null : model.getSubGroupsCount();
>```
></details>
> <details>
><summary>Evidence</summary>
><br/>
>
><pre>
>The supplier wraps <b><i>getGroupModel()</i></b>, which may not resolve a concurrently deleted group, while the
>interface explicitly says the count never returns null and the representation helper copies it
>without validation.
></pre>
>
> <code>[model/infinispan/src/main/java/org/keycloak/models/cache/infinispan/GroupAdapter.java[49-55]](https://github.com/drape-io/crbench-qodo-2026-09/blob/434d186c32e1bf6b757ef90cdbc521d298cb22eb/model/infinispan/src/main/java/org/keycloak/models/cache/infinispan/GroupAdapter.java/#L49-L55)</code>
> <code>[model/infinispan/src/main/java/org/keycloak/models/cache/infinispan/GroupAdapter.java[298-300]](https://github.com/drape-io/crbench-qodo-2026-09/blob/434d186c32e1bf6b757ef90cdbc521d298cb22eb/model/infinispan/src/main/java/org/keycloak/models/cache/infinispan/GroupAdapter.java/#L298-L300)</code>
> <code>[server-spi/src/main/java/org/keycloak/models/GroupModel.java[293-300]](https://github.com/drape-io/crbench-qodo-2026-09/blob/434d186c32e1bf6b757ef90cdbc521d298cb22eb/server-spi/src/main/java/org/keycloak/models/GroupModel.java/#L293-L300)</code>
> <code>[services/src/main/java/org/keycloak/utils/GroupUtils.java[89-91]](https://github.com/drape-io/crbench-qodo-2026-09/blob/434d186c32e1bf6b757ef90cdbc521d298cb22eb/services/src/main/java/org/keycloak/utils/GroupUtils.java/#L89-L91)</code>
></details>
> <details>
><summary>Agent prompt</summary>
><br/>
>
>```
>The issue below was found during a code review. Follow the provided context and guidance below and implement a solution
>
>## Issue description
>`GroupAdapter.getSubGroupsCount()` now returns `null` when its backing group disappears, violating `GroupModel#getSubGroupsCount()`'s documented non-null contract and propagating a null count into group representations.
>
>## Fix Focus Areas
>- model/infinispan/src/main/java/org/keycloak/models/cache/infinispan/GroupAdapter.java[274-275]
>- server-spi/src/main/java/org/keycloak/models/GroupModel.java[293-300]
>- services/src/main/java/org/keycloak/utils/GroupUtils.java[89-91]
>
>## Recommended Fix
>Handle an absent backing group without returning null, such as returning `0L` for the concurrently deleted group or excluding that stale group before representation conversion, while preserving the non-null model contract.
>```
> <code>ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools</code>
></details>
<hr/>
</details>
<details>
<summary> 2. Concurrent read failures escape the test <code>🐞 Bug</code> <code>☼ Reliability</code></summary>
<br/>
> <details open>
><summary>Description</summary>
><br/>
>
><pre>
><b><i>createMultiDeleteMultiReadMulti()</i></b> starts an unretained reader thread and checks <b><i>caughtExceptions</i></b>
>without waiting for that thread's in-flight request to finish. If the final request fails after
><b><i>deletedAll</i></b> is set, the assertion can run before the exception is recorded and the regression still
>passes.
></pre>
></details>
> <details>
><summary>Code</summary>
><br/>
>
><code>[tests/base/src/test/java/org/keycloak/tests/admin/group/GroupTest.java[R155-157]](https://github.com/drape-io/crbench-qodo-2026-09/pull/54/files#diff-09029369f6dcb59247af73ecf684d308388b0203d39b59afc7916d5b805de152R155-R157)</code>
>
>```diff
>+ deletedAll.set(true);
>+
>+ assertThat(caughtExceptions, Matchers.empty());
>```
></details>
> <details>
><summary>Evidence</summary>
><br/>
>
><pre>
>The worker records exceptions asynchronously, but the main test sets the stop flag and immediately
>asserts the shared list; no join establishes that the last request and its catch block have
>completed.
></pre>
>
> <code>[tests/base/src/test/java/org/keycloak/tests/admin/group/GroupTest.java[136-149]](https://github.com/drape-io/crbench-qodo-2026-09/blob/434d186c32e1bf6b757ef90cdbc521d298cb22eb/tests/base/src/test/java/org/keycloak/tests/admin/group/GroupTest.java/#L136-L149)</code>
> <code>[tests/base/src/test/java/org/keycloak/tests/admin/group/GroupTest.java[151-157]](https://github.com/drape-io/crbench-qodo-2026-09/blob/434d186c32e1bf6b757ef90cdbc521d298cb22eb/tests/base/src/test/java/org/keycloak/tests/admin/group/GroupTest.java/#L151-L157)</code>
></details>
> <details>
><summary>Agent prompt</summary>
><br/>
>
>```
>The issue below was found during a code review. Follow the provided context and guidance below and implement a solution
>
>## Issue description
>The concurrent group test asserts its exception list without joining the reader thread, so an exception from the final in-flight request can be recorded after the assertion.
>
>## Fix Focus Areas
>- tests/base/src/test/java/org/keycloak/tests/admin/group/GroupTest.java[136-157]
>
>## Recommended Fix
>Store the reader `Thread` in a variable, signal it to stop after deletion, join it with a bounded timeout, assert that it terminated, and only then inspect `caughtExceptions`.
>```
> <code>ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools</code>
></details>
<hr/>
</details>
<br/>
<img src="https://img.shields.io/badge/Medium-634FD1?style=flat-square" height="20px" alt="Remediation recommended">
<details>
<summary> 3. A failed deletion leaves a runaway thread <code>🐞 Bug</code> <code>☼ Reliability</code></summary>
<br/>
> <details open>
><summary>Description</summary>
><br/>
>
><pre>
><b><i>createMultiDeleteMultiReadMulti()</i></b> sets <b><i>deletedAll</i></b> only after every removal succeeds, and the
>newly created reader is a non-daemon thread with no other termination path. If any removal throws,
>control skips the flag update while the reader continues issuing requests, allowing it to overlap
>cleanup or keep the test process alive.
></pre>
></details>
> <details>
><summary>Code</summary>
><br/>
>
><code>[tests/base/src/test/java/org/keycloak/tests/admin/group/GroupTest.java[R152-155]](https://github.com/drape-io/crbench-qodo-2026-09/pull/54/files#diff-09029369f6dcb59247af73ecf684d308388b0203d39b59afc7916d5b805de152R152-R155)</code>
>
>```diff
>+ groupUuuids.forEach(groupUuid -> {
>+ managedRealm.admin().groups().group(groupUuid).remove();
>+ });
>+ deletedAll.set(true);
>```
></details>
> <details>
><summary>Evidence</summary>
><br/>
>
><pre>
>The loop continues while <b><i>deletedAll</i></b> is false, but that value is only changed after the full
>deletion loop; an exception from any <b><i>remove()</i></b> prevents the only stop statement from executing.
></pre>
>
> <code>[tests/base/src/test/java/org/keycloak/tests/admin/group/GroupTest.java[136-149]](https://github.com/drape-io/crbench-qodo-2026-09/blob/434d186c32e1bf6b757ef90cdbc521d298cb22eb/tests/base/src/test/java/org/keycloak/tests/admin/group/GroupTest.java/#L136-L149)</code>
> <code>[tests/base/src/test/java/org/keycloak/tests/admin/group/GroupTest.java[151-155]](https://github.com/drape-io/crbench-qodo-2026-09/blob/434d186c32e1bf6b757ef90cdbc521d298cb22eb/tests/base/src/test/java/org/keycloak/tests/admin/group/GroupTest.java/#L151-L155)</code>
></details>
> <details>
><summary>Agent prompt</summary>
><br/>
>
>```
>The issue below was found during a code review. Follow the provided context and guidance below and implement a solution
>
>## Issue description
>An exception during group deletion bypasses the reader's stop signal, leaving the non-daemon worker loop running after the test fails.
>
>## Fix Focus Areas
>- tests/base/src/test/java/org/keycloak/tests/admin/group/GroupTest.java[136-155]
>
>## Recommended Fix
>Retain the reader thread and place the stop signal plus bounded join in a `finally` block so every success or failure path terminates the worker before the test returns.
>```
> <code>ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools</code>
></details>
<hr/>
</details>
<img src="https://www.qodo.ai/wp-content/uploads/2025/11/light-grey-line.svg" height="10%" alt="Grey Divider">
<!-- qodo-context:start -->
<details><summary><strong>Context sources</strong></summary>
<div>Review mode: <code>⚖️ Balanced</code>: This changes cache behavior and adds a concurrent create/delete/read integration test, creating meaningful runtime and concurrency risk, but the scope is not dense enough to warrant extended review.</div>
<!-- qodo-context:end -->
</details>
<img src="https://www.qodo.ai/wp-content/uploads/2025/11/light-grey-line.svg" height="10%" alt="Grey Divider">
<!-- qodo-daily-tip:start -->
<details>
<summary><strong>Tip of the day</strong></summary>
<br/>
<pre>💡 Did you know, you can reply 'qodo' on any finding to push back, ask questions, or dig deeper</pre>
<a href="https://docs.qodo.ai/tips-and-tricks">More tips ↗</a> | <a href="https://app.qodo.ai/configurations?tab=display-preferences">Customize Qodo ↗</a> | <a href="https://docs.qodo.ai">Qodo docs ↗</a>
</details>
<img src="https://www.qodo.ai/wp-content/uploads/2025/11/light-grey-line.svg" height="10%" alt="Grey Divider">
<!-- qodo-daily-tip:end -->
<!-- https://github.com/drape-io/crbench-qodo-2026-09/commit/434d186c32e1bf6b757ef90cdbc521d298cb22eb -->
<a href="https://www.qodo.ai"><img src="https://www.qodo.ai/wp-content/uploads/2025/03/qodo-logo.svg" width="80" alt="Qodo Logo"></a>