Uploaded image for project: 'Sling'
  1. Sling
  2. SLING-4805

ResourceResolver should extend Closable interface.

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Closed
    • Major
    • Resolution: Fixed
    • API 2.9.0
    • API 2.11.0
    • API
    • 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

          Activity

            People

              cziegeler Carsten Ziegeler
              mchudy MichaƂ Chudy
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: