JDK-6497219 : Equal fonts are not equal
  • Type: Bug
  • Component: client-libs
  • Sub-Component: 2d
  • Affected Version: 7
  • Priority: P2
  • Status: Closed
  • Resolution: Duplicate
  • OS: windows_xp
  • CPU: x86
  • Submitted: 2006-11-24
  • Updated: 2011-01-19
  • Resolved: 2006-11-24
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 7
7Resolved
Related Reports
Duplicate :  
Relates :  
Description
Let's see 4 cases:

1) first font is equal to the second one:
        Font f1 = new Font( "serif", Font.BOLD, 12 );
        Font f2 = new Font( "serif", Font.BOLD, 12 );
        System.out.println( f1.equals( f2 ) );
EXPECT: true
ACTUAL: true

2) first font is equal to the second one:
        Font f1 = new Font( "serif", Font.BOLD, 12 ); f1.getAttributes();
        Font f2 = new Font( "serif", Font.BOLD, 12 );
        System.out.println( f1.equals( f2 ) );
EXPECT: true
ACTUAL: false

3) first font is equal to the second one:
        Font f1 = new Font( "serif", Font.BOLD, 12 );
        Font f2 = new Font( "serif", Font.BOLD, 12 ); f2.getAttributes();
        System.out.println( f1.equals( f2 ) );
EXPECT: true
ACTUAL: false

4) first font is equal to the second one:
        Font f1 = new Font( "serif", Font.BOLD, 12 ); f1.getAttributes();
        Font f2 = new Font( "serif", Font.BOLD, 12 ); f2.getAttributes();
        System.out.println( f1.equals( f2 ) );
EXPECT: true
ACTUAL: true

Sources are attached.

Comments
EVALUATION This is a duplicate of 6487386: Font.equals() incorrectly returns false if getAttributes() is called on just one of the fonts This is already fixed in JDK7 (b03?) and is also fixed in JDK 6u1 b01
24-11-2006

EVALUATION When we call font.getAttributes(), font.values private field is created. At the same time Font.equals() method takes this field into consideration, so if font1.values is null and font2.values is not null, then font1.equals(font2) is false.
24-11-2006