Mantis - Quercus
Viewing Issue Advanced Details
2182 tweak always 11-17-07 02:36 11-20-07 09:51
koreth  
nam  
normal  
closed 3.1.4  
fixed  
none    
none 3.1.4  
0002182: Minor logic bug in Env.getConnection()
I think I'm right about this, but if not, apologies for the noise.

Env.getConnection() does

    ConnectionEntry entry = new ConnectionEntry();
    entry.init(database, userName, password);

    ConnectionEntry oldEntry = _connMap.get(entry);

So at this point oldEntry is the existing entry in the connection map and entry is a brand-new one. Then the code tests to see if oldEntry is valid -- is it null, is its connection closed, etc. If oldEntry doesn't have a valid connection, it establishes a new connection and updates "entry" to have a reference to the new connection.

Then, whether or not oldEntry was invalid (and thus whether or not a new connection was installed into "entry") the code does

      _connMap.put(entry, entry);

This looks like it can replace a perfectly valid oldEntry (one that has a working connection) with a new "entry" that has no connection at all (which will be the case if oldEntry doesn't test as broken).

My fix is to move that "put" up by one line, inside the "if oldEntry is bad" block. That means the existing oldEntry is left in the connection map if it's in good shape.

I'm not sure how this would actually manifest itself as a problem at runtime but it looked wrong to me when I was examining this code.

There are no notes attached to this issue.