Open cpovirk opened 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.
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.
As #3566 points out,
ThreadFactoryBuilder.newThread
is permitted to returnnull
(and classes likeThreadPoolExecutor
are resilient to this).Our
ThreadFactoryBuilder
callsnewThread
and returns it directly or, if the user has requested particular settings on the thread (like a name or priority), it first calls methods likesetName
on it.There are a few directions we could go:
ThreadFactoryBuilder
no longer permit backing factories that returnnull
: Make itsnewThread
method callverifyNotNull
on the backing factory's returned thread, and document the new input requirement and output guarantee.ThreadFactoryBuilder
resilient to backing factories that returnnull
: Skip calls likesetName
if the backing factory returnsnull
, and document that ournewThread
method can returnnull
. (This is a behavior change, but it's probably a good one: OurnewThread
method can already sometimes returnnull
, so this change just makes it do that more often, rather than throwNullPointerException
.)null
as long as no settings are requested on it -- in other words, then there was probably no reason to useThreadFactoryBuilder
in the first place :)