commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ggreg...@apache.org
Subject commons-dbutils git commit: [DBUTILS-139] Update Java requirement from version 6 to 7. Use try-with-resources.
Date Fri, 04 May 2018 20:24:28 GMT
Repository: commons-dbutils
Updated Branches:
  refs/heads/master 91ebf9901 -> 298f30f93


[DBUTILS-139] Update Java requirement from version 6 to 7. Use
try-with-resources.

Project: http://git-wip-us.apache.org/repos/asf/commons-dbutils/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-dbutils/commit/298f30f9
Tree: http://git-wip-us.apache.org/repos/asf/commons-dbutils/tree/298f30f9
Diff: http://git-wip-us.apache.org/repos/asf/commons-dbutils/diff/298f30f9

Branch: refs/heads/master
Commit: 298f30f93910d213abdaa8022ea92506efa0c9f2
Parents: 91ebf99
Author: Gary Gregory <garydgregory@gmail.com>
Authored: Fri May 4 14:24:26 2018 -0600
Committer: Gary Gregory <garydgregory@gmail.com>
Committed: Fri May 4 14:24:26 2018 -0600

----------------------------------------------------------------------
 .../commons/dbutils/AbstractQueryRunner.java       |  2 ++
 .../org/apache/commons/dbutils/QueryLoader.java    | 17 +++++++----------
 2 files changed, 9 insertions(+), 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/commons-dbutils/blob/298f30f9/src/main/java/org/apache/commons/dbutils/AbstractQueryRunner.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/dbutils/AbstractQueryRunner.java b/src/main/java/org/apache/commons/dbutils/AbstractQueryRunner.java
index 472ed32..d89cee1 100644
--- a/src/main/java/org/apache/commons/dbutils/AbstractQueryRunner.java
+++ b/src/main/java/org/apache/commons/dbutils/AbstractQueryRunner.java
@@ -516,6 +516,7 @@ public abstract class AbstractQueryRunner {
     protected PreparedStatement prepareStatement(Connection conn, String sql)
             throws SQLException {
 
+        @SuppressWarnings("resource")
         PreparedStatement ps = conn.prepareStatement(sql);
         try {
             configureStatement(ps);
@@ -552,6 +553,7 @@ public abstract class AbstractQueryRunner {
     protected PreparedStatement prepareStatement(Connection conn, String sql, int returnedKeys)
             throws SQLException {
 
+        @SuppressWarnings("resource")
         PreparedStatement ps = conn.prepareStatement(sql, returnedKeys);
         try {
             configureStatement(ps);

http://git-wip-us.apache.org/repos/asf/commons-dbutils/blob/298f30f9/src/main/java/org/apache/commons/dbutils/QueryLoader.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/dbutils/QueryLoader.java b/src/main/java/org/apache/commons/dbutils/QueryLoader.java
index ac43251..26881ef 100644
--- a/src/main/java/org/apache/commons/dbutils/QueryLoader.java
+++ b/src/main/java/org/apache/commons/dbutils/QueryLoader.java
@@ -110,26 +110,23 @@ public class QueryLoader {
      */
     protected Map<String, String> loadQueries(String path) throws IOException {
         // Findbugs flags getClass().getResource as a bad practice; maybe we should change
the API?
-        InputStream in = getClass().getResourceAsStream(path);
+        final Properties props;
+        try (InputStream in = getClass().getResourceAsStream(path)) {
 
-        if (in == null) {
-            throw new IllegalArgumentException(path + " not found.");
-        }
-
-        Properties props = new Properties();
-        try {
+            if (in == null) {
+                throw new IllegalArgumentException(path + " not found.");
+            }
+            props = new Properties();
             if (dotXml.matcher(path).matches()) {
                 props.loadFromXML(in);
             } else {
                 props.load(in);
             }
-        } finally {
-            in.close();
         }
 
         // Copy to HashMap for better performance
 
-        @SuppressWarnings({ "rawtypes", "unchecked" }) // load() always creates <String,String>
entries
+        @SuppressWarnings({"rawtypes", "unchecked" }) // load() always creates <String,String>
entries
         HashMap<String, String> hashMap = new HashMap(props);
         return hashMap;
     }


Mime
View raw message