Bug 165084 - [compiler] "Parameter is never read" could be customized for constructors
Summary: [compiler] "Parameter is never read" could be customized for constructors
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-11-18 16:40 EST by Christophe Cornu CLA
Modified: 2006-11-24 13:57 EST (History)
5 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Christophe Cornu CLA 2006-11-18 16:40:34 EST
Here is a mistake I do too often. Wondering if you will find this case interesting enough to add it to JDT UI.

class MyClass {

    Foo foo;
    Bar bar;
    String msg;

    public MyClass(Foo foo, Bar bar, String msg) {
        this.foo = foo;
        this.arg3 = arg3;
        // more work
    }

I forgot to assign bar to this.bar . This happens in particular when refactoring a class, declaring extra arguments, passing extra arguments and fixing javadoc (till compile errors are gone). Then start running but things still don't work. Then after some debugging, find out the constructor isn't doing its work. With eclipse 3.2 M3 JRE1.5 I don't see any warning inside the constructor.

Suggestion: detect this case and report it. Add the yellow warning decoration under the bar variable in the constructor.

"Warning: Argument bar is not assigned in constructor"
Comment 1 Christophe Cornu CLA 2006-11-18 16:41:52 EST
Typo on arg3, I meant:

class MyClass {

    Foo foo;
    Bar bar;
    String msg;

    public MyClass(Foo foo, Bar bar, String msg) {
        this.foo = foo;
        this.msg = msg;
        // more work
    }
Comment 2 Markus Keller CLA 2006-11-19 12:51:34 EST
A common practise to prevent such bugs is to make these fields final. A warning is problematic, since it will inevitably lead to false positives.
Comment 3 Dani Megert CLA 2006-11-20 03:33:14 EST
You can enable the "Parameter is never read" compiler problem.
Comment 4 Martin Aeschlimann CLA 2006-11-21 04:26:30 EST
Moving to jdt.core to decide.
Comment 5 Philipe Mulet CLA 2006-11-21 08:16:58 EST
Comment 3 is the actual feature you are looking for. 
We could special case constructors though.
Comment 6 Christophe Cornu CLA 2006-11-24 13:57:58 EST
Thanks for suggestion in comment 3.