JDK-6487386 : Font.equals() incorrectly returns false if getAttributes() is called on just one of the fonts
  • Type: Bug
  • Component: client-libs
  • Sub-Component: 2d
  • Affected Version: 6,7
  • Priority: P3
  • Status: Closed
  • Resolution: Fixed
  • OS: generic,windows_xp
  • CPU: generic,x86
  • Submitted: 2006-10-27
  • Updated: 2011-03-08
  • Resolved: 2011-03-08
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 6 JDK 7
6u1Fixed 7 b03Fixed
Related Reports
Duplicate :  
Description
This program below incorrectly prints false since JDK 6 b33 in April 2005 :

import java.awt.Font;

public class FNE {

    public static void main(String[] args) throws Exception {
        Font f1 = new Font("Lucida Sans", Font.PLAIN, 12);
        Font cf1 = f1.deriveFont(Font.PLAIN, 12f);
        f1.getAttributes();
        //cf1.getAttributes();
        System.out.println("equal="+f1.equals(cf1));
    }
}

Comments
EVALUATION This was introduced in fixing 4339577: Adding kerning to the text layout process and 4296952 : Cannot underline Font using Map where the way attributes are stored was changed. The field is lazily initialized in fonts that do not get explicitly constructed with attributes. The bug is that the equals() method now returns false if one font has its attribute initialised and the other does not (the field is null), without checking whether the attributes when initialiased are equal.
27-10-2006