-
Notifications
You must be signed in to change notification settings - Fork 134
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
StreamOptionalGetWithoutFilter #2949
base: develop
Are you sure you want to change the base?
Conversation
Generate changelog in
|
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.
How confident are we that there are no legitimate uses to call .map(Optional::get)
without filtering? I can't think of an specific uses, but I wouldn't be surprised if there were some.
|
||
private static final Matcher<ExpressionTree> OPTIONAL_GET_METHOD = Matchers.staticMethod() | ||
.onClass(Optional.class.getName()) | ||
.named("get") |
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.
Probably also want to include orElseThrow
here.
I'm not sure it's worth maintaining a check for this, unless we see failures begin to crop up in practice. I can imagine false positives causing more total friction than a couple failures getting through. It's certainly possible that my estimation is off, though. |
Before this PR
Discussion of #2946 identified potential value in identifying places where
Stream
s ofOptional
s should get if the optional is present before mapping viaOptional::get
.After this PR
==COMMIT_MSG==
Add
StreamOptionalGetWithoutFilter
to identify places whereStream<Optional<?>>
should callfilter(Optional::isPresent)
beforemap(Optional::get)
.Similar to
OptionalNotPresent
but for streams.==COMMIT_MSG==
Possible downsides?