google / guava

Google core libraries for Java
Apache License 2.0
50.19k stars 10.91k forks source link

Behavior of ThreadFactoryBuilder is unclear if backing factory returns null #3568

Open cpovirk opened 5 years ago

cpovirk commented 5 years ago

As #3566 points out, ThreadFactoryBuilder.newThread is permitted to return null (and classes like ThreadPoolExecutor are resilient to this).

Our ThreadFactoryBuilder calls newThread and returns it directly or, if the user has requested particular settings on the thread (like a name or priority), it first calls methods like setName on it.

There are a few directions we could go:

v-aksenov commented 5 years ago

I think, that method called "newTread" should return new thread. It seems logicaly. And if method cannot create new Thread and return it, then input parameters are wrong. So in this case I agree with your first way - add verifyNotNull verification before creating thread process. If you do not mind, I would like to take this task.

cpovirk commented 5 years ago

If only Java had written the contract that way, this would be a much easier decision :( Given that newThread is documented to be able to return null, the decision is much trickier. My guess is that we'll never get around to investigating which way to go on this. Thanks for the offer, though.