You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@servicecomb.apache.org by GitBox <gi...@apache.org> on 2020/12/05 02:43:51 UTC

[GitHub] [servicecomb-java-chassis] wujimin commented on a change in pull request #2103: [SCB-2145]fix local yaml unsafe parse problem

wujimin commented on a change in pull request #2103:
URL: https://github.com/apache/servicecomb-java-chassis/pull/2103#discussion_r536487595



##########
File path: service-registry/registry-local/src/main/java/org/apache/servicecomb/localregistry/LocalRegistryStore.java
##########
@@ -111,37 +111,38 @@ public MicroserviceInstance getSelfMicroserviceInstance() {
   private List<RegistryBean> loadYamlBeans() {
     List<RegistryBean> beans = new ArrayList<>();
 
-    InputStream is = null;
-
     try {
       ClassLoader loader = JvmUtils.findClassLoader();
       Enumeration<URL> urls = loader.getResources(REGISTRY_FILE_NAME);
+
       while (urls.hasMoreElements()) {
         URL url = urls.nextElement();
-        is = url.openStream();
-        if (is != null) {
-          beans.addAll(initFromData(is));
+
+        InputStream is = null;
+        try {
+          is = url.openStream();
+          if (is != null) {
+            beans.addAll(initFromData(is));
+          }
+        } finally {
+          if (is != null) {
+            try {
+              is.close();
+            } catch (IOException e) {
+              // nothing to do
+            }
+          }

Review comment:
       ```java
     try (InputStream is = url.openStream()) {
       if (is != null) {
         beans.addAll(initFromData(is));
       }
     }
   ```




----------------------------------------------------------------
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