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.
Build ID: 200609161800 (Netbeans 6.0 M3) Steps to reproduce: Apply Encapsulate Field refactoring on the following input program: public class A { private boolean theField; void method_A(){ if (theField = true){ // do something } } } Encapsulate Field refactoring produces the erroneous code (uncompilable): public class A { private boolean theField; void method_A(){ if (setTheField(true)){ // do something } } public boolean isTheField() { return theField; } public void setTheField(boolean theField) { this.theField = theField; } } Possible reason: the refactoring engine is not able to distinguish between an assignment (in the if's condition) and a boolean evaluation (again in the if's condition). Solution: if the setter method would return the field, the refactored code would compile and be correct.
Returning value from setter will break java bean pattern. I'm afraid there is no way how to solve this problem.