]
Gail Badner commented on HHH-1364:
----------------------------------
Please use the user forum (
Defensive check of isClosed when obtaining a connection from
ConnectionManager
------------------------------------------------------------------------------
Key: HHH-1364
URL:
http://opensource.atlassian.com/projects/hibernate/browse/HHH-1364
Project: Hibernate3
Issue Type: Improvement
Components: core
Affects Versions: 3.1
Environment: Particularly bad in J2EE environments, where thread stale
thread-local connections show up in an unpredictable manner as threads are re-used.
Reporter: Damon Feldman
Assignee: Steve Ebersole
Priority: Minor
Fix For: 3.1.2
Original Estimate: 20 minutes
Remaining Estimate: 20 minutes
A null connection is returned to the caller, causing a NPE in another part of the system
if a connection is set to null AND the ConnectionManager is closed.
---- EXISTING CODE from ConnectionManager ----
/**
* Retrieves the connection currently managed by this ConnectionManager.
* <p/>
* Note, that we may need to obtain a connection to return here if a
* connection has either not yet been obtained (non-UserSuppliedConnectionProvider)
* or has previously been aggressively released (if supported in this environment).
*
* @return The current Connection.
*
* @throws HibernateException Indicates a connection is currently not
* available (we are currently manually disconnected).
*/
public Connection getConnection() throws HibernateException {
if ( connection == null && !isClosed ) {
openConnection();
}
return connection;
}
--------------------- RECOMMENDATION -----------
public Connection getConnection() throws HibernateException {
if ( connection == null) {
if(isClosed )
throw new HibernateException("A Connection Manager
that has been closed cannot supply a Connection.");
openConnection();
}
return connection;
}
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: