IDEMPIERE-2544:to more warning compiler hidden good warning

leak resource
This commit is contained in:
hieplq 2015-04-04 13:37:51 +07:00
parent d3107ced16
commit 1cac3f646f
7 changed files with 86 additions and 72 deletions

View File

@ -353,8 +353,9 @@ public class ReplicationLocal extends SvrProcess
// no keys - search for parents // no keys - search for parents
if (list.size() == 0) if (list.size() == 0)
{ {
DB.close(rs); DB.close(rs, pstmt);
rs = null; rs = null;
pstmt = null;
sql = "SELECT ColumnName FROM AD_Column " sql = "SELECT ColumnName FROM AD_Column "
+ "WHERE AD_Table_ID=?" + "WHERE AD_Table_ID=?"
+ " AND IsParent='Y'"; + " AND IsParent='Y'";

View File

@ -17,6 +17,7 @@
package org.compiere.impexp; package org.compiere.impexp;
import java.io.FileInputStream; import java.io.FileInputStream;
import java.io.IOException;
import org.compiere.model.MBankStatementLoader; import org.compiere.model.MBankStatementLoader;
import org.xml.sax.SAXException; import org.xml.sax.SAXException;
@ -71,6 +72,13 @@ public final class OFXFileBankStatementLoader extends OFXBankStatementHandler im
{ {
m_errorMessage = new StringBuffer("ErrorReadingData"); m_errorMessage = new StringBuffer("ErrorReadingData");
m_errorDescription = new StringBuffer(); m_errorDescription = new StringBuffer();
}finally{
if (m_stream != null)
try {
m_stream.close();
} catch (IOException e) {
e.printStackTrace();
}
} }
return result; return result;

View File

@ -1625,6 +1625,8 @@ queued-job-count = 0 (class javax.print.attribute.standard.QueuedJobCount)
.append("FROM C_DocType dt, C_Order o ") .append("FROM C_DocType dt, C_Order o ")
.append("WHERE o.C_DocTypeTarget_ID=dt.C_DocType_ID") .append("WHERE o.C_DocTypeTarget_ID=dt.C_DocType_ID")
.append(" AND o.C_Order_ID=?"); .append(" AND o.C_Order_ID=?");
DB.close(rs, pstmt);
rs = null; pstmt = null;
pstmt = DB.prepareStatement(sql.toString(), null); pstmt = DB.prepareStatement(sql.toString(), null);
pstmt.setInt(1, C_Order_ID); pstmt.setInt(1, C_Order_ID);
rs = pstmt.executeQuery(); rs = pstmt.executeQuery();

View File

@ -2,7 +2,6 @@ package org.compiere.process;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.sql.PreparedStatement; import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException; import java.sql.SQLException;
import java.sql.Timestamp; import java.sql.Timestamp;
import java.util.logging.Level; import java.util.logging.Level;
@ -51,9 +50,7 @@ public class FactReconciliation extends SvrProcess
*/ */
protected String doIt() protected String doIt()
{ {
PreparedStatement pstmt = null; PreparedStatement pstmt = null;
ResultSet rs = null;
String sql = "INSERT into T_Reconciliation " + String sql = "INSERT into T_Reconciliation " +
"(AD_Client_ID, AD_Org_ID, Created, CreatedBy, Updated, UpdatedBy, " + "(AD_Client_ID, AD_Org_ID, Created, CreatedBy, Updated, UpdatedBy, " +
@ -69,8 +66,6 @@ public class FactReconciliation extends SvrProcess
try try
{ {
pstmt = DB.prepareStatement(sql, get_TrxName()); pstmt = DB.prepareStatement(sql, get_TrxName());
pstmt.setInt(1, getAD_PInstance_ID()); pstmt.setInt(1, getAD_PInstance_ID());
pstmt.setInt(2, p_Account_ID); pstmt.setInt(2, p_Account_ID);
@ -88,6 +83,8 @@ public class FactReconciliation extends SvrProcess
" AND r.AD_PInstance_ID = t.AD_PInstance_ID) = 0 " + " AND r.AD_PInstance_ID = t.AD_PInstance_ID) = 0 " +
"AND t.AD_PInstance_ID = ?"; "AND t.AD_PInstance_ID = ?";
DB.close(pstmt);
pstmt = null;
pstmt = DB.prepareStatement(sql, get_TrxName()); pstmt = DB.prepareStatement(sql, get_TrxName());
pstmt.setInt(1, getAD_PInstance_ID()); pstmt.setInt(1, getAD_PInstance_ID());
count = pstmt.executeUpdate(); count = pstmt.executeUpdate();
@ -95,7 +92,6 @@ public class FactReconciliation extends SvrProcess
if (log.isLoggable(Level.FINE))log.log(Level.FINE, result); if (log.isLoggable(Level.FINE))log.log(Level.FINE, result);
} }
catch (SQLException e) catch (SQLException e)
{ {
@ -104,8 +100,8 @@ public class FactReconciliation extends SvrProcess
} }
finally finally
{ {
DB.close(rs, pstmt); DB.close(pstmt);
rs = null; pstmt = null; pstmt = null;
} }
if (log.isLoggable(Level.FINE)) log.fine((System.currentTimeMillis() - m_start) + " ms"); if (log.isLoggable(Level.FINE)) log.fine((System.currentTimeMillis() - m_start) + " ms");

View File

@ -18,7 +18,6 @@ package org.compiere.tools;
import java.io.File; import java.io.File;
import java.io.FileInputStream; import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream; import java.io.FileOutputStream;
import java.io.IOException; import java.io.IOException;
@ -165,32 +164,15 @@ public class Strip
private boolean copy (File infile, File outfile) private boolean copy (File infile, File outfile)
{ {
FileInputStream fis = null; FileInputStream fis = null;
try
{
fis = new FileInputStream(infile);
}
catch (FileNotFoundException fnfe)
{
System.err.println(fnfe);
return false;
}
//
FileOutputStream fos = null; FileOutputStream fos = null;
try try{
{ fis = new FileInputStream(infile);
fos = new FileOutputStream(outfile, false); // no append fos = new FileOutputStream(outfile, false); // no append
}
catch (FileNotFoundException fnfe)
{
System.err.println(fnfe);
return false;
}
int noIn = 0; int noIn = 0;
int noOut = 0; int noOut = 0;
int noLines = 1; int noLines = 1;
try
{
int c; int c;
while ((c = fis.read()) != -1) while ((c = fis.read()) != -1)
{ {
@ -203,15 +185,24 @@ public class Strip
if (c == 13) // cr if (c == 13) // cr
noLines++; noLines++;
} }
fis.close(); System.out.println(" read: " + noIn + ", written: " + noOut + " - lines: " + noLines);
fos.close(); }catch (IOException ioe)
}
catch (IOException ioe)
{ {
System.err.println(ioe); System.err.println(ioe);
return false; 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; return true;
} // stripIt } // stripIt

View File

@ -233,6 +233,8 @@ public class PackIn {
ZipFile zf = new ZipFile(m_packageDirectory+File.separator+"blobs"+File.separator+fileName); ZipFile zf = new ZipFile(m_packageDirectory+File.separator+"blobs"+File.separator+fileName);
Enumeration<?> e = zf.entries(); Enumeration<?> e = zf.entries();
ArrayList<File> files = new ArrayList<File>(); ArrayList<File> files = new ArrayList<File>();
File[] retValue = null;
try{
while (e.hasMoreElements()) { while (e.hasMoreElements()) {
ZipEntry ze = (ZipEntry) e.nextElement(); ZipEntry ze = (ZipEntry) e.nextElement();
File file = new File(m_packageDirectory + File.separator + ze.getName()); File file = new File(m_packageDirectory + File.separator + ze.getName());
@ -245,8 +247,11 @@ public class PackIn {
fout.close(); fout.close();
files.add(file); files.add(file);
} }
File[] retValue = new File[files.size()]; retValue = new File[files.size()];
files.toArray(retValue); files.toArray(retValue);
}catch (Exception ex){
zf.close();
}
return retValue; return retValue;
} }

View File

@ -378,12 +378,23 @@ public class CSVImportAction implements EventListener<Event>
} catch (IOException e) { } catch (IOException e) {
throw new AdempiereException(e); throw new AdempiereException(e);
} finally { } finally {
if (in != null)
try {
in.close();
} catch (IOException e) {
}
if (bw != null)
try {
bw.close();
} catch (IOException e) {
}
if (reader != null)
try { try {
reader.close(); reader.close();
in.close(); } catch (IOException e) {
if (bw != null) }
bw.close();
} catch (IOException e) {}
} }
return is; return is;
} }