Amazon Ergo 1.0 · Balanced

fix-concurrent-group-access-to-prevent-nullpointerexception-keycloak

Keycloak · Java · XS · <30 lines · 3 files

The normal review, with one generalist agent. Judge: Claude Opus 5.5.

Gold bugs found
1 of 2
Comments published
3
Comments matching a bug
1
Comments not matching
2
Cost of this PR
$0.497

Published comments (3)

mediumbugmodel/infinispan/src/main/java/org/keycloak/models/cache/infinispan/GroupAdapter.java:274-275

getSubGroupsCount() returns null for a concurrently deleted group — Unboxing the result can throw a `NullPointerException` because `GroupModel.getSubGroupsCount()` promises never to return null. Return `0L` when the model is gone, or update the SPI contract.

mediumbugtests/base/src/test/java/org/keycloak/tests/admin/group/GroupTest.java:151-157

Reader thread is not joined before checking caught exceptions — An exception from the last in-flight request can be added after `assertThat(caughtExceptions, ...)` runs, letting the test pass despite the failure. Join the reader thread before asserting.

mediumbugtests/base/src/test/java/org/keycloak/tests/admin/group/GroupTest.java:136-155

Failed group deletion leaves reader thread running indefinitely — If a group `remove()` call throws, `deletedAll` stays false and the non-daemon reader thread can hang the test JVM indefinitely. Set `deletedAll` in a `finally` block and join the reader thread.

Gold bugs found (1)

mediumThe concurrency regression test never waits for the reader thread before asserting no exceptions, so it can pass even when the concurrent-deletion NPE still occurs.

Gold bugs missed (1)

mediumThe null guard for a concurrently deleted cached group is added only to getSubGroupsCount; the getSubGroupsStream overloads still dereference modelSupplier.get(), so e.g. GroupResource.getSubGroups still throws the NPE the PR set out to fix.