[ http://jira.jboss.com/jira/browse/JBAS-680?page=history ]
Adrian Brock updated JBAS-680:
------------------------------
Description:
SourceForge Submitter: cmunday .
Hi,
There is a Statement that does not get closed and is
left to be finialized within the following method (included
below) from the HiLoKeyGenerator class.
The statement create by:
stmt = con.prepareStatement(nextKeyQuery);
leaks because the variable "stmt" is re-assigned with:
stmt = con.prepareStatement(updateStmt);
This second statement is closed within the finally clause
but the first one is never closed and should be
Cheers,
Craig.
public synchronized Object generateKey()
{
if(lo < hi)
return new Integer(lo++);
Connection con = null;
PreparedStatement stmt = null;
ResultSet rs = null;
Transaction currentTx = null;
try
{
currentTx = tm.suspend();
tm.begin();
con = datasource.getConnection();
int rowsUpdated;
do
{
if(isDebugEnabled) log.debug("Executing SQL: "
+ nextKeyQuery);
stmt = con.prepareStatement(nextKeyQuery);
rs = stmt.executeQuery();
if(!rs.next())
throw new Exception("Couldn't read next key:
ResultSet is empty.");
lo = rs.getInt(1);
hi = lo + blockSize;
if(isDebugEnabled)
log.debug("Executing SQL: " + updateStmt
+ " [p1=" + hi + ",p2=" + lo + "]");
stmt = con.prepareStatement(updateStmt);
stmt.setInt(1, hi);
stmt.setInt(2, lo);
rowsUpdated = stmt.executeUpdate();
}
while(rowsUpdated == 0);
tm.commit();
}
catch(Exception e)
{
log.error("Error fetching next key:", e);
try
{
tm.rollback();
}
catch(SystemException se)
{
log.error("Couldn't rollback transaction: ", se);
}
}
finally
{
JDBCUtil.safeClose(rs);
JDBCUtil.safeClose(stmt);
JDBCUtil.safeClose(con);
if(currentTx != null)
{
try
{
tm.resume(currentTx);
}
catch(InvalidTransactionException ite)
{
log.error("Invalid transaction: ", ite);
}
catch(SystemException se)
{
log.error("Unexpected error: ", se);
}
}
}
return new Integer(lo++);
}
was:
SourceForge Submitter: cmunday .
Hi,
There is a Statement that does not get closed and is
left to be finialized within the following method (included
below) from the HiLoKeyGenerator class.
The statement create by:
stmt = con.prepareStatement(nextKeyQuery);
leaks because the variable "stmt" is re-assigned with:
stmt = con.prepareStatement(updateStmt);
This second statement is closed within the finally clause
but the first one is never closed and should be
Cheers,
Craig.
public synchronized Object generateKey()
{
if(lo < hi)
return new Integer(lo++);
Connection con = null;
PreparedStatement stmt = null;
ResultSet rs = null;
Transaction currentTx = null;
try
{
currentTx = tm.suspend();
tm.begin();
con = datasource.getConnection();
int rowsUpdated;
do
{
if(isDebugEnabled) log.debug("Executing SQL: "
+ nextKeyQuery);
stmt = con.prepareStatement(nextKeyQuery);
rs = stmt.executeQuery();
if(!rs.next())
throw new Exception("Couldn't read next key:
ResultSet is empty.");
lo = rs.getInt(1);
hi = lo + blockSize;
if(isDebugEnabled)
log.debug("Executing SQL: " + updateStmt
+ " [p1=" + hi + ",p2=" + lo + "]");
stmt = con.prepareStatement(updateStmt);
stmt.setInt(1, hi);
stmt.setInt(2, lo);
rowsUpdated = stmt.executeUpdate();
}
while(rowsUpdated == 0);
tm.commit();
}
catch(Exception e)
{
log.error("Error fetching next key:", e);
try
{
tm.rollback();
}
catch(SystemException se)
{
log.error("Couldn't rollback transaction: ", se);
}
}
finally
{
JDBCUtil.safeClose(rs);
JDBCUtil.safeClose(stmt);
JDBCUtil.safeClose(con);
if(currentTx != null)
{
try
{
tm.resume(currentTx);
}
catch(InvalidTransactionException ite)
{
log.error("Invalid transaction: ", ite);
}
catch(SystemException se)
{
log.error("Unexpected error: ", se);
}
}
}
return new Integer(lo++);
}
Environment:
Component: EJBs
> PreparedStatement leak in HiLoKeyGenerator.java
> -----------------------------------------------
>
> Key: JBAS-680
> URL: http://jira.jboss.com/jira/browse/JBAS-680
> Project: JBoss Application Server
> Type: Bug
> Components: EJBs
> Versions: JBossAS-4.0.0 Final
> Reporter: SourceForge User
> Assignee: Alexey Loubyansky
>
>
> SourceForge Submitter: cmunday .
> Hi,
> There is a Statement that does not get closed and is
> left to be finialized within the following method (included
> below) from the HiLoKeyGenerator class.
> The statement create by:
> stmt = con.prepareStatement(nextKeyQuery);
> leaks because the variable "stmt" is re-assigned with:
> stmt = con.prepareStatement(updateStmt);
> This second statement is closed within the finally clause
> but the first one is never closed and should be
> Cheers,
> Craig.
>
> public synchronized Object generateKey()
> {
> if(lo < hi)
> return new Integer(lo++);
> Connection con = null;
> PreparedStatement stmt = null;
> ResultSet rs = null;
> Transaction currentTx = null;
> try
> {
> currentTx = tm.suspend();
> tm.begin();
> con = datasource.getConnection();
> int rowsUpdated;
> do
> {
> if(isDebugEnabled) log.debug("Executing SQL: "
> + nextKeyQuery);
> stmt = con.prepareStatement(nextKeyQuery);
> rs = stmt.executeQuery();
> if(!rs.next())
> throw new Exception("Couldn't read next key:
> ResultSet is empty.");
> lo = rs.getInt(1);
> hi = lo + blockSize;
> if(isDebugEnabled)
> log.debug("Executing SQL: " + updateStmt
> + " [p1=" + hi + ",p2=" + lo + "]");
> stmt = con.prepareStatement(updateStmt);
> stmt.setInt(1, hi);
> stmt.setInt(2, lo);
> rowsUpdated = stmt.executeUpdate();
> }
> while(rowsUpdated == 0);
> tm.commit();
> }
> catch(Exception e)
> {
> log.error("Error fetching next key:", e);
> try
> {
> tm.rollback();
> }
> catch(SystemException se)
> {
> log.error("Couldn't rollback transaction: ", se);
> }
> }
> finally
> {
> JDBCUtil.safeClose(rs);
> JDBCUtil.safeClose(stmt);
> JDBCUtil.safeClose(con);
> if(currentTx != null)
> {
> try
> {
> tm.resume(currentTx);
> }
> catch(InvalidTransactionException ite)
> {
> log.error("Invalid transaction: ", ite);
> }
> catch(SystemException se)
> {
> log.error("Unexpected error: ", se);
> }
> }
> }
> return new Integer(lo++);
> }
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
http://jira.jboss.com/jira/secure/Administrators.jspa
-
If you want more information on JIRA, or have a bug to report see:
http://www.atlassian.com/software/jira
-------------------------------------------------------
SF email is sponsored by - The IT Product Guide
Read honest & candid reviews on hundreds of IT Products from real users.
Discover which products truly live up to the hype. Start reading now.
http://ads.osdn.com/?ad_id=6595&alloc_id=14396&op=click
_______________________________________________
JBoss-Development mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/jboss-development