try-with-resources and null resource (original) (raw)

Rémi Forax forax at univ-mlv.fr
Mon Jan 24 15:49:20 PST 2011


On 01/24/2011 11:32 PM, Tim Peierls wrote:

On Mon, Jan 24, 2011 at 3:24 PM, Stephen Colebourne<scolebourne at joda.org>wrote:

The current behaviour isn't too bad, just non-optimal. For a new feature, I'd prefer it was optimal. I don't think we have a consensus on the metric yet. My feeling: The current approach preserves options for everyone. Those who want a null check at resource init time can easily provide one: try (Resource r = checkNotNull(provideInitialResourceValue())) { // body } Those who don't want it don't have it forced on them. If the null check were always performed, I'd have no way to use try-with-resources and get the side-effects of executing the body up to the point where the null Resource is dereferenced.

side-effects => hours of debugging

(Not saying one always wants to do this, or even that one often wants to do this, just that try-with-resources shouldn't prevent it.)

Do you have a use case for that ? And even if you find a twisted use case, do you really think anyone will be able to understand that code ?

--tim

Rémi



More information about the coin-dev mailing list