On 30/04/14 00:41, Stephen Allen wrote:
On Tue, Apr 29, 2014 at 5:43 PM, Andy Seaborne <[email protected]> wrote:

On 29/04/14 20:29, Stephen Allen wrote:

One simple change I would really like to make when we switch to Java 7 is
to make org.apache.jena.atlas.lib.Closeable extend
java.lang.AutoCloseable.
   That way we can take advantage of try-with-resources.


Which classes/patterns in particular did you want autoclosability?
org.apache.jena.atlas.lib.Closeable gets used widely.

oaj.lib.Closeable defines close without a checked exception;
java.lang.AutoCloseable defines close to throw an exception:


I want all of them to implement AutoCloseable.  Then the user can use
try-with-resources on any of our oaj.lib.Closeable classes.  We would have
oaj.lib.Closeable extend java.lang.AutoCloseable and override the close()
method to throw no exception.  That doesn't break any legacy interaction,
but adds the try-with-resources feature if you want it.  See the last
section of [1] that describes this behavior.

I took a look at everything from oaj.lib.Closeable.

It would be helpful on many things (and documentation needs changing for the publicly visible items).

For some things it's not helpful (e.g. TDB Journal) and where we don't require closing (TDB TupleTables - looks more like it simply does not need Closeable as it's meaning less history). Several internal items (e.g. QueryEngineBase) don't need Closeable either. These are no used in the try-with-resources fashion so adding AutoCloseable implies the wrong thing.

An extreme case of DatasetGraph where "close" has specific meaning. This could have Closeable removed.

I got ~30 warnings

Stephen - you have been working on an alternative API - how do you want to advance that?

        Andy


-Stephen

[1]
http://docs.oracle.com/javase/tutorial/essential/exceptions/tryResourceClose.html


Reply via email to