You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@sling.apache.org by "Michał Chudy (JIRA)" <ji...@apache.org> on 2015/06/13 16:04:00 UTC

[jira] [Created] (SLING-4805) ResourceResolver should extend Closable interface.

Michał Chudy created SLING-4805:
-----------------------------------

             Summary: ResourceResolver should extend Closable interface.
                 Key: SLING-4805
                 URL: https://issues.apache.org/jira/browse/SLING-4805
             Project: Sling
          Issue Type: Improvement
          Components: API, JCR
    Affects Versions: API 2.9.0, JCR Resource 2.5.0
            Reporter: Michał Chudy


While creating {{ResourceResolver}}, we have to remember to close it and code looks like that:
{code}
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();
	}
}
{code}

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.
{code}
try (ResourceResolver resolver = factory.getServiceResourceResolver(null)) {
	//do sth
}
{code}

(Please notice that {{Closable}} is still part of Java 6 API)



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)