United StatesChange Country, Oracle Worldwide Web Sites Communities I am a... I want to...
Bug ID: JDK-6487386 Font.equals() incorrectly returns false if getAttributes() is called on just one of the fonts
JDK-6487386 : Font.equals() incorrectly returns false if getAttributes() is called on just one of the fonts

Details
Type:
Bug
Submit Date:
2006-10-27
Status:
Closed
Updated Date:
2011-03-08
Project Name:
JDK
Resolved Date:
2011-03-08
Component:
client-libs
OS:
generic,windows_xp
Sub-Component:
2d
CPU:
x86,generic
Priority:
P3
Resolution:
Fixed
Affected Versions:
6,7
Fixed Versions:

Related Reports
Backport:
Duplicate:

Sub Tasks

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.
                                     
2006-10-27



Hardware and Software, Engineered to Work Together