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

Key: IDEA-16979
Type: New Feature New Feature
Status: Open Open
Assignee: Maxim Shafirov
Reporter: Serge Baranov
Votes: 0
Watchers: 0
Operations

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

"Constant conditions and exceptions" should be aware of equals() semantics

Created: 27 Jan 08 19:03   Updated: 28 Jan 08 09:58
Component/s: Code Analysis. Inspection

Build: 7,590
Severity: Medium


 Description  « Hide
Support feedback:

The code snippet below triggers an inspection warning which I believe is incorrect:

public void buggyInspectionExample(String name) {
        DefaultMutableTreeNode selectedNode = (DefaultMutableTreeNode) tree.getSelectionPath().getLastPathComponent();
        if (selectedNode == null) {
            return;
        }
        DefaultMutableTreeNode parentNode = (DefaultMutableTreeNode) selectedNode.getParent();
        final Object parentName = parentNode == null ? null : parentNode.getUserObject();
        // at this point parentName is non-null if and only if parentNode is non-null
        if ("Topics".equals(parentName)) {
            // if this is true then parentName is non-null
            ((GemsTopicNode) selectedNode).setProperty((GemsConnectionNode) parentNode.getParent(), name);
            // therefore the above line should NOT trigger an inspection warning 
        } else if ("Queues".equals(parentName)) {
            ((GemsQueueNode) selectedNode).setProperty((GemsConnectionNode) parentNode.getParent(), name);
        }
    }


 All   Comments   Work Log   Change History      Sort Order:
Dmitry Jemerov - 27 Jan 08 19:11
This is not actually a bug. The inspection isn't smart enough to know about the semantics of the equals() method and its handling of null/notnull values.

Eugene Vigdorchik - 28 Jan 08 09:58
What if the programmer actually implemented equals() breaking the contract? Java is not powerful enough to express this contract in type system.