Bug 155312 - [compiler] Feature-Request:: static check for unecessary variable assignment
Summary: [compiler] Feature-Request:: static check for unecessary variable assignment
Status: NEW
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.2   Edit
Hardware: PC Windows XP
: P3 enhancement (vote)
Target Milestone: ---   Edit
Assignee: JDT-Core-Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2006-08-26 12:04 EDT by Michael Schneider CLA
Modified: 2008-08-22 11:18 EDT (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Michael Schneider CLA 2006-08-26 12:04:57 EDT
I propose adding a static check in Java code for the following situation:

    x = 42;
    
    // ... no reading of variable 'x'

    x = 100;

Here, variable x is assigned a value '42', which is never read before reassigning the value '100' to x. This is never useful, but sometimes it is a sign of an error. As an example, imagine a JUnit testcase with variables x and y in the testfixture, and the two assignments above within the setUp() routine. Most probably, the author wanted to write

    x = 42;
    y = 100;

but accidentally assigned value '100' to variable 'x' instead of 'y'. This might become a hard to find error.

I propose adding this static check to the Preferences, under

  Java -> Compiler -> Errors/Warnings -> Unnecessary Code

Michael