Skip to content

Conversation

@ryujungkyun
Copy link

Fixes #gh-18585

This PR replaces orElse with orElseGet in WebAuthnConfigurer
to ensure lazy instantiation of default repositories.

In the configure method of WebAuthnConfigurer, Optional.orElse() is currently
used to provide default implementations when specific Beans are not found
in the ApplicationContext.

image

However, orElse() evaluates its argument eagerly. As a result,
userEntityRepository() and userCredentialRepository() are always invoked,
instantiating new repository objects even when a corresponding repository
Bean is already present in the ApplicationContext.

This leads to unnecessary object creation each time the configuration
is initialized.

I propose replacing orElse with orElseGet to ensure that the default
repositories are instantiated only when the Optional is empty.

image

This change aligns with Java Optional best practices by avoiding unnecessary
object creation and ensuring that default components are initialized only
when they are actually needed.

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Jan 25, 2026
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.

2 participants