Java Crash libFontParser.dylib TSFNTFont::GetFormat() on macOS

   No ratings yet.
Kelly Heffner Wilkerson

Categories: Development | View Comments

I recently ran into a new JVM crash with a customer, and found that there wasn't much online when I researched the problem. Upon trying to show the first JFrame in the Java program on a Mac, the program closed with a fatal JVM error. Here's the summary from the hotspot vm file, I include the longer stack trace at the end of this post.

# A fatal error has been detected by the Java Runtime Environment:
#
#  SIGBUS (0xa) at pc=0x00007fff4fb28ea3, pid=9663, tid=32787
#
# JRE version: OpenJDK Runtime Environment (11.0.1+13) (build 11.0.1+13)
# Java VM: OpenJDK 64-Bit Server VM (11.0.1+13, mixed mode, tiered, compressed oops, g1 gc, bsd-amd64)
# Problematic frame:
# C  [libFontParser.dylib+0x1ea3]  TSFNTFont::GetFormat() const+0x5b
#

This was on macOS High Sierra, Java 11.0.1+13.

The only mention of the same error I found was this person who encountered the same crash running IntelliJ. Unfortunately, they fixed the issue by reinstalling macOS, which isn't ideal. But, in my searches, I stumbled on this old Apple Communities thread from 2013 that shares the similarity of a SIGBUS crash in TSFNTFont::GetFormat() of libFontParser. In the discussion, they fixed the issue by using Font Book to disable broken broken Arial fonts (because their crash specifically mentions Arial.)

This issue is also fixed by using Font Book to repair/disable broken installed fonts.

To fix the broken fonts, causing the JVM crash in TSFNTFont::GetFormat() of libFontParser.dylib:

  1. Open the Font Book app by using the macOS Spotlight search in the upper right corner. Search for font book and the app should be the top search result.

  2. Select "all fonts" in the left column.

  3. Click any font, then press Command + A to select all of the fonts.

  4. From the File menu, choose Validate Fonts.

  5. Clean up the broken fonts (red icon indicating an error in the validation) by disabling or removing the font.

Digging in to the stack trace of the error, ultimately I found that the error happens while initializing fonts. These fonts are loaded regardless of what fonts are being used in the JFrame.

Stack: [0x0000700002926000,0x0000700002a26000],  sp=0x0000700002a20d50,  free space=1003k
Native frames: (J=compiled Java code, A=aot compiled Java code, j=interpreted, Vv=VM code, C=native code)
C  [libFontParser.dylib+0x1ea3]  TSFNTFont::GetFormat() const+0x5b
C  [libFontParser.dylib+0x1d40]  TTrueTypeFont::IsTrueTypeFont(TSFNTFont const&)+0xe
C  [libFontParser.dylib+0x4e0f7]  TFont::CreateFontEntities(char const*, bool, bool&, short, char const*, bool)+0xc1d
C  [libFontParser.dylib+0x4feb0]  TFont::CreateFontEntitiesForFile(char const*, bool, bool, short, char const*)+0xf0
C  [libFontParser.dylib+0x10a7]  FPFontCreateFontsWithPath+0xa1
C  [CoreGraphics+0x32fb37]  create_private_data_array_with_path+0x1d
C  [CoreGraphics+0x1af27]  CGFontCreateFontsWithPath+0x1a
C  [CoreGraphics+0x1ab74]  CGFontCreateFontsWithURL+0x175
C  [CoreText+0xe6d0c]  CreateFontsWithURL(__CFURL const*, bool)+0xc7
C  [CoreText+0xb224]  CreateFontWithFontURL(__CFURL const*, bool)+0x3a
C  [CoreText+0xe750e]  TCGFontCache::CopyFont(__CFURL const*, bool)+0xa2
C  [CoreText+0xaf49]  TBaseFont::CopyNativeFont() const+0x8d
C  [CoreText+0xae98]  TBaseFont::CopyGraphicsFont() const+0x12
C  [CoreText+0x195b4]  CTFontCopyGraphicsFont+0x74
C  [libawt_lwawt.dylib+0x28f3]  -[AWTFont initWithFont:]+0x5c
C  [libawt_lwawt.dylib+0x2b47]  +[AWTFont awtFontForName:style:]+0xe8
C  [libawt_lwawt.dylib+0x33dc]  Java_sun_font_CFont_createNativeFont+0x50
j  sun.font.CFont.createNativeFont(Ljava/lang/String;I)J+0 java.desktop@11.0.1
J 1816 c1 sun.font.CFont.getWidth()I java.desktop@11.0.1 (198 bytes) @ 0x000000010bd349cc [0x000000010bd347a0+0x000000000000022c]
J 1855 c1 sun.font.FontFamily.preferredWidth(Lsun/font/Font2D;)Z java.desktop@11.0.1 (134 bytes) @ 0x000000010bd53fb4 [0x000000010bd53ea0+0x0000000000000114]
J 1854 c1 sun.font.FontFamily.setFont(Lsun/font/Font2D;I)V java.desktop@11.0.1 (245 bytes) @ 0x000000010bd52edc [0x000000010bd52540+0x000000000000099c]
J 1852 c1 sun.font.CFontManager.registerGenericFont(Lsun/font/Font2D;Z)Lsun/font/Font2D; java.desktop@11.0.1 (170 bytes) @ 0x000000010bd512bc [0x000000010bd509e0+0x00000000000008dc]
J 1840 c1 sun.font.CFontManager.registerFont(Ljava/lang/String;Ljava/lang/String;)V java.desktop@11.0.1 (17 bytes) @ 0x000000010bd49cc4 [0x000000010bd49b60+0x0000000000000164]
v  ~StubRoutines::call_stub
V  [libjvm.dylib+0x3a587a]  JavaCalls::call_helper(JavaValue*, methodHandle const&, JavaCallArguments*, Thread*)+0x21a
V  [libjvm.dylib+0x3e086a]  jni_invoke_nonstatic(JNIEnv_*, JavaValue*, _jobject*, JNICallType, _jmethodID*, JNI_ArgumentPusher*, Thread*)+0x274
V  [libjvm.dylib+0x3e5076]  jni_CallVoidMethodV+0x156
C  [JavaNativeFoundation+0x367b]  JNFCallVoidMethod+0xaf
C  [libawt_lwawt.dylib+0x2f88]  Java_sun_font_CFontManager_loadNativeFonts+0x324
j  sun.font.CFontManager.loadNativeFonts()V+0 java.desktop@11.0.1
j  sun.font.CFontManager$1.run()Ljava/lang/Object;+14 java.desktop@11.0.1
v  ~StubRoutines::call_stub
V  [libjvm.dylib+0x3a587a]  JavaCalls::call_helper(JavaValue*, methodHandle const&, JavaCallArguments*, Thread*)+0x21a
V  [libjvm.dylib+0x41ff2f]  JVM_DoPrivileged+0x6d2
J 1614  java.security.AccessController.doPrivileged(Ljava/security/PrivilegedAction;)Ljava/lang/Object; java.base@11.0.1 (0 bytes) @ 0x0000000112f0d812 [0x0000000112f0d740+0x00000000000000d2]
j  sun.font.CFontManager.loadFonts()V+19 java.desktop@11.0.1
j  sun.font.SunFontManager.findFont2D(Ljava/lang/String;II)Lsun/font/Font2D;+855 java.desktop@11.0.1
j  java.awt.Font.getFont2D()Lsun/font/Font2D;+83 java.desktop@11.0.1
j  java.awt.Font$FontAccessImpl.getFont2D(Ljava/awt/Font;)Lsun/font/Font2D;+1 java.desktop@11.0.1
j  sun.font.FontUtilities.getFont2D(Ljava/awt/Font;)Lsun/font/Font2D;+4 java.desktop@11.0.1
j  sun.font.FontDesignMetrics.initMatrixAndMetrics()V+4 java.desktop@11.0.1
j  sun.font.FontDesignMetrics.<init>(Ljava/awt/Font;Ljava/awt/font/FontRenderContext;)V+62 java.desktop@11.0.1
j  sun.font.FontDesignMetrics.getMetrics(Ljava/awt/Font;Ljava/awt/font/FontRenderContext;)Lsun/font/FontDesignMetrics;+128 java.desktop@11.0.1
j  sun.swing.SwingUtilities2.getFontMetrics(Ljavax/swing/JComponent;Ljava/awt/Font;)Ljava/awt/FontMetrics;+15 java.desktop@11.0.1
j  javax.swing.JComponent.getFontMetrics(Ljava/awt/Font;)Ljava/awt/FontMetrics;+2 java.desktop@11.0.1
j  com.apple.laf.AquaProgressBarUI.getPreferredSize(Ljavax/swing/JComponent;)Ljava/awt/Dimension;+22 java.desktop@11.0.1
j  javax.swing.JComponent.getPreferredSize()Ljava/awt/Dimension;+26 java.desktop@11.0.1
j  java.awt.BorderLayout.preferredLayoutSize(Ljava/awt/Container;)Ljava/awt/Dimension;+157 java.desktop@11.0.1
j  java.awt.Container.preferredSize()Ljava/awt/Dimension;+43 java.desktop@11.0.1
j  java.awt.Container.getPreferredSize()Ljava/awt/Dimension;+1 java.desktop@11.0.1
j  javax.swing.JComponent.getPreferredSize()Ljava/awt/Dimension;+39 java.desktop@11.0.1
j  java.awt.BorderLayout.layoutContainer(Ljava/awt/Container;)V+159 java.desktop@11.0.1
j  java.awt.Container.layout()V+11 java.desktop@11.0.1
j  java.awt.Container.doLayout()V+1 java.desktop@11.0.1
j  java.awt.Container.validateTree()V+47 java.desktop@11.0.1
j  java.awt.Container.validateTree()V+110 java.desktop@11.0.1
j  java.awt.Container.validateTree()V+110 java.desktop@11.0.1
j  java.awt.Container.validateTree()V+110 java.desktop@11.0.1
j  java.awt.Container.validate()V+60 java.desktop@11.0.1
j  java.awt.Container.validateUnconditionally()V+14 java.desktop@11.0.1
j  java.awt.Window.show()V+12 java.desktop@11.0.1
j  java.awt.Component.show(Z)V+5 java.desktop@11.0.1
j  java.awt.Component.setVisible(Z)V+2 java.desktop@11.0.1
j  java.awt.Window.setVisible(Z)V+2 java.desktop@11.0.1
My code that calls JFrame.setVisible(true); :)