Return-Path: Delivered-To: apmail-jakarta-taglibs-dev-archive@www.apache.org Received: (qmail 18294 invoked from network); 17 Feb 2005 00:41:41 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur-2.apache.org with SMTP; 17 Feb 2005 00:41:41 -0000 Received: (qmail 77507 invoked by uid 500); 17 Feb 2005 00:41:39 -0000 Delivered-To: apmail-jakarta-taglibs-dev-archive@jakarta.apache.org Received: (qmail 77479 invoked by uid 500); 17 Feb 2005 00:41:39 -0000 Mailing-List: contact taglibs-dev-help@jakarta.apache.org; run by ezmlm Precedence: bulk List-Unsubscribe: List-Subscribe: List-Help: List-Post: List-Id: "Tag Libraries Developers List" Reply-To: "Tag Libraries Developers List" Delivered-To: mailing list taglibs-dev@jakarta.apache.org Received: (qmail 77465 invoked by uid 500); 17 Feb 2005 00:41:38 -0000 Received: (qmail 77460 invoked by uid 99); 17 Feb 2005 00:41:38 -0000 X-ASF-Spam-Status: No, hits=-9.8 required=10.0 tests=ALL_TRUSTED,NO_REAL_NAME X-Spam-Check-By: apache.org Received: from minotaur.apache.org (HELO minotaur.apache.org) (209.237.227.194) by apache.org (qpsmtpd/0.28) with SMTP; Wed, 16 Feb 2005 16:41:38 -0800 Received: (qmail 18252 invoked by uid 1003); 17 Feb 2005 00:41:37 -0000 Date: 17 Feb 2005 00:41:37 -0000 Message-ID: <20050217004137.18251.qmail@minotaur.apache.org> From: pierred@apache.org To: jakarta-taglibs-cvs@apache.org Subject: cvs commit: jakarta-taglibs/standard/src/org/apache/taglibs/standard/tag/common/sql QueryTagSupport.java X-Virus-Checked: Checked X-Spam-Rating: minotaur-2.apache.org 1.6.2 0/1000/N pierred 2005/02/16 16:41:37 Modified: standard/src/org/apache/taglibs/standard/tag/common/sql QueryTagSupport.java Log: Patch from Dhiru Pandey for bug #17388 This is needed because in the current implementation, if an error occurs before the preparedStatement is closed, then the closing of the preparedStatement would depend on the implementation of finalize() for the PreparedStatement class which should be called when that object is GCed (Garbage Collected). This is not a good practice since: a) we should not depend on the implementation of the finalize() method in PreparedStatement b) the invocation of the finalize() method is not guaranteed by the JVM. So even if finalize() does call close(), there is no guarantee that finalize() itself will be called when this object is GCed and we may continue to see memory leaks and resource leaks as reported in Bug 17388 (Result set created in query tag is never released + update tag) Revision Changes Path 1.40 +10 -2 jakarta-taglibs/standard/src/org/apache/taglibs/standard/tag/common/sql/QueryTagSupport.java Index: QueryTagSupport.java =================================================================== RCS file: /home/cvs/jakarta-taglibs/standard/src/org/apache/taglibs/standard/tag/common/sql/QueryTagSupport.java,v retrieving revision 1.39 retrieving revision 1.40 diff -u -r1.39 -r1.40 --- QueryTagSupport.java 28 Feb 2004 01:01:45 -0000 1.39 +++ QueryTagSupport.java 17 Feb 2005 00:41:36 -0000 1.40 @@ -209,15 +209,23 @@ * value for isLimitedByMaxRows(); there's no way to check * if it was from the ResultSet. */ + PreparedStatement ps = null; try { - PreparedStatement ps = conn.prepareStatement(sqlStatement); + ps = conn.prepareStatement(sqlStatement); setParameters(ps, parameters); ResultSet rs = ps.executeQuery(); result = new ResultImpl(rs, startRow, maxRows); - ps.close(); } catch (Throwable e) { throw new JspException(sqlStatement + ": " + e.getMessage(), e); + } finally { + if (ps != null) { + try { + ps.close(); + } catch (SQLException sqe) { + throw new JspException(sqe.getMessage(), sqe); + } + } } pageContext.setAttribute(var, result, scope); return EVAL_PAGE; --------------------------------------------------------------------- To unsubscribe, e-mail: taglibs-dev-unsubscribe@jakarta.apache.org For additional commands, e-mail: taglibs-dev-help@jakarta.apache.org