On Wed, 8 May 2024 16:06:29 GMT, Stuart Marks <sma...@openjdk.org> wrote:

> Most of these are defined in terms of `String.valueOf(Object)` which if 
> passed a null reference will return the String object containing `null`. So 
> no, I don't think NPE should be thrown. It might be worth mentioning this 
> explicitly somewhere though.

Right, in our current model, `Console.readln(prompt)` can be reduced to 
`Console.print(prompt)` followed by actual reading. `Console.print(prompt)` can 
in turn be reduced to printing the result of `String.valueOf((Object) prompt)`, 
which is a string "null".

The above reduction means that `Console.readln(null)` will not throw NPE. Now, 
what I'm asking if that's what we really want.

With `Console.println(null)` and `Console.print(null)` not throwing NPE makes 
sense. However, with `Console.readln(null)` it might not. After all, we ask for 
a **`String`** prompt, not an `Object` prompt. All other methods of `Console` 
that accept `String`, throw NPE if that string is null.

One more consideration. Whatever the behaviour we choose for 
`Console.readln(null)`, we should choose the same behaviour for 
`IO.readln(null)`. Otherwise, it would be a constant source of unpleasantly 
surprising inconsistency.

Thoughts?

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

PR Review Comment: https://git.openjdk.org/jdk/pull/19112#discussion_r1594464589

Reply via email to