tamaya-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From acob...@apache.org
Subject [incubator-tamaya] 01/01: LHF: use try-with-resources with BufferedReader
Date Wed, 01 May 2019 14:25:41 GMT
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 <acoburn@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) {


Mime
View raw message