Eclipse Bug - Encapsulate Field
Found this bug in Eclipse today while using the Encapsulate field functionality.
Eclipse Version: Version: 3.1.0
Build id: 200412162000
Create this simple class in eclipse -
public class TestEncapsulate {
String a, b;
}
1) Select the Field a
2) Right-click and select Refactor -> Encapsulate Field.
3) Click Ok.
4) The following code is generated -
public class TestEncapsulate {
String b;
private int a;
/**
* @param a The a to set.
*/
void setA(String a) {
this.a = a;
}
/**
* @return Returns the a.
*/
String getA() {
return a;
}
}
Problems
a) The field was changed to a private field even though it was package-private earlier.
This is ok by me, since I typically keep the fields as private.
b) The data type was changed from String to int!!!
This is crazy!
The encapsulate field works fine when there is only one field delared in one line (String a;)
It breaks in the above code for both fields 'a' & 'b' declared in a single line and the fields are non-private (i.e., public, protected or package-private). The type of the field does not matter (of course, if the field type is int, point b above will not hold).
I have reported this Encapsulate field bug.
Found this bug in Eclipse today while using the Encapsulate field functionality.
Eclipse Version: Version: 3.1.0
Build id: 200412162000
Create this simple class in eclipse -
public class TestEncapsulate {
String a, b;
}
1) Select the Field a
2) Right-click and select Refactor -> Encapsulate Field.
3) Click Ok.
4) The following code is generated -
public class TestEncapsulate {
String b;
private int a;
/**
* @param a The a to set.
*/
void setA(String a) {
this.a = a;
}
/**
* @return Returns the a.
*/
String getA() {
return a;
}
}
Problems
a) The field was changed to a private field even though it was package-private earlier.
This is ok by me, since I typically keep the fields as private.
b) The data type was changed from String to int!!!
This is crazy!
The encapsulate field works fine when there is only one field delared in one line (String a;)
It breaks in the above code for both fields 'a' & 'b' declared in a single line and the fields are non-private (i.e., public, protected or package-private). The type of the field does not matter (of course, if the field type is int, point b above will not hold).
I have reported this Encapsulate field bug.
0 Comments:
Post a Comment
<< Home