Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8071446

isOpenJDK check in sun.font.FontUtilities is unreliable and can crash

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Not an Issue
    • Icon: P3 P3
    • 9
    • 7u71, 8, 9
    • client-libs
    • 2d
    • x86_64
    • linux

      FULL PRODUCT VERSION :
      java version "1.7.0_72"
      Java(TM) SE Runtime Environment (build 1.7.0_72-b14)
      Java HotSpot(TM) 64-Bit Server VM (build 24.72-b04, mixed mode)


      ADDITIONAL OS VERSION INFORMATION :
      Linux atlas 3.13.0-43-generic #72-Ubuntu SMP Mon Dec 8 19:35:06 UTC 2014 x86_64 x86_64 x86_64 GNU/Linux

      EXTRA RELEVANT SYSTEM CONFIGURATION :
      not relevant

      A DESCRIPTION OF THE PROBLEM :
      sun.font.FontUtilities (and anything in java that depends on using a font) checks for the presence of the font file "LucidaSansRegular.ttf" to determine which library to load (if it's oracle or openJDK).

      This will cause an UnsatisfiedLinkError, if you follow the license agreement for redistribution of the JRE. (http://www.oracle.com/technetwork/java/javase/jre-7-readme-430162.html) Specifically, if you remove the "fonts/" location.

      http://grepcode.com/file/repository.grepcode.com/java/root/jdk/openjdk/8-b132/sun/font/FontUtilities.java#127

      Since this file MIGHT ALSO exist in an openJDK distribution, one possible solution would be to just check an env. var instead of testing if the file exists.

      REGRESSION. Last worked in version 6u43

      ADDITIONAL REGRESSION INFORMATION:
      From what I can tell, this was introduced in java 7.

      The problem is at this location in the source code:
      http://grepcode.com/file/repository.grepcode.com/java/root/jdk/openjdk/8-b132/sun/font/FontUtilities.java#127

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      1) delete "LucidaSansRegular.ttf" from the fonts/ location
      2) call FontUtilites.isLogging()
      2a) OR, call ANY public static method in FontUtilties
      2b) OR, create (and render) a simple swing GUI with text in it



      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      A JFrame with a text box.
      ACTUAL -
      nothing

      ERROR MESSAGES/STACK TRACES THAT OCCUR :
      java.lang.UnsatisfiedLinkError: sun.font.FreetypeFontScaler.initIDs(Ljava/lang/Class;)V
      at sun.font.FreetypeFontScaler.initIDs(Native Method)
      at sun.font.FreetypeFontScaler.<clinit>(Unknown Source)
      at java.lang.Class.forName0(Native Method)
      at java.lang.Class.forName(Unknown Source)
      at sun.font.FontScaler.<clinit>(Unknown Source)
      at sun.font.TrueTypeFont.getScaler(Unknown Source)
      at sun.font.FileFontStrike.<init>(Unknown Source)
      at sun.font.FileFont.createStrike(Unknown Source)
      at sun.font.Font2D.getStrike(Unknown Source)
      at sun.font.Font2D.getStrike(Unknown Source)
      at sun.font.CompositeStrike.getStrikeForSlot(Unknown Source)
      at sun.font.CompositeStrike.getFontMetrics(Unknown Source)
      at sun.font.FontDesignMetrics.initMatrixAndMetrics(Unknown Source)
      at sun.font.FontDesignMetrics.<init>(Unknown Source)
      at sun.font.FontDesignMetrics.getMetrics(Unknown Source)
      at sun.swing.SwingUtilities2.getFontMetrics(Unknown Source)
      at javax.swing.JComponent.getFontMetrics(Unknown Source)
      at javax.swing.plaf.synth.SynthGraphicsUtils.getPreferredSize(Unknown Source)
      at javax.swing.plaf.synth.SynthLabelUI.getPreferredSize(Unknown Source)
      at javax.swing.JComponent.getPreferredSize(Unknown Source)
      at java.awt.FlowLayout.preferredLayoutSize(Unknown Source)
      at java.awt.Container.preferredSize(Unknown Source)
      at java.awt.Container.getPreferredSize(Unknown Source)
      at javax.swing.JComponent.getPreferredSize(Unknown Source)
      at java.awt.BorderLayout.preferredLayoutSize(Unknown Source)
      at java.awt.Container.preferredSize(Unknown Source)
      at java.awt.Container.getPreferredSize(Unknown Source)
      at javax.swing.JComponent.getPreferredSize(Unknown Source)
      at javax.swing.JRootPane$RootLayout.preferredLayoutSize(Unknown Source)
      at java.awt.Container.preferredSize(Unknown Source)
      at java.awt.Container.getPreferredSize(Unknown Source)
      at javax.swing.JComponent.getPreferredSize(Unknown Source)
      at java.awt.BorderLayout.preferredLayoutSize(Unknown Source)
      at java.awt.Container.preferredSize(Unknown Source)
      at java.awt.Container.getPreferredSize(Unknown Source)
      at java.awt.Window.pack(Unknown Source)
      at xxxx.util.swing.InputWindow.initGUI(InputWindow.java:127)
      at xxxx.util.swing.InputWindow.<init>(InputWindow.java:44)
      at java.awt.event.InvocationEvent.dispatch(Unknown Source)
      at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
      at java.awt.EventQueue.access$200(Unknown Source)
      at java.awt.EventQueue$3.run(Unknown Source)
      at java.awt.EventQueue$3.run(Unknown Source)
      at java.security.AccessController.doPrivileged(Native Method)
      at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
      at java.awt.EventQueue.dispatchEvent(Unknown Source)
      at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
      at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
      at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
      at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
      at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
      at java.awt.EventDispatchThread.run(Unknown Source)

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      public class InputWindow extends JFrame {
        public static void main(String[] args) {
              EventQueue.invokeLater(new Runnable() {
                  @Override
                  public void run() {
                      try {
                          InputWindow window = new InputWindow();
                          window.setVisible(true);
                      } catch (Exception e) {
                          e.printStackTrace();
                      }
                  }
              });
          }


       public InputWindow() {
             setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
              setResizable(false);
              setBounds(0, 0, 360, 187);

              JPanel contentPane = new JPanel();
              contentPane.setBorder(null);
              contentPane.setLayout(new BorderLayout(0, 0));
              setContentPane(contentPane);

             JPanel dialogPanel = new JPanel();
             dialogPanel.setBackground(Color.WHITE);
             contentPane.add(dialogPanel, BorderLayout.CENTER);

             JLabel label = new JLabel("Enter your user name");
             dialogPanel.add(label);
             pack();
          }
      }
      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      Don't delete "LucidaSansRegular.ttf", or if using openJDK, DO NOT have that font in the "fonts/" directory.

      Cannot make progress if using LucidaSansRegular.ttf on openJDK (or, conversely, not using - and deleting - LucidaSansRegular.ttf on oracleJRE)

            prr Philip Race
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated:
              Resolved: