United StatesChange Country, Oracle Worldwide Web Sites Communities I am a... I want to...
Bug ID: JDK-6626403 getFontMetrics hangs Java
JDK-6626403 : getFontMetrics hangs Java

Details
Type:
Bug
Submit Date:
2007-11-06
Status:
Closed
Updated Date:
2011-03-07
Project Name:
JDK
Resolved Date:
2011-03-07
Component:
client-libs
OS:
windows_xp
Sub-Component:
2d
CPU:
x86
Priority:
P4
Resolution:
Fixed
Affected Versions:
6
Fixed Versions:

Related Reports
Backport:

Sub Tasks

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.
                                     
2007-11-27



Hardware and Software, Engineered to Work Together