JDK-6626403 : getFontMetrics hangs Java
  • Type: Bug
  • Component: client-libs
  • Sub-Component: 2d
  • Affected Version: 6
  • Priority: P4
  • Status: Closed
  • Resolution: Fixed
  • OS: windows_xp
  • CPU: x86
  • Submitted: 2007-11-06
  • Updated: 2011-03-07
  • Resolved: 2011-03-07
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
6u10Fixed 7 b28Fixed
Description
FULL PRODUCT VERSION :
Java 1.6.0 with Sun Microsystems Inc. Java HotSpot(TM) Client VM mixed mode

ADDITIONAL OS VERSION INFORMATION :
Windows XP
Windows Vista

A DESCRIPTION OF THE PROBLEM :
Our customer is Motorola and they have their own Motorola font.
When we call getFontMetrics on the Mortorola font, Java hangs.

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
I have the Motorola font.  Please email me for the font.
Run the test code with Motorola7.ttf in the Windows\Fonts directory.

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Not a hang.

REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
import javax.swing.*;
import java.awt.Font;
import java.awt.GraphicsConfiguration;
import java.awt.GraphicsDevice;
import java.awt.GraphicsEnvironment;

   public class fontbug {

     public static void main(String args[]) {
           GraphicsEnvironment env = GraphicsEnvironment.getLocalGraphicsEnvironment();
           String[] fonts = env.getAvailableFontFamilyNames();
           String thisFont;
           Font testFont;
           JPanel testPanel = new JPanel();
           for (int i = 0; i < fonts.length; i++) {
                thisFont = fonts[i];
  
                if (thisFont != null && !thisFont.equals(""))
                {
                    System.out.println("Font name = " + thisFont );
                    // Use a plain style and size 10, just to see if the font has a width or height.
                    testFont = new Font(thisFont, Font.PLAIN, 10);
                    if (testPanel.getFontMetrics(testFont).charWidth('n') != 0  && testPanel.getFontMetrics(testFont).getHeight() != 0 )
                    {
     
                    }
                }
            }
       
       }
    }
---------- END SOURCE ----------

Comments
EVALUATION Font has only few defined glyphs and they all are "special". Attempt to calculate global hints result in the infinite loop because heuristics are not applicable and number of glyph is too small (so iteration step is 0). Proposed fix is to make sure increment is not zero.
27-11-2007