-
Notifications
You must be signed in to change notification settings - Fork 5.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ProviderManager Should Use CollectionUtils#contains #8695
ProviderManager Should Use CollectionUtils#contains #8695
Conversation
@yukihane Please sign the Contributor License Agreement! Click here to manually synchronize the status of this Pull Request. See the FAQ for frequently asked questions. |
@yukihane Thank you for signing the Contributor License Agreement! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the quick turnaround, @yukihane! I've left some feedback inline.
@@ -145,7 +145,7 @@ private void checkState() { | |||
throw new IllegalArgumentException( | |||
"A parent AuthenticationManager or a list " | |||
+ "of AuthenticationProviders is required"); | |||
} else if (providers.contains(null)) { | |||
} else if (providers.stream().anyMatch(Objects::isNull)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
At the framework level, we find that the Stream API is not fast enough. Would you please use a for loop instead?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In particular we avoid the Stream APIs because they create extra objects which leads to excessive Garbage Collection. This can cause the JDK to pause and deteriorate the performance. See gh-7154
I believe we could use Spring's CollectionUtils.contains
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've understood it and amended to use CollectionUtils.contains
.
@@ -102,6 +102,26 @@ public void testStartupFailsIfProvidersNotSetAsVarargs() { | |||
new ProviderManager((AuthenticationProvider) null); | |||
} | |||
|
|||
@Test | |||
public void testUsingNullNotPermittedList() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this test has the right idea. It seems like the list ought to have a null
element, though, to fully describe the use case.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I assumed it already existed.
I've created additional test case.
3b7fe27
to
a8d910e
Compare
Use
stream().anyMatch(Objects::isNull)
insead ofcontains(null)
, which may throwNullPointerException
.Fixes #8689