tamaya-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From GitBox <...@apache.org>
Subject [GitHub] [incubator-tamaya] ottlinger commented on a change in pull request #49: TAMAYA-277: LHF: use try-with-resources with BufferedReader
Date Wed, 01 May 2019 20:15:53 GMT
ottlinger commented on a change in pull request #49: TAMAYA-277: LHF: use try-with-resources
with BufferedReader
URL: https://github.com/apache/incubator-tamaya/pull/49#discussion_r280159576
 
 

 ##########
 File path: code/core/src/main/java/org/apache/tamaya/core/internal/OSGIServiceLoader.java
 ##########
 @@ -192,39 +192,39 @@ private void removeEntryPath(Bundle bundle, String entryPath) {
             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) {
 
 Review comment:
   @acoburn can we use a multicatch here?
   `catch(NCDFE | Exception e)`
   as the handling is the same
   
   Interestingly the quality build breaks due to the reformat .....

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

Mime
View raw message