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 17:34:00 UTC

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

    [ https://issues.apache.org/jira/browse/SLING-4805?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14584663#comment-14584663 ] 

Michał Chudy commented on SLING-4805:
-------------------------------------

:-) What a timing! Thanks!

> ResourceResolver should extend Closable interface.
> --------------------------------------------------
>
>                 Key: SLING-4805
>                 URL: https://issues.apache.org/jira/browse/SLING-4805
>             Project: Sling
>          Issue Type: Improvement
>          Components: API
>    Affects Versions: API 2.9.0
>            Reporter: Michał Chudy
>            Assignee: Carsten Ziegeler
>             Fix For: API 2.10.0
>
>
> 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)