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
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'";

View File

@ -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;

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("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();

View File

@ -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 "";

View File

@ -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

View File

@ -233,20 +233,25 @@ public class PackIn {
ZipFile zf = new ZipFile(m_packageDirectory+File.separator+"blobs"+File.separator+fileName);
Enumeration<?> e = zf.entries();
ArrayList<File> files = new ArrayList<File>();
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;
}

View File

@ -378,12 +378,23 @@ public class CSVImportAction implements EventListener<Event>
} 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;
}