Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1256,13 +1256,17 @@ public ThreadPoolExecutor(int corePoolSize,
BlockingQueue<Runnable> workQueue,
ThreadFactory threadFactory,
RejectedExecutionHandler handler) {
if (corePoolSize < 0 ||
maximumPoolSize <= 0 ||
maximumPoolSize < corePoolSize ||
keepAliveTime < 0)
throw new IllegalArgumentException();
if (workQueue == null || threadFactory == null || handler == null)
throw new NullPointerException();
if (corePoolSize < 0)
throw new IllegalArgumentException("corePoolSize must be non-negative");
if (maximumPoolSize <= 0 || maximumPoolSize < corePoolSize)
throw new IllegalArgumentException("maximumPoolSize must be positive and greater-or-equal to corePoolSize");
if (keepAliveTime < 0)
throw new IllegalArgumentException("keepAliveTime must not be negative");

Objects.requireNonNull(workQueue, "workQueue");
Objects.requireNonNull(threadFactory, "threadFactory");
Objects.requireNonNull(handler, "handler");

this.corePoolSize = corePoolSize;
this.maximumPoolSize = maximumPoolSize;
this.workQueue = workQueue;
Expand All @@ -1289,8 +1293,7 @@ public ThreadPoolExecutor(int corePoolSize,
* @throws NullPointerException if {@code command} is null
*/
public void execute(Runnable command) {
if (command == null)
throw new NullPointerException();
Objects.requireNonNull(command, "command");
/*
* Proceed in 3 steps:
*
Expand Down Expand Up @@ -1451,9 +1454,7 @@ protected void finalize() {}
* @see #getThreadFactory
*/
public void setThreadFactory(ThreadFactory threadFactory) {
if (threadFactory == null)
throw new NullPointerException();
this.threadFactory = threadFactory;
this.threadFactory = Objects.requireNonNull(threadFactory, "threadFactory");
}

/**
Expand All @@ -1474,9 +1475,7 @@ public ThreadFactory getThreadFactory() {
* @see #getRejectedExecutionHandler
*/
public void setRejectedExecutionHandler(RejectedExecutionHandler handler) {
if (handler == null)
throw new NullPointerException();
this.handler = handler;
this.handler = Objects.requireNonNull(handler, "handler");
}

/**
Expand All @@ -1503,8 +1502,10 @@ public RejectedExecutionHandler getRejectedExecutionHandler() {
* @see #getCorePoolSize
*/
public void setCorePoolSize(int corePoolSize) {
if (corePoolSize < 0 || maximumPoolSize < corePoolSize)
throw new IllegalArgumentException();
if (corePoolSize < 0)
throw new IllegalArgumentException("corePoolSize must be non-negative");
if (maximumPoolSize < corePoolSize)
throw new IllegalArgumentException("corePoolSize must be lesser-or-equal to maximumPoolSize");
int delta = corePoolSize - this.corePoolSize;
this.corePoolSize = corePoolSize;
if (workerCountOf(ctl.get()) > corePoolSize)
Expand Down Expand Up @@ -1629,7 +1630,7 @@ public void allowCoreThreadTimeOut(boolean value) {
*/
public void setMaximumPoolSize(int maximumPoolSize) {
if (maximumPoolSize <= 0 || maximumPoolSize < corePoolSize)
throw new IllegalArgumentException();
throw new IllegalArgumentException("maximumPoolSize must be positive and greater-or-equal to corePoolSize");
this.maximumPoolSize = maximumPoolSize;
if (workerCountOf(ctl.get()) > maximumPoolSize)
interruptIdleWorkers();
Expand Down Expand Up @@ -1663,7 +1664,7 @@ public int getMaximumPoolSize() {
*/
public void setKeepAliveTime(long time, TimeUnit unit) {
if (time < 0)
throw new IllegalArgumentException();
throw new IllegalArgumentException("time must be non-negative");
if (time == 0 && allowsCoreThreadTimeOut())
throw new IllegalArgumentException("Core threads must have nonzero keep alive times");
long keepAliveTime = unit.toNanos(time);
Expand Down