From 1cac3f646ffa5aad02d86b872d5fd6df97259f0f Mon Sep 17 00:00:00 2001 From: hieplq Date: Sat, 4 Apr 2015 13:37:51 +0700 Subject: [PATCH] IDEMPIERE-2544:to more warning compiler hidden good warning leak resource --- .../compiere/process/ReplicationLocal.java | 3 +- .../impexp/OFXFileBankStatementLoader.java | 8 +++ .../src/org/compiere/print/ReportEngine.java | 2 + .../compiere/process/FactReconciliation.java | 42 +++++++-------- .../src/org/compiere/tools/Strip.java | 53 ++++++++----------- .../src/org/adempiere/pipo2/PackIn.java | 29 +++++----- .../webui/panel/action/CSVImportAction.java | 21 ++++++-- 7 files changed, 86 insertions(+), 72 deletions(-) diff --git a/org.adempiere.base.process/src/org/compiere/process/ReplicationLocal.java b/org.adempiere.base.process/src/org/compiere/process/ReplicationLocal.java index eadb2aff64..7e76fa705e 100644 --- a/org.adempiere.base.process/src/org/compiere/process/ReplicationLocal.java +++ b/org.adempiere.base.process/src/org/compiere/process/ReplicationLocal.java @@ -353,8 +353,9 @@ public class ReplicationLocal extends SvrProcess // no keys - search for parents if (list.size() == 0) { - DB.close(rs); + DB.close(rs, pstmt); rs = null; + pstmt = null; sql = "SELECT ColumnName FROM AD_Column " + "WHERE AD_Table_ID=?" + " AND IsParent='Y'"; diff --git a/org.adempiere.base/src/org/compiere/impexp/OFXFileBankStatementLoader.java b/org.adempiere.base/src/org/compiere/impexp/OFXFileBankStatementLoader.java index bc444d6d98..7f2b1aedf4 100644 --- a/org.adempiere.base/src/org/compiere/impexp/OFXFileBankStatementLoader.java +++ b/org.adempiere.base/src/org/compiere/impexp/OFXFileBankStatementLoader.java @@ -17,6 +17,7 @@ package org.compiere.impexp; import java.io.FileInputStream; +import java.io.IOException; import org.compiere.model.MBankStatementLoader; import org.xml.sax.SAXException; @@ -71,6 +72,13 @@ public final class OFXFileBankStatementLoader extends OFXBankStatementHandler im { m_errorMessage = new StringBuffer("ErrorReadingData"); m_errorDescription = new StringBuffer(); + }finally{ + if (m_stream != null) + try { + m_stream.close(); + } catch (IOException e) { + e.printStackTrace(); + } } return result; diff --git a/org.adempiere.base/src/org/compiere/print/ReportEngine.java b/org.adempiere.base/src/org/compiere/print/ReportEngine.java index 4599ebeaf7..6dd25c27be 100644 --- a/org.adempiere.base/src/org/compiere/print/ReportEngine.java +++ b/org.adempiere.base/src/org/compiere/print/ReportEngine.java @@ -1625,6 +1625,8 @@ queued-job-count = 0 (class javax.print.attribute.standard.QueuedJobCount) .append("FROM C_DocType dt, C_Order o ") .append("WHERE o.C_DocTypeTarget_ID=dt.C_DocType_ID") .append(" AND o.C_Order_ID=?"); + DB.close(rs, pstmt); + rs = null; pstmt = null; pstmt = DB.prepareStatement(sql.toString(), null); pstmt.setInt(1, C_Order_ID); rs = pstmt.executeQuery(); diff --git a/org.adempiere.base/src/org/compiere/process/FactReconciliation.java b/org.adempiere.base/src/org/compiere/process/FactReconciliation.java index f465ec7013..9e28d559c6 100644 --- a/org.adempiere.base/src/org/compiere/process/FactReconciliation.java +++ b/org.adempiere.base/src/org/compiere/process/FactReconciliation.java @@ -2,7 +2,6 @@ package org.compiere.process; import java.math.BigDecimal; import java.sql.PreparedStatement; -import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Timestamp; import java.util.logging.Level; @@ -51,9 +50,7 @@ public class FactReconciliation extends SvrProcess */ protected String doIt() { - PreparedStatement pstmt = null; - ResultSet rs = null; String sql = "INSERT into T_Reconciliation " + "(AD_Client_ID, AD_Org_ID, Created, CreatedBy, Updated, UpdatedBy, " + @@ -69,8 +66,6 @@ public class FactReconciliation extends SvrProcess try { - - pstmt = DB.prepareStatement(sql, get_TrxName()); pstmt.setInt(1, getAD_PInstance_ID()); pstmt.setInt(2, p_Account_ID); @@ -88,25 +83,26 @@ public class FactReconciliation extends SvrProcess " AND r.AD_PInstance_ID = t.AD_PInstance_ID) = 0 " + "AND t.AD_PInstance_ID = ?"; - pstmt = DB.prepareStatement(sql, get_TrxName()); - pstmt.setInt(1, getAD_PInstance_ID()); - count = pstmt.executeUpdate(); - result = Msg.getMsg(getCtx(), "@Deleted@") + ": " + count; + DB.close(pstmt); + pstmt = null; + pstmt = DB.prepareStatement(sql, get_TrxName()); + pstmt.setInt(1, getAD_PInstance_ID()); + count = pstmt.executeUpdate(); + result = Msg.getMsg(getCtx(), "@Deleted@") + ": " + count; + + if (log.isLoggable(Level.FINE))log.log(Level.FINE, result); - if (log.isLoggable(Level.FINE))log.log(Level.FINE, result); - - - } - catch (SQLException e) - { - log.log(Level.SEVERE, sql, e); - return e.getLocalizedMessage(); - } - finally - { - DB.close(rs, pstmt); - rs = null; pstmt = null; - } + } + catch (SQLException e) + { + log.log(Level.SEVERE, sql, e); + return e.getLocalizedMessage(); + } + finally + { + DB.close(pstmt); + pstmt = null; + } if (log.isLoggable(Level.FINE)) log.fine((System.currentTimeMillis() - m_start) + " ms"); return ""; diff --git a/org.adempiere.base/src/org/compiere/tools/Strip.java b/org.adempiere.base/src/org/compiere/tools/Strip.java index e15dcdb932..8449b2abca 100644 --- a/org.adempiere.base/src/org/compiere/tools/Strip.java +++ b/org.adempiere.base/src/org/compiere/tools/Strip.java @@ -18,7 +18,6 @@ package org.compiere.tools; import java.io.File; import java.io.FileInputStream; -import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; @@ -165,32 +164,15 @@ public class Strip private boolean copy (File infile, File outfile) { FileInputStream fis = null; - try - { - fis = new FileInputStream(infile); - } - catch (FileNotFoundException fnfe) - { - System.err.println(fnfe); - return false; - } - // FileOutputStream fos = null; - try - { - fos = new FileOutputStream(outfile, false); // no append - } - catch (FileNotFoundException fnfe) - { - System.err.println(fnfe); - return false; - } - - int noIn = 0; - int noOut = 0; - int noLines = 1; - try - { + try{ + fis = new FileInputStream(infile); + fos = new FileOutputStream(outfile, false); // no append + + int noIn = 0; + int noOut = 0; + int noLines = 1; + int c; while ((c = fis.read()) != -1) { @@ -203,15 +185,24 @@ public class Strip if (c == 13) // cr noLines++; } - fis.close(); - fos.close(); - } - catch (IOException ioe) + System.out.println(" read: " + noIn + ", written: " + noOut + " - lines: " + noLines); + }catch (IOException ioe) { System.err.println(ioe); return false; + }finally{ + if (fos != null) + try { + fos.close(); + } catch (IOException e) { + } + if (fis != null) + try { + fis.close(); + } catch (IOException e) { + } + } - System.out.println(" read: " + noIn + ", written: " + noOut + " - lines: " + noLines); return true; } // stripIt diff --git a/org.adempiere.pipo/src/org/adempiere/pipo2/PackIn.java b/org.adempiere.pipo/src/org/adempiere/pipo2/PackIn.java index 0a1b1f7bc2..d19c0a5542 100644 --- a/org.adempiere.pipo/src/org/adempiere/pipo2/PackIn.java +++ b/org.adempiere.pipo/src/org/adempiere/pipo2/PackIn.java @@ -233,20 +233,25 @@ public class PackIn { ZipFile zf = new ZipFile(m_packageDirectory+File.separator+"blobs"+File.separator+fileName); Enumeration e = zf.entries(); ArrayList files = new ArrayList(); - while (e.hasMoreElements()) { - ZipEntry ze = (ZipEntry) e.nextElement(); - File file = new File(m_packageDirectory + File.separator + ze.getName()); - FileOutputStream fout = new FileOutputStream(file); - InputStream in = zf.getInputStream(ze); - for (int c = in.read(); c != -1; c = in.read()) { - fout.write(c); + File[] retValue = null; + try{ + while (e.hasMoreElements()) { + ZipEntry ze = (ZipEntry) e.nextElement(); + File file = new File(m_packageDirectory + File.separator + ze.getName()); + FileOutputStream fout = new FileOutputStream(file); + InputStream in = zf.getInputStream(ze); + for (int c = in.read(); c != -1; c = in.read()) { + fout.write(c); + } + in.close(); + fout.close(); + files.add(file); } - in.close(); - fout.close(); - files.add(file); + retValue = new File[files.size()]; + files.toArray(retValue); + }catch (Exception ex){ + zf.close(); } - File[] retValue = new File[files.size()]; - files.toArray(retValue); return retValue; } diff --git a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/panel/action/CSVImportAction.java b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/panel/action/CSVImportAction.java index 952e7b812f..42ec95ff9b 100644 --- a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/panel/action/CSVImportAction.java +++ b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/panel/action/CSVImportAction.java @@ -378,12 +378,23 @@ public class CSVImportAction implements EventListener } catch (IOException e) { throw new AdempiereException(e); } finally { - try { - reader.close(); - in.close(); - if (bw != null) + if (in != null) + try { + in.close(); + } catch (IOException e) { + } + + if (bw != null) + try { bw.close(); - } catch (IOException e) {} + } catch (IOException e) { + } + + if (reader != null) + try { + reader.close(); + } catch (IOException e) { + } } return is; }