RFR: 8301604: Replace Collections.unmodifiableList with List.of
Nir Lisker
nlisker at openjdk.org
Wed Feb 1 23:08:34 UTC 2023
On Wed, 1 Feb 2023 16:54:30 GMT, John Hendrikx <jhendrikx at openjdk.org> wrote:
>> modules/javafx.media/src/main/java/com/sun/media/jfxmedia/Media.java line 103:
>>
>>> 101: }
>>> 102: }
>>> 103: return returnValue;
>>
>> This method can be reduced to
>>
>> public List<Track> getTracks() {
>> synchronized (tracks) {
>> return tracks.isEmpty() ? null : List.copyOf(tracks);
>> }
>> }
>>
>> though I find it highly questionable that it returns `null` for an empty list instead of just an empty list. There are 2 use cases of this method and both would do better with just an empty list.
>
> Yeah, I noticed this as well right away, it is documented to do this though. The documentation however does seem to suggest it might be possible that there are three results:
>
> 1. Tracks haven't been scanned yet -> `null`
> 2. Tracks have been scanned, but none where found -> empty list
> 3. Tracks have been scanned and some were found -> list
>
> Whether case 2 can ever happen is unclear, but distinguishing it from the case where nothing has been scanned yet with `null` does not seem unreasonable.
It's an internal class and no calling class makes this distinction. I don't think it's meant to function in the way you described.
-------------
PR: https://git.openjdk.org/jfx/pull/1012
More information about the openjfx-dev
mailing list