RFR: 8347491: IllegalArgumentationException thrown by ThreadPoolExecutor doesn't have a useful message

Viktor Klang vklang at openjdk.org
Wed Feb 12 14:09:13 UTC 2025


On Tue, 11 Feb 2025 08:39:51 GMT, Per Minborg <pminborg at openjdk.org> wrote:

>> Motivation:
>> When a user passes a wrong parameter, the current implementation throws an IllegalArgumentException with an error message `null`, which is not helpful.
>> 
>> Modification:
>> Add detail error messages.
>> 
>> Result:
>> Helpful messages.
>
> src/java.base/share/classes/java/util/concurrent/AbstractExecutorService.java line 122:
> 
>> 120:     @Override
>> 121:     public Future<?> submit(Runnable task) {
>> 122:         if (task == null) throw new NullPointerException("task can't be null");
> 
> Why not use `Objects.requireNonNull()` and break out the repeated code into a common method?

I'd prefer `Objects.requireNonNull(task, "task");`

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

PR Review Comment: https://git.openjdk.org/jdk/pull/23050#discussion_r1952715499


More information about the core-libs-dev mailing list