On Wed, 14 May 2025 12:09:16 GMT, Alexey Ivanov <aiva...@openjdk.org> wrote:

>> 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.

I respectfully disagree for a few reasons:

>  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.)

Implementation and documentation of Objects.requireNonNull including its use in 
our codebase and in newly added code suggests that it is intended for 
validating parameters before dereferencing them. This contradicts the strict 
separation you're implying.

Additionally as I mentioned earlier the javax.sound.** code already uses npe 
for null parameter checks. Introducing a mix of exception styles would reduce 
consistency.

-------------

PR Review Comment: https://git.openjdk.org/jdk/pull/24991#discussion_r2089520351

Reply via email to