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.

Bug 257990 - Incorrect "Field Can Be Final" transform for comma separated field declarations
Summary: Incorrect "Field Can Be Final" transform for comma separated field declarations
Status: RESOLVED FIXED
Alias: None
Product: java
Classification: Unclassified
Component: Hints (show other bugs)
Version: 8.1
Hardware: PC Windows 10 x64
: P2 normal (vote)
Assignee: Svata Dedic
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2016-02-15 13:32 UTC by Crydust
Modified: 2016-03-03 02:05 UTC (History)
0 users

See Also:
Issue Type: DEFECT
Exception Reporter:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Crydust 2016-02-15 13:32:13 UTC
The "Field Can Be Final" transform ignores the comma operator.
This makes all fields on the same line final and causes compilation errors.

Reason for P2: Inspect and Transform should not add compilation errors.

before: 
public class Example {
    // Field a can be final
    private int a, b;
    public Example(int a, int b) {
        this.a = a;
    }
    public int getA() {
        return a;
    }
    public int getB() {
        return b;
    }
    public void setB(int b) {
        this.b = b;
    }
}

after:
public class Example {
    private final int a, b;
    public Example(int a, int b) {
        this.a = a;
        // ERROR: variable b might not have been initialized
    }
    public int getA() {
        return a;
    }
    public int getB() {
        return b;
    }
    public void setB(int b) {
        // ERROR: cannot assign a value to final variable b
        this.b = b;
    }
}

expected:
public class Example {
    private final int a;
    private int b;
    public Example(int a, int b) {
        this.a = a;
    }
    public int getA() {
        return a;
    }
    public int getB() {
        return b;
    }
    public void setB(int b) {
        this.b = b;
    }
}
Comment 1 Svata Dedic 2016-02-29 15:04:00 UTC
The reason is that rewrite tries to be as small as possible. In the case of fields in a field group (common declarator), the "smallest" must be extended to the common fields parent.

Fixed hopefully modifier, annotation and type changes for field groups in jet-main#16112f3e2972
Comment 2 Quality Engineering 2016-03-03 02:05:57 UTC
Integrated into 'main-silver', will be available in build *201603030002* on http://bits.netbeans.org/dev/nightly/ (upload may still be in progress)

Changeset: http://hg.netbeans.org/main-silver/rev/16112f3e2972
User: Svata Dedic <sdedic@netbeans.org>
Log: #257990: rewrite anywhere in declarator of a variable which is part of variable group will run rewrite on the variable's parent