On Thu, 6 Mar 2025 12:38:01 GMT, Jaikiran Pai <j...@openjdk.org> wrote:

>> We have helpful NPE messages now - they are more user-friendly.
>> And shorter methods are more likely to be inlined.
>
> src/java.base/share/classes/java/lang/String.java line 3649:
> 
>> 3647:             Iterable<? extends CharSequence> elements) {
>> 3648:         Objects.requireNonNull(delimiter);
>> 3649:         Objects.requireNonNull(elements);
> 
> Hello Andrey, I have a different opinion about this. I think removing 
> existing calls to `Objects.requireNonNull()` in favour of implicit null check 
> (some times too far away in the code) isn't useful. 
> 
> You noted that the implicit `NullPointerException` stacktrace are more user 
> friendly now. I think you can get similar level of useful information from 
> `Objects.requireNonNull()` too. In these two specific cases, what you could 
> perhaps do is change those calls to even pass the `message` so that it's 
> clear what parameter is `null`. Something like:
> 
>     Objects.requireNonNull(delimiter, "delimiter");
>     Objects.requireNonNull(elements, "elements");

Should we add it to other overloads of `join` then?

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

PR Review Comment: https://git.openjdk.org/jdk/pull/23710#discussion_r1983977821

Reply via email to