-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
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
Clean up Optional-related code. #9285
Conversation
fd9a8e6
to
982f6a0
Compare
b0ac2c9
to
4e9ce88
Compare
Yeah, the |
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.
Other simplifications look good to me
final var source = playbackListener.sourceOf(stream, streamInfo); | ||
|
||
return Optional.ofNullable(source) |
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.
And also turn source1
into source
below
final var source = playbackListener.sourceOf(stream, streamInfo); | |
return Optional.ofNullable(source) | |
return Optional.ofNullable(playbackListener.sourceOf(stream, streamInfo)) |
}, () -> { | ||
reloadPlayQueueManager(); | ||
setRecovery(); | ||
}); |
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.
Maybe add a comment in this lambda to make it clear that it is called when we have no current stream info
Oh great! I had gradle out of sync with the ide |
4e9ce88
to
e8216b2
Compare
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 made some small changes, in part described below, in the last commit, to fix some things and make further improvements. Thank you!
.map(item -> item.localConfiguration) | ||
.map(localConfiguration -> localConfiguration.tag) |
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.
map
will crash if the return value of the lambda is null
. I looked it up but there does not seem to be a mapNullable
(just like ofNullable
exists). So I used flatMap(... -> Optional.ofNullable(...))
jshell> Optional.of(new Object()).map(null)
| Exception java.lang.NullPointerException
| at Objects.requireNonNull (Objects.java:233)
| at Optional.map (Optional.java:256)
| at (#2:1)
jshell> Optional.of(new Object()).flatMap(o -> Optional.ofNullable(null))
$4 ==> Optional.empty
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.
null
values returned in the lambda are converted to empty Optional
s in the map
method: https://developer.android.com/reference/java/util/Optional#map(java.util.function.Function%3C?%20super%20T,%20?%20extends%20U%3E)
You passed a null
value for the lambda argument, not as the return type (the correct notation would be item -> null
).
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.
You are right, I feel so stupid now... I will revert that part of my commit
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 pushed ad605e2
|| getRoot().map(View::getParent).orElse(null) == null) { | ||
if (!isPlayerAndPlayerServiceAvailable() || player.UIs().get(MainPlayerUi.class).isEmpty() | ||
|| getRoot().map(View::getParent).isEmpty()) { |
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.
Your code is perfectly equivalent, but I think the .map(View::getParent)
was wrongly being used to allow getParent
to return null
.
Kudos, SonarCloud Quality Gate passed! |
What is it?
Description of the changes in your PR
SimplifyOptionalCallChains
, as theOptional#isEmpty()
method is now available in the Android SDK starting with version 33 and is desugared.Optional
method chaining.Fixes the following issue(s)
APK testing
The APK can be found by going to the "Checks" tab below the title. On the left pane, click on "CI", scroll down to "artifacts" and click "app" to download the zip file which contains the debug APK of this PR.
Due diligence