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 98165

Summary: [Encapsulate Field] Refactoring does not distinguish between assignment and evaluation
Product: editor Reporter: kely_garcia <kely_garcia>
Component: RefactoringAssignee: issues@java <issues>
Status: RESOLVED WONTFIX    
Severity: blocker    
Priority: P3    
Version: 6.x   
Hardware: PC   
OS: Windows XP   
Issue Type: DEFECT Exception Reporter:

Description kely_garcia 2007-03-19 06:04:06 UTC
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.
Comment 1 Jiri Prox 2007-03-19 09:32:41 UTC
Returning value from setter will break java bean pattern.
I'm afraid there is no way how to solve this problem.