Details
-
Improvement
-
Status: Closed
-
Major
-
Resolution: Fixed
-
API 2.9.0
-
None
Description
While creating ResourceResolver, we have to remember to close it and code looks like that:
ResourceResolver resourceResolver = null; try { resourceResolver = resourceResolverFactory.getServiceResourceResolver(null); } catch (LoginException e) { LOGGER.error("Error during getting instance of ResourceResolver class", e); } finally { if (resourceResolver != null) { resourceResolver.close(); } }
While making ResourceResolver additionally extend Closable (or AutoClosable) interface, we could use try-with-resources Java 7 feature and our code would be more concise, elegant, readable.
try (ResourceResolver resolver = factory.getServiceResourceResolver(null)) { //do sth }
(Please notice that Closable is still part of Java 6 API)
Attachments
Issue Links
- is duplicated by
-
SLING-4798 ResourceResolver should extend java.io.Closeable
- Resolved