Skip to content

fix: allow nullable uid in InetOrgPerson#19373

Open
ezhilnn wants to merge 1 commit into
spring-projects:mainfrom
ezhilnn:fix/inet-org-person-nullable-uid
Open

fix: allow nullable uid in InetOrgPerson#19373
ezhilnn wants to merge 1 commit into
spring-projects:mainfrom
ezhilnn:fix/inet-org-person-nullable-uid

Conversation

@ezhilnn

@ezhilnn ezhilnn commented Jun 23, 2026

Copy link
Copy Markdown

Fixes #19370

Problem

uid is marked @Nullable on the field but two places contradicted
this:

  • getUid() called Objects.requireNonNull(), throwing NPE if uid is null
  • Essence(DirContextOperations) constructor called Assert.notNull(),
    throwing IllegalArgumentException if uid is absent from LDAP context

According to the LDAP inetOrgPerson schema, uid is not a mandatory
field. This behavior also regressed from pre-7.1.0 behavior (introduced
in commit c5632cc).

Changes

  • getUid() now returns @Nullable String and returns the field directly
  • Constructor no longer asserts uid is non-null; skips setUid() if absent
  • setUid() now accepts @Nullable String and guards username mapping
    with a null check

Testing

  • Added testNullUidIsAllowed() to verify null uid no longer throws

Signed-off-by: ezhilnn <ezhilnaga4732@gmail.com>
@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Jun 23, 2026
@ezhilnn ezhilnn force-pushed the fix/inet-org-person-nullable-uid branch from 3c516d5 to dd57915 Compare June 23, 2026 19:24
@ezhilnn

ezhilnn commented Jun 29, 2026

Copy link
Copy Markdown
Author

@spring-projects-issues can someone approve this

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

The commit c5632cc broke the uid nullability and introduced an additional local username variable that seems to be unnecessary.
I am suggesting to restore these parts to the original code. I have added detailed comments for the changes.


public static class Essence extends Person.Essence {

private @Nullable String username;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This can be removed like in the previous version when the instance.getUsername() is directly checked in setUid()

Comment on lines 248 to 251
public void setUsername(String username) {
super.setUsername(username);
this.username = username;
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Remove this, no override is necessary when no local username variable is used.

((InetOrgPerson) this.instance).uid = uid;

if (this.username == null) {
if (this.username == null && uid != null) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Suggested change
if (this.username == null && uid != null) {
if (this.instance.getUsername() == null) {

Directly check the instance.getUsername(). The check for uid != null is not necessary.

Comment on lines 224 to +227
String uid = ctx.getStringAttribute("uid");
Assert.notNull(uid, "uid cannot be null");
setUid(uid);
if (uid != null) {
setUid(uid);
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Suggested change
String uid = ctx.getStringAttribute("uid");
Assert.notNull(uid, "uid cannot be null");
setUid(uid);
if (uid != null) {
setUid(uid);
}
setUid(ctx.getStringAttribute("uid"));

I would just restore the original code, also to be consistent with the other attributes:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

status: waiting-for-triage An issue we've not yet triaged

Projects

None yet

Development

Successfully merging this pull request may close these issues.

InetOrgPerson uid should not be a mandatory field - may cause regression as of version 7.1.0

3 participants