History | Log In     View a printable version of the current page.  
Issue Details (XML | Word | Printable)

Key: IDEADEV-25366
Type: Bug Bug
Status: Resolved Resolved
Resolution: Fixed
Priority: Normal Normal
Assignee: Bas Leijdekkers
Reporter: Björn Kautler
Votes: 0
Watchers: 1
Operations

If you were logged in you would be able to see more operations.
IDEA: Development

Faulty "'Connection' should be opened in a try block, and closed in a finally block" inspection in InspectionGadgets plugin

Created: 18 Jan 08 14:39   Updated: 19 Mar 08 18:12
Component/s: Code Analysis. Inspection
Fix Version/s: Selena 7.0.4, Diana 8243

Original Estimate: Unknown Remaining Estimate: Unknown Time Spent: Unknown
Environment: Windows XP SP2

Build: 7,590
Fixed in build: 8,238
Severity: High


 Description  « Hide
com.siyeh.ig.j2me.ConnectionResourceInspection.CloseVisitor uses "closeRecordStore" instead of "close", this way the inspection always reports false positives . Additionally even if "close" is checked, the following code:
javax.microedition.io.Connection connection = null;
try {
    connection = (javax.microedition.io.file.FileConnection) Connector.open("");
} catch (IOException ioe) {
    // ignore
} finally {
    try {
        if (null != connection) {
            connection.close();
        }
    } catch (IOException ioe) {
        // ignore
    }
}

will also report wrongly, because of the type cast. I know that this cast is unneccessary here, but it is just for demonstration. The real code is more like:

javax.microedition.io.file.FileConnection fileConnection = null;
try {
    fileConnection = (javax.microedition.io.file.FileConnection) Connector.open("");
    if (!fileConnection.exists()) {
        fileConnection.mkdir();
    }
} catch (IOException ioe) {
    // ignore
} finally {
    try {
        if (null != fileConnection) {
            fileConnection.close();
        }
    } catch (IOException ioe) {
        // ignore
    }
}


 All   Comments   Work Log   Change History      Sort Order:
Björn Kautler - 18 Jan 08 14:45
In case others have that problem and want to workaround this:
Connection connection = null;
try {
    connection = Connector.open("");
    final FileConnection fileConnection = (FileConnection) connection;
    if (!fileConnection.exists()) {
        fileConnection.mkdir();
    }
} catch (IOException ioe) {
    // ignore
} finally {
    try {
        if (null != connection) {
            connection.close();
        }
    } catch (IOException ioe) {
        // ignore
    }
}