You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tamaya.apache.org by ac...@apache.org on 2019/05/01 14:25:40 UTC

[incubator-tamaya] branch try_with_resource created (now b6e7901)

This is an automated email from the ASF dual-hosted git repository.

acoburn pushed a change to branch try_with_resource
in repository https://gitbox.apache.org/repos/asf/incubator-tamaya.git.


      at b6e7901  LHF: use try-with-resources with BufferedReader

This branch includes the following new commits:

     new b6e7901  LHF: use try-with-resources with BufferedReader

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.



[incubator-tamaya] 01/01: LHF: use try-with-resources with BufferedReader

Posted by ac...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

acoburn pushed a commit to branch try_with_resource
in repository https://gitbox.apache.org/repos/asf/incubator-tamaya.git

commit b6e7901bf97280fe46849327abf2ff9003db84bc
Author: Aaron Coburn <ac...@apache.org>
AuthorDate: Wed May 1 10:22:21 2019 -0400

    LHF: use try-with-resources with BufferedReader
    
    This opens a BufferedReader in a try-with-resources block to ensure that
    the resource is properly closed in the event of an exception.
---
 .../tamaya/core/internal/OSGIServiceLoader.java    | 58 +++++++++++-----------
 1 file changed, 29 insertions(+), 29 deletions(-)

diff --git a/code/core/src/main/java/org/apache/tamaya/core/internal/OSGIServiceLoader.java b/code/core/src/main/java/org/apache/tamaya/core/internal/OSGIServiceLoader.java
index 0efe5b0..8ca0065 100644
--- a/code/core/src/main/java/org/apache/tamaya/core/internal/OSGIServiceLoader.java
+++ b/code/core/src/main/java/org/apache/tamaya/core/internal/OSGIServiceLoader.java
@@ -192,39 +192,39 @@ public class OSGIServiceLoader implements BundleListener {
             URL child = bundle.getEntry(entryPath);
             InputStream inStream = child.openStream();
 
-            BufferedReader br = new BufferedReader(new InputStreamReader(inStream, "UTF-8"));
-            String implClassName = br.readLine();
-            while (implClassName != null) {
-                int hashIndex = implClassName.indexOf("#");
-                if (hashIndex > 0) {
-                    implClassName = implClassName.substring(0, hashIndex - 1);
-                } else if (hashIndex == 0) {
-                    implClassName = "";
-                }
-                implClassName = implClassName.trim();
-                if (implClassName.length() > 0) {
-                    LOG.fine("Unloading Service (" + serviceName + "): " + implClassName);
-                    try {
-                        // Load the service class
-                        Class<?> implClass = bundle.loadClass(implClassName);
-                        if (!serviceClass.isAssignableFrom(implClass)) {
-                            LOG.warning("Configured service: " + implClassName + " is not assignable to "
-                                    + serviceClass.getName());
-                            continue;
-                        }
-                        ServiceReference<?> ref = bundle.getBundleContext().getServiceReference(implClass);
-                        if (ref != null) {
-                            bundle.getBundleContext().ungetService(ref);
+            try (BufferedReader br = new BufferedReader(new InputStreamReader(inStream, "UTF-8"))) {
+                String implClassName = br.readLine();
+                while (implClassName != null) {
+                    int hashIndex = implClassName.indexOf("#");
+                    if (hashIndex > 0) {
+                        implClassName = implClassName.substring(0, hashIndex - 1);
+                    } else if (hashIndex == 0) {
+                        implClassName = "";
+                    }
+                    implClassName = implClassName.trim();
+                    if (implClassName.length() > 0) {
+                        LOG.fine("Unloading Service (" + serviceName + "): " + implClassName);
+                        try {
+                            // Load the service class
+                            Class<?> implClass = bundle.loadClass(implClassName);
+                            if (!serviceClass.isAssignableFrom(implClass)) {
+                                LOG.warning("Configured service: " + implClassName + " is not assignable to "
+                                        + serviceClass.getName());
+                                continue;
+                            }
+                            ServiceReference<?> ref = bundle.getBundleContext().getServiceReference(implClass);
+                            if (ref != null) {
+                                bundle.getBundleContext().ungetService(ref);
+                            }
+                        } catch (Exception e) {
+                            LOG.log(Level.SEVERE, "Failed to unload service: " + implClassName, e);
+                        } catch (NoClassDefFoundError err) {
+                            LOG.log(Level.SEVERE, "Failed to unload service: " + implClassName, err);
                         }
-                    } catch (Exception e) {
-                        LOG.log(Level.SEVERE, "Failed to unload service: " + implClassName, e);
-                    } catch (NoClassDefFoundError err) {
-                        LOG.log(Level.SEVERE, "Failed to unload service: " + implClassName, err);
                     }
+                    implClassName = br.readLine();
                 }
-                implClassName = br.readLine();
             }
-            br.close();
         } catch (RuntimeException rte) {
             throw rte;
         } catch (Exception e) {