jakarta-taglibs-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pier...@apache.org
Subject cvs commit: jakarta-taglibs/standard/src/org/apache/taglibs/standard/tag/common/sql UpdateTagSupport.java
Date Thu, 17 Feb 2005 00:44:16 GMT
pierred     2005/02/16 16:44:16

  Modified:    standard/src/org/apache/taglibs/standard/tag/common/sql
                        UpdateTagSupport.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.30      +10 -2     jakarta-taglibs/standard/src/org/apache/taglibs/standard/tag/common/sql/UpdateTagSupport.java
  
  Index: UpdateTagSupport.java
  ===================================================================
  RCS file: /home/cvs/jakarta-taglibs/standard/src/org/apache/taglibs/standard/tag/common/sql/UpdateTagSupport.java,v
  retrieving revision 1.29
  retrieving revision 1.30
  diff -u -r1.29 -r1.30
  --- UpdateTagSupport.java	19 Oct 2004 20:47:15 -0000	1.29
  +++ UpdateTagSupport.java	17 Feb 2005 00:44:16 -0000	1.30
  @@ -151,14 +151,22 @@
   	}
   
   	int result = 0;
  +	PreparedStatement ps = null;
   	try {
  -	    PreparedStatement ps = conn.prepareStatement(sqlStatement);
  +	    ps = conn.prepareStatement(sqlStatement);
   	    setParameters(ps, parameters);
   	    result = ps.executeUpdate();
  -            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);
  +		}
  +	    }
   	}
   	if (var != null)
   	    pageContext.setAttribute(var, new Integer(result), scope);
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: taglibs-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: taglibs-dev-help@jakarta.apache.org


Mime
View raw message