Dr. Dobb's is part of the Informa Tech Division of Informa PLC

This site is operated by a business or businesses owned by Informa PLC and all copyright resides with them. Informa PLC's registered office is 5 Howick Place, London SW1P 1WG. Registered in England and Wales. Number 8860726.


Welcome Guest | Log In | Register | Benefits
Channels ▼
RSS

JVM Languages

Java & Static Analysis


July, 2005: Java & Static Analysis

class TestResourceLeak

{
    public CoreResponse process(Entit entity) throws ResourceException {
        CoreResponse coreresponse = new CoreResponse();
        DatabaseConnection dbcon = new DatabaseConnection();
        Connection con1 = null;
        Connection con2 = null;
        //getting the Data Base Connection
        try
        {
            con1 = dbcon.getConnection();
            con2 = dbcon.getConnection();
            ...
        }
        catch(Exception e)
        {
            con1.close();
            throw new ResourceException(e.getMessage(),e) ;
        }
        con1.close();
        return coreresponse;
    }   
}

Example 2: The database connection object con2 that is not closed.


Related Reading


More Insights