Shahar Havivi has uploaded a new change for review. Change subject: findbugs: method may fail to close resource ......................................................................
findbugs: method may fail to close resource OBL: Method may fail to clean up stream or resource on checked exception (OBL_UNSATISFIED_OBLIGATION_EXCEPTION_EDGE) Change-Id: I717fa1ecf687517a0b952d8649e2a0cda7a9fd26 Signed-off-by: Shahar Havivi <[email protected]> --- M backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/kerberos/KrbConfCreator.java M backend/manager/tools/src/main/java/org/ovirt/engine/core/domains/ManageDomains.java M backend/manager/tools/src/main/java/org/ovirt/engine/core/tools/common/db/StandaloneDataSource.java 3 files changed, 33 insertions(+), 17 deletions(-) git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/24/15324/1 diff --git a/backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/kerberos/KrbConfCreator.java b/backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/kerberos/KrbConfCreator.java index 842025d..395061d 100644 --- a/backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/kerberos/KrbConfCreator.java +++ b/backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/kerberos/KrbConfCreator.java @@ -165,10 +165,15 @@ } public void toFile(String krb5ConfPath, StringBuffer sb) throws FileNotFoundException, IOException { - - FileOutputStream fos = new FileOutputStream(krb5ConfPath); - fos.write(sb.toString().getBytes()); - fos.close(); + FileOutputStream fos = null; + try { + fos = new FileOutputStream(krb5ConfPath); + fos.write(sb.toString().getBytes()); + } finally { + if (fos != null) { + fos.close(); + } + } } private String appendRealms(List<String> realms) throws AuthenticationException { diff --git a/backend/manager/tools/src/main/java/org/ovirt/engine/core/domains/ManageDomains.java b/backend/manager/tools/src/main/java/org/ovirt/engine/core/domains/ManageDomains.java index 51f682c..56ef8a5 100644 --- a/backend/manager/tools/src/main/java/org/ovirt/engine/core/domains/ManageDomains.java +++ b/backend/manager/tools/src/main/java/org/ovirt/engine/core/domains/ManageDomains.java @@ -1105,17 +1105,27 @@ } private static void copyFile(String srcFilePath, String dstFilePath) throws IOException { - InputStream in = new FileInputStream(srcFilePath); - OutputStream out = new FileOutputStream(dstFilePath); + InputStream in = null; + OutputStream out = null; - // Transfer bytes from in to out - byte[] buf = new byte[1024]; - int len; - while ((len = in.read(buf)) > 0) { - out.write(buf, 0, len); + try { + in = new FileInputStream(srcFilePath); + out = new FileOutputStream(dstFilePath); + + // Transfer bytes from in to out + byte[] buf = new byte[1024]; + int len; + while ((len = in.read(buf)) > 0) { + out.write(buf, 0, len); + } + } finally { + if (in != null) { + in.close(); + } + if (out != null) { + out.close(); + } } - in.close(); - out.close(); } private static void deleteFile(String filePath) { diff --git a/backend/manager/tools/src/main/java/org/ovirt/engine/core/tools/common/db/StandaloneDataSource.java b/backend/manager/tools/src/main/java/org/ovirt/engine/core/tools/common/db/StandaloneDataSource.java index 2ae6549..4ea1654 100644 --- a/backend/manager/tools/src/main/java/org/ovirt/engine/core/tools/common/db/StandaloneDataSource.java +++ b/backend/manager/tools/src/main/java/org/ovirt/engine/core/tools/common/db/StandaloneDataSource.java @@ -114,13 +114,14 @@ rs.next(); } finally { - if (rs != null) { - rs.close(); - } - + // Statement should be close first if (statement != null) { statement.close(); } + + if (rs != null) { + rs.close(); + } } } -- To view, visit http://gerrit.ovirt.org/15324 To unsubscribe, visit http://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I717fa1ecf687517a0b952d8649e2a0cda7a9fd26 Gerrit-PatchSet: 1 Gerrit-Project: ovirt-engine Gerrit-Branch: master Gerrit-Owner: Shahar Havivi <[email protected]> _______________________________________________ Engine-patches mailing list [email protected] http://lists.ovirt.org/mailman/listinfo/engine-patches
