RFR: 8356049: Need a simple way to play back a sound clip [v5]
Alexey Ivanov
aivanov at openjdk.org
Wed May 14 12:11:59 UTC 2025
On Wed, 14 May 2025 03:46:37 GMT, Sergey Bylokhov <serb at openjdk.org> wrote:
>> src/java.desktop/share/classes/javax/sound/SoundClip.java line 63:
>>
>>> 61: public static SoundClip createSoundClip(File file) throws IOException {
>>> 62: if (file == null) {
>>> 63: throw new IllegalArgumentException("file must not be null");
>>
>> Most of the APIs in javax.sound.* throw NullPointerException for null arguments and IllegalArgumentException for other invalid parameters.
>
> it is even noticed for both subpackages, it is better to use NPE here as well:
>
> * Please note: In the {@code javax.sound.sampled.spi} APIs, a {@code null}
> * reference parameter to methods is incorrect unless explicitly documented on
> * the method as having a meaningful interpretation. Usage to the contrary is
> * incorrect coding and may result in a run time exception either immediately or
> * at some later time. {@code NullPointerException} is an example of typical and
> * acceptable run time exception for such cases.
I still think `IllegalArgumentException` is better and clearer if we check the value of the parameter before proceeding to doing anything with the parameter and bail out if the parameter has an invalid value.
`NullPointerException`, on the other hand, indicates the code accessed an object but the reference was `null`. (This could occur, for example, if parameters aren't validated.)
Although both exception indicate a coding error, they have different semantics.
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/24991#discussion_r2088789154
More information about the client-libs-dev
mailing list