On Tue, 5 Jun 2018 at 00:25, Ben Caradoc-Davies <b...@transient.nz> wrote:
> Many interfaces in GeoTools and GeoServer use the Dispose pattern, often
> with a dispose() method, but do not implement AutoCloseable, preventing
> their use in a try-with-resources statement. Examples range from
> ImageReader to DataStore/DataAccess. Some interfaces like FeatureReader
> already implement Closeable and thus AutoCloseable, but many do not.
>
> Java 7 try-with-resources improves code quality because it simplifies
> code by automating common boilerplate:
>
> https://docs.oracle.com/javase/tutorial/essential/exceptions/tryResourceClose.html
> https://docs.oracle.com/javase/8/docs/api/java/lang/AutoCloseable.html
>
> Adding AutoCloseable to an interface is an API-breaking change because
> third-party subclasses that do not implement a close() method will no
> longer compile. Any change would be applied only to master and would
> target GeoTools 20.0 and GeoServer 2.14.0.
>
+1 for this anything that improves clean up and saves me writing code is
good!
>
> - Should we add AutoCloseable to interfaces, and if so which ones? We
> could make a list.
>
This is an obvious first step, is there an easy way to do it? grep for
dispose?
>
> - Do we make the change one interface at a time or try to do them all at
> once?
>
>
I would go for one at a time, working from a list. My feeling is that doing
one is something I could work on while waiting for something else to
complete, whereas doing all of them is going to be a weekend or more and
harder to share the work out.
> - Should we rename dispose() to close() in implementers and add a
> deprecated dispose() that wraps close(), or just add a close() that
> wraps dispose()?
>
I'd favour deprecating a dispose() that wraps close() - makes it clearer
what we intend.
>
> - As we are breaking the API anyway, should we get rid of dispose()
> entirely by renaming it to close() without adding a deprecated wrapper?
>
>
That is harder for downstream users to handle IMHO.
> - I thought of updating only interfaces and overrides. A more ambitious
> scope would find every deprecated dispose() and refactor to use
> try-with-resources. The alternative is to refactor incrementally over
> time. How do we wish to pay off our technical debt?
>
>
I would prefer to fight the debt as we go and find all the deprecated
disposes in our code as we go.
> - Who is interested in participating in this work?
>
>
I'd be up to do some of it.
Ian
------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Geoserver-devel mailing list
Geoserver-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/geoserver-devel