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

Viktor Klang vklang at openjdk.org
Wed Feb 12 14:19:18 UTC 2025


On Sat, 11 Jan 2025 07:10:53 GMT, He-Pin(kerr) <duke 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/ThreadPoolExecutor.java line 1264:

> 1262:             throw new IllegalArgumentException("maximumPoolSize must be positive, but got " + maximumPoolSize);
> 1263:         } else if (maximumPoolSize < corePoolSize) {
> 1264:             throw new IllegalArgumentException("maximumPoolSize must >= corePoolSize , " + "but got maximumPoolSize:" + maximumPoolSize + " corePoolSize :" + corePoolSize);

Too many different formulations of messages for me ("can't" vs "must be" vs "must >=")

I'd recommend using "must be" as in "must be non-negative", "must be positive", "must be greater-or-equal to"

test/jdk/java/util/concurrent/tck/ThreadPoolExecutorTest.java line 309:

> 307:                 shouldThrow();
> 308:             } catch (NullPointerException success) {
> 309:                 Assert.assertNotNull(success.getMessage());

Should assert the expected message.

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

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


More information about the core-libs-dev mailing list