try-with-resources and null resource

Tim Peierls tim at peierls.net
Mon Jan 24 14:32:57 PST 2011


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. (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.)

--tim



More information about the coin-dev mailing list