GLM-5.3 Flash · 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
2 of 2
Comments published
4
Comments matching a bug
2
Comments not matching
2
Cost of this PR
$0.044

Published comments (4)

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

Null modelSupplier result still dereferenced in sibling getSubGroupsStream overloads — The same null from `modelSupplier.get()` still reaches the `getSubGroupsStream` overloads, including one used by the group-children endpoint in `GroupResource`, so the NPE this PR fixes remains reproducible. Apply the same null handling to all three sibling overloads.

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

getSubGroupsCount() returns null, violating GroupModel's never-null contract — The null propagates through `GroupUtils.populateSubGroupCount` and is serialized as a null `subGroupCount` in admin API responses, breaking clients that expect a number. Return `0L` instead — a group that no longer resolves has no subgroups.

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

Reader thread not joined before asserting no exceptions were captured — A request still in flight when `deletedAll` is set can append to `caughtExceptions` after the assertion has already run, so the test passes despite capturing the exact concurrent-deletion failure it should detect. Join the reader thread before asserting on `caughtExceptions`.

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

Reader thread spins forever if a group delete throws before deletedAll is set — If any `remove()` call throws, `deletedAll.set(true)` is never reached and the reader thread loops forever issuing admin requests, hanging the test JVM and discarding the collected exceptions. Wrap the deletion loop in try/finally so `deletedAll` is always set.

Gold bugs found (2)

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

Gold bugs missed (0)

None.