This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.
Summary: | Missing hint to remove unused assignment | ||
---|---|---|---|
Product: | java | Reporter: | cezariusz <cezariusz> |
Component: | Hints | Assignee: | Svata Dedic <sdedic> |
Status: | REOPENED --- | ||
Severity: | normal | ||
Priority: | P3 | ||
Version: | 8.1 | ||
Hardware: | PC | ||
OS: | Windows 7 | ||
Issue Type: | ENHANCEMENT | Exception Reporter: | |
Attachments: | Only one hint available for the unnecessary assignment |
Description
cezariusz
2015-04-30 06:55:28 UTC
Created attachment 153470 [details]
Only one hint available for the unnecessary assignment
I don't think that removing code need to be automated this way; deleting a portion of text is trivial - and it's rather unlikely that the code is actually useless, but rather some code path which should (was intended to) use the value does not. (In reply to Svata Dedic from comment #2) > I don't think that removing code need to be automated this way; deleting a > portion of text is trivial - and it's rather unlikely that the code is > actually useless, but rather some code path which should (was intended to) > use the value does not. I do not agree with INVALID. 1. It is a warning with an exclamation mark. I don't want to have a yellow status of the file and I want the IDE to help me with that. 2. It's trivial, but requires several keystrokes (End, Left, 5 x Shift+Ctrl+Left, Backspace). Alt-Enter, Enter would be much faster. 3. There are hints for even more trivial actions like removing an unused import, though it's just a Ctrl+D to delete a line. 4. It's very often a useless code, because programmers assign a null value "just in case". A common example: public String unused() throws SQLException { Connection connection = null; String value = null; try { connection = getCommonConnection(); value = getDatabaseName(connection); } catch (SQLException e) { logError(e); resetCommonConnection(); throw e; } return value; } BTW: The "value = null" assignment is not detected as unused. Should I report a bug for it. Whatever. In that case, let's make it an enhancement. Hm, null assignment COULD be important, sometimes, even though the value is not used: to clear a reference which would otherwise prevent GC of an object (consider call to a blocking method). Optimizing compiler would limit the scope of the variable, but there's no guarantee such optimization happens at runtime. But not in the case in your example: in variable initializer - this one should be reported. Specifically in this case I would agree with an automated action: the expression has no potential side effects and the result is not used. |