Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 280940

Summary: Object comparison instead of value comparison
Product: [Tools] GEF Reporter: Juergen Denner <j.denner>
Component: GEF-Legacy Draw2dAssignee: Marc Gobeil <mgobeil>
Status: RESOLVED FIXED QA Contact:
Severity: normal    
Priority: P3 CC: ahunter.eclipse
Version: 3.5   
Target Milestone: 3.6.0 (Helios) M6   
Hardware: PC   
OS: Windows Vista   
Whiteboard:
Attachments:
Description Flags
patch for setters none

Description Juergen Denner CLA 2009-06-19 14:47:32 EDT
The 3.5 shape class contains the following code:

---
 ...
public void setAlpha(Integer value) {
    if(alpha != value) {
        alpha = value;
        repaint();
    }
}
public void setAlpha(int value) {
    setAlpha(new Integer(value));
}
 ...
---

Invoking setAlpha(255) two times in a row, leads to two repaint calls.
This is because "alpha != value" compare pointers and not values and 255 is always boxed to new Integer.

In our application, setAlpha(255) was invoked within a shapes overwritten paintFigure method. This triggered a repaint and in the end, the application was permanently repainting.

alpha can be null but if it's not null, the value should be compared.

The same applies to setAntialias.

Kind regards,
Jürgen
Comment 1 Marc Gobeil CLA 2009-06-22 09:18:33 EDT
Created attachment 139750 [details]
patch for setters

This should fix it, and also reduce unnecessary object creation in the setter methods for both Alpha and Antialias properties.

I did some quick testing of the patch, but would someone mind double checking the if statements I've added to make sure they don't miss any cases?
Comment 2 Anthony Hunter CLA 2009-07-27 13:13:44 EDT
I think this is good to commit.
Comment 3 Anthony Hunter CLA 2010-02-04 19:18:42 EST
(In reply to comment #2)
> I think this is good to commit.

I cannot recally why we did not commit this.
Comment 4 Anthony Hunter CLA 2010-02-17 22:44:03 EST
Committed to HEAD for 3.6