[hibernate-issues] [Hibernate-JIRA] Commented: (HHH-1364) Defensive check of isClosed when obtaining a connection from ConnectionManager
Gail Badner (JIRA)
noreply at atlassian.com
Wed Oct 24 16:48:39 EDT 2007
[ http://opensource.atlassian.com/projects/hibernate/browse/HHH-1364?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_28546 ]
Gail Badner commented on HHH-1364:
----------------------------------
Please use the user forum (http://forum.hibernate.org/) to ask for help.
> 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: http://opensource.atlassian.com/projects/hibernate/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira
More information about the hibernate-issues
mailing list