From 860b4ede1e9c1c90ab9e33c37daa524d54bdeea9 Mon Sep 17 00:00:00 2001 From: Heng Sin Low Date: Tue, 29 Jan 2008 08:47:47 +0000 Subject: [PATCH] [ 1874419 ] JDBC Statement not close in a finally block --- .../org/compiere/server/AcctProcessor.java | 13 +--- .../org/compiere/server/AlertProcessor.java | 17 ++--- .../org/compiere/server/RequestProcessor.java | 76 +++++++------------ .../server/org/compiere/server/Scheduler.java | 8 +- .../compiere/server/WorkflowProcessor.java | 58 ++++++-------- 5 files changed, 69 insertions(+), 103 deletions(-) diff --git a/serverRoot/src/main/server/org/compiere/server/AcctProcessor.java b/serverRoot/src/main/server/org/compiere/server/AcctProcessor.java index 865aa2142b..34dcf63a6e 100644 --- a/serverRoot/src/main/server/org/compiere/server/AcctProcessor.java +++ b/serverRoot/src/main/server/org/compiere/server/AcctProcessor.java @@ -129,23 +129,16 @@ public class AcctProcessor extends AdempiereServer countError++; } rs.close(); - pstmt.close(); - pstmt = null; } catch (Exception e) { log.log(Level.SEVERE, sql.toString(), e); } - if (pstmt != null) + finally { - try - { - pstmt.close(); - } - catch (Exception e) - { - } + DB.close(pstmt); } + // if (count > 0) { diff --git a/serverRoot/src/main/server/org/compiere/server/AlertProcessor.java b/serverRoot/src/main/server/org/compiere/server/AlertProcessor.java index 1607a67d0a..3686d3274e 100644 --- a/serverRoot/src/main/server/org/compiere/server/AlertProcessor.java +++ b/serverRoot/src/main/server/org/compiere/server/AlertProcessor.java @@ -270,20 +270,17 @@ public class AlertProcessor extends AdempiereServer pstmt.close (); pstmt = null; } - catch (Exception e) + catch (Throwable e) { log.log(Level.SEVERE, sql, e); - error = e; + if (e instanceof Exception) + error = (Exception)e; + else + error = new Exception(e.getMessage(), e); } - try + finally { - if (pstmt != null) - pstmt.close (); - pstmt = null; - } - catch (Exception e) - { - pstmt = null; + DB.close(pstmt); } // Error occured diff --git a/serverRoot/src/main/server/org/compiere/server/RequestProcessor.java b/serverRoot/src/main/server/org/compiere/server/RequestProcessor.java index 885c6a231a..0ce6844427 100644 --- a/serverRoot/src/main/server/org/compiere/server/RequestProcessor.java +++ b/serverRoot/src/main/server/org/compiere/server/RequestProcessor.java @@ -116,13 +116,15 @@ public class RequestProcessor extends AdempiereServer } } rs.close (); - pstmt.close (); - pstmt = null; } catch (Exception e) { log.log(Level.SEVERE, sql, e); } + finally + { + DB.close(pstmt); + } m_summary.append("New Due #").append(count); if (countEMails > 0) m_summary.append(" (").append(countEMails).append(" EMail)"); @@ -169,13 +171,15 @@ public class RequestProcessor extends AdempiereServer } } rs.close (); - pstmt.close (); - pstmt = null; } catch (Exception e) { log.log(Level.SEVERE, sql, e); } + finally + { + DB.close(pstmt); + } m_summary.append("New Overdue #").append(count); if (countEMails > 0) m_summary.append(" (").append(countEMails).append(" EMail)"); @@ -224,12 +228,15 @@ public class RequestProcessor extends AdempiereServer count++; } rs.close(); - pstmt.close(); } catch (SQLException e) { log.log(Level.SEVERE, sql, e); } + finally + { + DB.close(pstmt); + } m_summary.append("Alerts #").append(count); if (countEMails > 0) m_summary.append(" (").append(countEMails).append(" EMail)"); @@ -265,12 +272,15 @@ public class RequestProcessor extends AdempiereServer count++; } rs.close(); - pstmt.close(); } catch (SQLException e) { log.log(Level.SEVERE, sql, e); } + finally + { + DB.close(pstmt); + } m_summary.append("Escalated #").append(count).append(" - "); } // Esacalate @@ -316,29 +326,20 @@ public class RequestProcessor extends AdempiereServer } } rs.close(); - pstmt.close(); } catch (SQLException e) { log.log(Level.SEVERE, sql, e); } + finally + { + DB.close(pstmt); + } m_summary.append("Inactivity #").append(count); if (countEMails > 0) m_summary.append(" (").append(countEMails).append(" EMail)"); m_summary.append (" - "); - } // Inactivity - - // - try - { - if (pstmt != null) - pstmt.close (); - pstmt = null; - } - catch (Exception e) - { - pstmt = null; - } + } // Inactivity } // processRequests /** @@ -442,22 +443,14 @@ public class RequestProcessor extends AdempiereServer count++; } rs.close (); - pstmt.close (); - pstmt = null; } catch (Exception e) { log.log (Level.SEVERE, sql, e); } - try + finally { - if (pstmt != null) - pstmt.close (); - pstmt = null; - } - catch (Exception e) - { - pstmt = null; + DB.close(pstmt); } m_summary.append("Status Timeout #").append(count) @@ -506,23 +499,16 @@ public class RequestProcessor extends AdempiereServer failure++; } rs.close (); - pstmt.close (); - pstmt = null; } catch (Exception e) { log.log (Level.SEVERE, sql, e); } - try + finally { - if (pstmt != null) - pstmt.close (); - pstmt = null; - } - catch (Exception e) - { - pstmt = null; + DB.close(pstmt); } + m_summary.append("Auto Change Request #").append(count); if (failure > 0) m_summary.append("(fail=").append(failure).append(")"); @@ -578,20 +564,14 @@ public class RequestProcessor extends AdempiereServer notFound++; } rs.close(); - pstmt.close(); - pstmt = null; } catch (SQLException ex) { log.log(Level.SEVERE, sql, ex); } - try - { - if (pstmt != null) - pstmt.close(); - } - catch (SQLException ex1) + finally { + DB.close(pstmt); } pstmt = null; // diff --git a/serverRoot/src/main/server/org/compiere/server/Scheduler.java b/serverRoot/src/main/server/org/compiere/server/Scheduler.java index 75230bbc90..66781834aa 100644 --- a/serverRoot/src/main/server/org/compiere/server/Scheduler.java +++ b/serverRoot/src/main/server/org/compiere/server/Scheduler.java @@ -77,8 +77,12 @@ public class Scheduler extends AdempiereServer log.log(Level.WARNING, process.toString(), e); m_summary.append(e.toString()); } - if (m_trx != null) - m_trx.close(); + finally + { + if (m_trx != null) + m_trx.close(); + } + // int no = m_model.deleteLog(); m_summary.append("Logs deleted=").append(no); diff --git a/serverRoot/src/main/server/org/compiere/server/WorkflowProcessor.java b/serverRoot/src/main/server/org/compiere/server/WorkflowProcessor.java index eacc8b6934..dd1d0d1d2f 100644 --- a/serverRoot/src/main/server/org/compiere/server/WorkflowProcessor.java +++ b/serverRoot/src/main/server/org/compiere/server/WorkflowProcessor.java @@ -104,14 +104,16 @@ public class WorkflowProcessor extends AdempiereServer // saves and calls MWFProcess.checkActivities(); count++; } - rs.close (); - pstmt.close (); - pstmt = null; + rs.close (); } catch (Exception e) { log.log(Level.SEVERE, "wakeup", e); } + finally + { + DB.close(pstmt); + } m_summary.append("Wakeup #").append(count).append (" - "); } // wakeup @@ -149,26 +151,17 @@ public class WorkflowProcessor extends AdempiereServer count++; } rs.close (); - pstmt.close (); - pstmt = null; } catch (Exception e) { log.log(Level.SEVERE, sql, e); } - m_summary.append("DynPriority #").append(count).append (" - "); - - // Clean-up - try + finally { - if (pstmt != null) - pstmt.close (); - pstmt = null; - } - catch (Exception e) - { - pstmt = null; + DB.close(pstmt); } + + m_summary.append("DynPriority #").append(count).append (" - "); } // setPriority @@ -194,9 +187,10 @@ public class WorkflowProcessor extends AdempiereServer + " AND (wf.AD_WorkflowProcessor_ID IS NULL OR wf.AD_WorkflowProcessor_ID=?))"; int count = 0; int countEMails = 0; + PreparedStatement pstmt = null; try { - PreparedStatement pstmt = DB.prepareStatement(sql, null); + pstmt = DB.prepareStatement(sql, null); pstmt.setInt (1, m_model.getAlertOverPriority()); pstmt.setInt (2, m_model.getAD_WorkflowProcessor_ID()); ResultSet rs = pstmt.executeQuery(); @@ -217,6 +211,10 @@ public class WorkflowProcessor extends AdempiereServer { log.log(Level.SEVERE, "(Priority) - " + sql, e); } + finally + { + DB.close(pstmt); + } m_summary.append("OverPriority #").append(count); if (countEMails > 0) m_summary.append(" (").append(countEMails).append(" EMail)"); @@ -258,13 +256,16 @@ public class WorkflowProcessor extends AdempiereServer count++; } rs.close (); - pstmt.close (); - pstmt = null; } catch (Exception e) { log.log(Level.SEVERE, "(EndWaitTime) - " + sql, e); } + finally + { + DB.close(pstmt); + } + m_summary.append("EndWaitTime #").append(count); if (countEMails > 0) m_summary.append(" (").append(countEMails).append(" EMail)"); @@ -311,24 +312,15 @@ public class WorkflowProcessor extends AdempiereServer { log.log(Level.SEVERE, "(Inactivity): " + sql, e); } + finally + { + DB.close(pstmt); + } m_summary.append("Inactivity #").append(count); if (countEMails > 0) m_summary.append(" (").append(countEMails).append(" EMail)"); m_summary.append (" - "); - } // Inactivity - - - // Clean-up - try - { - if (pstmt != null) - pstmt.close (); - pstmt = null; - } - catch (Exception e) - { - pstmt = null; - } + } // Inactivity } // sendAlerts /**