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 - [Encapsulate Field] Refactoring does not distinguish between assignment and evaluation
Summary: [Encapsulate Field] Refactoring does not distinguish between assignment and e...
Status: RESOLVED WONTFIX
Alias: None
Product: editor
Classification: Unclassified
Component: Refactoring (show other bugs)
Version: 6.x
Hardware: PC Windows XP
: P3 blocker (vote)
Assignee: issues@java
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2007-03-19 06:04 UTC by kely_garcia
Modified: 2007-04-03 18:02 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 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.