cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aadamc...@apache.org
Subject [1/2] cayenne git commit: try-with-resources
Date Thu, 29 Sep 2016 11:32:26 GMT
Repository: cayenne
Updated Branches:
  refs/heads/master a851b9f44 -> 8c7bec0f4


try-with-resources


Project: http://git-wip-us.apache.org/repos/asf/cayenne/repo
Commit: http://git-wip-us.apache.org/repos/asf/cayenne/commit/76ab7c77
Tree: http://git-wip-us.apache.org/repos/asf/cayenne/tree/76ab7c77
Diff: http://git-wip-us.apache.org/repos/asf/cayenne/diff/76ab7c77

Branch: refs/heads/master
Commit: 76ab7c770112328ca2847ad0cf12a23deccf3daa
Parents: a851b9f
Author: Andrus Adamchik <andrus@objectstyle.com>
Authored: Thu Sep 29 14:30:57 2016 +0300
Committer: Andrus Adamchik <andrus@objectstyle.com>
Committed: Thu Sep 29 14:30:57 2016 +0300

----------------------------------------------------------------------
 .../cayenne/configuration/XMLDataMapLoader.java | 34 ++++----------------
 1 file changed, 6 insertions(+), 28 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cayenne/blob/76ab7c77/cayenne-server/src/main/java/org/apache/cayenne/configuration/XMLDataMapLoader.java
----------------------------------------------------------------------
diff --git a/cayenne-server/src/main/java/org/apache/cayenne/configuration/XMLDataMapLoader.java
b/cayenne-server/src/main/java/org/apache/cayenne/configuration/XMLDataMapLoader.java
index c9cbab1..61e871a 100644
--- a/cayenne-server/src/main/java/org/apache/cayenne/configuration/XMLDataMapLoader.java
+++ b/cayenne-server/src/main/java/org/apache/cayenne/configuration/XMLDataMapLoader.java
@@ -18,10 +18,6 @@
  ****************************************************************/
 package org.apache.cayenne.configuration;
 
-import java.io.IOException;
-import java.io.InputStream;
-import java.net.URL;
-
 import org.apache.cayenne.CayenneRuntimeException;
 import org.apache.cayenne.map.DataMap;
 import org.apache.cayenne.map.MapLoader;
@@ -30,6 +26,9 @@ import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.xml.sax.InputSource;
 
+import java.io.InputStream;
+import java.net.URL;
+
 /**
  * @since 3.1
  */
@@ -46,34 +45,13 @@ public class XMLDataMapLoader implements DataMapLoader {
         MapLoader mapLoader = new MapLoader();
         URL url = configurationResource.getURL();
 
-        InputStream in = null;
-
-        DataMap map;
-
-        try {
-            in = url.openStream();
-
-            map = mapLoader.loadDataMap(new InputSource(in));
-        }
-        catch (Exception e) {
+        try (InputStream in = url.openStream()) {
+            return mapLoader.loadDataMap(new InputSource(in));
+        } catch (Exception e) {
             throw new CayenneRuntimeException(
                     "Error loading configuration from %s",
                     e,
                     url);
         }
-        finally {
-            try {
-                if (in != null) {
-                    in.close();
-                }
-            }
-            catch (IOException ioex) {
-                logger.info(
-                        "failure closing input stream for " + url + ", ignoring",
-                        ioex);
-            }
-        }
-
-        return map;
     }
 }


Mime
View raw message