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 256239 - Insert getter and setter can produce invalid Java when encapulate fields is selected.
Summary: Insert getter and setter can produce invalid Java when encapulate fields is s...
Status: NEW
Alias: None
Product: java
Classification: Unclassified
Component: Refactoring (show other bugs)
Version: 8.1
Hardware: PC Windows 10
: P3 normal (vote)
Assignee: Ralph Ruijs
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2015-10-28 21:36 UTC by peterhull90
Modified: 2015-10-29 10:07 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 peterhull90 2015-10-28 21:36:10 UTC
Product Version = NetBeans IDE 8.1 RC2 (Build 201510122201)
Operating System = Windows 10 version 10.0 running on amd64
Java; VM; Vendor = 1.8.0_66
Runtime = Java HotSpot(TM) 64-Bit Server VM 25.66-b17

Reproducibility: Happens every time

STEPS:
Create Java class like this:
public class NewClass {
      int x, y;
    }
Call up 'Generate' menu (ALT+INSERT)
Select 'Getter and Setter...'
Select all fields and select 'encapsulate fields'
Press 'Generate'

ACTUAL:
Modifications to class look like this:
public class NewClass {
    private int x;
    int y;

    public int getX() {
        return x;
    }

    public void setX(int x) {
        this.x = x;
    }
    private int y;

    public int getY() {
        return y;
    }

    public void setY(int y) {
        this.y = y;
    }
}

Note double definition of 'y'

EXPECTED:
Modifications to class look like this:
public class NewClass {
    private int x;

    public int getX() {
        return x;
    }

    public void setX(int x) {
        this.x = x;
    }
    private int y;

    public int getY() {
        return y;
    }

    public void setY(int y) {
        this.y = y;
    }
}

WORKROUND:
Don't declare > 1 field per line
Comment 1 Jiri Prox 2015-10-29 09:56:02 UTC
reproducible