Skip to content

Commit

Permalink
9077998: Add detail error messages when ThreadPoolExecutor's paramete…
Browse files Browse the repository at this point in the history
…r is illegal.
  • Loading branch information
He-Pin committed Jan 11, 2025
1 parent 3145278 commit fb67983
Showing 1 changed file with 20 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1256,11 +1256,15 @@ public ThreadPoolExecutor(int corePoolSize,
BlockingQueue<Runnable> workQueue,
ThreadFactory threadFactory,
RejectedExecutionHandler handler) {
if (corePoolSize < 0 ||
maximumPoolSize <= 0 ||
maximumPoolSize < corePoolSize ||
keepAliveTime < 0)
throw new IllegalArgumentException();
if (corePoolSize < 0) {
throw new IllegalArgumentException("corePoolSize < 0");
} else if (maximumPoolSize <= 0) {
throw new IllegalArgumentException("maximumPoolSize <= 0");
} else if (maximumPoolSize < corePoolSize) {
throw new IllegalArgumentException("maximumPoolSize < corePoolSize");
} else if (keepAliveTime < 0) {
throw new IllegalArgumentException("keepAliveTime < 0");
}
if (workQueue == null || threadFactory == null || handler == null)
throw new NullPointerException();
this.corePoolSize = corePoolSize;
Expand Down Expand Up @@ -1503,8 +1507,11 @@ 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 < 0");
} else if (corePoolSize > maximumPoolSize) {
throw new IllegalArgumentException("corePoolSize > maximumPoolSize");
}
int delta = corePoolSize - this.corePoolSize;
this.corePoolSize = corePoolSize;
if (workerCountOf(ctl.get()) > corePoolSize)
Expand Down Expand Up @@ -1628,8 +1635,11 @@ public void allowCoreThreadTimeOut(boolean value) {
* @see #getMaximumPoolSize
*/
public void setMaximumPoolSize(int maximumPoolSize) {
if (maximumPoolSize <= 0 || maximumPoolSize < corePoolSize)
throw new IllegalArgumentException();
if (maximumPoolSize <= 0) {
throw new IllegalArgumentException("maximumPoolSize <= 0");
} else if (maximumPoolSize < corePoolSize) {
throw new IllegalArgumentException("maximumPoolSize < corePoolSize");
}
this.maximumPoolSize = maximumPoolSize;
if (workerCountOf(ctl.get()) > maximumPoolSize)
interruptIdleWorkers();
Expand Down Expand Up @@ -1663,7 +1673,7 @@ public int getMaximumPoolSize() {
*/
public void setKeepAliveTime(long time, TimeUnit unit) {
if (time < 0)
throw new IllegalArgumentException();
throw new IllegalArgumentException("time < 0");
if (time == 0 && allowsCoreThreadTimeOut())
throw new IllegalArgumentException("Core threads must have nonzero keep alive times");
long keepAliveTime = unit.toNanos(time);
Expand Down

0 comments on commit fb67983

Please sign in to comment.