Skip to content

fix: guard null email in group membership leave admin event#104

Merged
nicolamacoir merged 1 commit into
Metatavu:developfrom
nicolamacoir:fix/group-leave-event-null-email
May 22, 2026
Merged

fix: guard null email in group membership leave admin event#104
nicolamacoir merged 1 commit into
Metatavu:developfrom
nicolamacoir:fix/group-leave-event-null-email

Conversation

@nicolamacoir
Copy link
Copy Markdown
Contributor

Summary

  • Fixes PATCH /Groups remove-member fails with NPE if target user has no email #103PATCH /Groups remove-member returned HTTP 500 when the target user had no email set.
  • GroupsController.dispatchGroupMembershipLeaveEvent passed user.getEmail() straight into Map.of(...), which rejects null values and threw NullPointerException.
  • The sibling dispatchGroupMembershipJoinEvent already coalesced null to ""; this PR applies the same guard to the leave event so the two paths stay symmetric.

Changes

  • GroupsController.java:414user.getEmail() == null ? "" : user.getEmail() in the admin event representation map.
  • RealmGroupPatchTestsIT.testRemoveGroupMemberWithoutEmail — regression test that creates a user, clears their email via the Keycloak admin client, adds them to a group, then removes them via SCIM PATCH and asserts success.

Test plan

  • ./gradlew test --tests "fi.metatavu.keycloak.scim.server.test.tests.functional.RealmGroupPatchTestsIT" passes
  • Existing testRemoveGroupMember / testRemoveGroupMemberAdminEvents still pass
  • Manually verify: PATCH-remove on an email-less user no longer 500s

GroupsController.dispatchGroupMembershipLeaveEvent passed
user.getEmail() directly into Map.of(), which rejects null values
and threw NullPointerException whenever the removed member had no
email set in Keycloak. PATCH /Groups remove-member then returned
HTTP 500 to the client.

The sibling join event already coalesces null to "" — apply the
same guard to the leave event so the two paths stay symmetric.

Adds a regression test that creates a user, clears their email
via the Keycloak admin client, then removes them from a group
via SCIM PATCH and asserts success.

Closes Metatavu#103
@sonarqubecloud
Copy link
Copy Markdown

@nicolamacoir nicolamacoir merged commit 5c89498 into Metatavu:develop May 22, 2026
3 checks passed
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.

PATCH /Groups remove-member fails with NPE if target user has no email

1 participant