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

[Linux] NPE: Cannot read field "firstFont" because "<local4>" is null

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P4 P4
    • jfx24
    • jfx23
    • javafx
    • None
    • b13
    • linux

      Trying to run any JavaFX application on Linux with prism.useFontConfig=false, fails with a NPE happening in LogicalFont:

      Caused by: java.lang.NullPointerException: Cannot read field "firstFont" because "<local4>" is null
              at javafx.graphics@23-ea/com.sun.javafx.font.LogicalFont.<init>(LogicalFont.java:177)
              at javafx.graphics@23-ea/com.sun.javafx.font.LogicalFont.getLogicalFont(LogicalFont.java:109)
              at javafx.graphics@23-ea/com.sun.javafx.font.LogicalFont.getLogicalFont(LogicalFont.java:149)
              at javafx.graphics@23-ea/com.sun.javafx.font.PrismFontFactory.createFont(PrismFontFactory.java:636)
              at javafx.graphics@23-ea/com.sun.javafx.font.PrismFontLoader.loadFont(PrismFontLoader.java:223)
              at javafx.graphics@23-ea/javafx.scene.text.Font.<init>(Font.java:346)
              at javafx.graphics@23-ea/javafx.scene.text.Font.getDefault(Font.java:110)
              at javafx.graphics@23-ea/javafx.scene.CssStyleHelper.<clinit>(CssStyleHelper.java:1695)
              ... 20 more

      The following simple test can be used to reproduce the issue:

      public class HelloFX extends Application {

          public void start(Stage stage) {
              Scene scene = new Scene(new StackPane());
              stage.setScene(scene);
              stage.show();
          }
      }

      Run it with -Dprism.useFontConfig=false and it will show this fatal exception (the application doesn't show up, the process ends):

      Error: JavaFX detected no fonts! Please refer to release notes for proper font configuration
      Exception in Application start method
      java.lang.reflect.InvocationTargetException
              at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:118)
              at java.base/java.lang.reflect.Method.invoke(Method.java:580)
              at javafx.graphics@23-ea/com.sun.javafx.application.LauncherImpl.launchApplicationWithArgs(LauncherImpl.java:464)
              at javafx.graphics@23-ea/com.sun.javafx.application.LauncherImpl.launchApplication(LauncherImpl.java:364)
              at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:103)
              at java.base/java.lang.reflect.Method.invoke(Method.java:580)
              at java.base/sun.launcher.LauncherHelper$FXHelper.main(LauncherHelper.java:1135)
      Caused by: java.lang.RuntimeException: Exception in Application start method
              at javafx.graphics@23-ea/com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:893)
              at javafx.graphics@23-ea/com.sun.javafx.application.LauncherImpl.lambda$launchApplication$2(LauncherImpl.java:196)
              at java.base/java.lang.Thread.run(Thread.java:1583)
      Caused by: java.lang.ExceptionInInitializerError
              at javafx.graphics@23-ea/javafx.scene.Node.reapplyCss(Node.java:9524)
              at javafx.graphics@23-ea/javafx.scene.Node.reapplyCSS(Node.java:9487)
              at javafx.graphics@23-ea/javafx.scene.Node.invalidatedScenes(Node.java:1071)
              at javafx.graphics@23-ea/javafx.scene.Node.setScenes(Node.java:1136)
              at javafx.graphics@23-ea/javafx.scene.Scene$8.invalidated(Scene.java:1246)
              at javafx.base@23-ea/javafx.beans.property.ObjectPropertyBase.markInvalid(ObjectPropertyBase.java:112)
              at javafx.base@23-ea/javafx.beans.property.ObjectPropertyBase.set(ObjectPropertyBase.java:147)
              at javafx.graphics@23-ea/javafx.scene.Scene.setRoot(Scene.java:1198)
              at javafx.graphics@23-ea/javafx.scene.Scene.<init>(Scene.java:362)
              at javafx.graphics@23-ea/javafx.scene.Scene.<init>(Scene.java:213)
              at hellofx.HelloFX.start(HelloFX.java:53)
              at javafx.graphics@23-ea/com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$9(LauncherImpl.java:839)
              at javafx.graphics@23-ea/com.sun.javafx.application.PlatformImpl.lambda$runAndWait$12(PlatformImpl.java:483)
              at javafx.graphics@23-ea/com.sun.javafx.application.PlatformImpl.lambda$runLater$10(PlatformImpl.java:456)
              at java.base/java.security.AccessController.doPrivileged(AccessController.java:400)
              at javafx.graphics@23-ea/com.sun.javafx.application.PlatformImpl.lambda$runLater$11(PlatformImpl.java:455)
              at javafx.graphics@23-ea/com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:95)
              at javafx.graphics@23-ea/com.sun.glass.ui.gtk.GtkApplication._runLoop(Native Method)
              at javafx.graphics@23-ea/com.sun.glass.ui.gtk.GtkApplication.lambda$runLoop$10(GtkApplication.java:264)
              ... 1 more
      Caused by: java.lang.NullPointerException: Cannot read field "firstFont" because "<local4>" is null
              at javafx.graphics@23-ea/com.sun.javafx.font.LogicalFont.<init>(LogicalFont.java:177)
              at javafx.graphics@23-ea/com.sun.javafx.font.LogicalFont.getLogicalFont(LogicalFont.java:109)
              at javafx.graphics@23-ea/com.sun.javafx.font.LogicalFont.getLogicalFont(LogicalFont.java:149)
              at javafx.graphics@23-ea/com.sun.javafx.font.PrismFontFactory.createFont(PrismFontFactory.java:636)
              at javafx.graphics@23-ea/com.sun.javafx.font.PrismFontLoader.loadFont(PrismFontLoader.java:223)
              at javafx.graphics@23-ea/javafx.scene.text.Font.<init>(Font.java:346)
              at javafx.graphics@23-ea/javafx.scene.text.Font.getDefault(Font.java:110)
              at javafx.graphics@23-ea/javafx.scene.CssStyleHelper.<clinit>(CssStyleHelper.java:1692)
              ... 20 more
      Exception running application hellofx.HelloFX

      It can be reproduced with any JavaFX version on Linux (I am using Ubuntu 22.04.4).

      Related: When running on Android (after JDK-8246104), with the same system property, the exception happens in FTFactory:

      Exception in thread "JavaFX Application Thread" java.lang.NullPointerException
      at com.sun.javafx.font.FontConfigManager.getFileNames(FontConfigManager.java:314)
      at com.sun.javafx.font.freetype.FTFactory.getFallbacks(FTFactory.java:136)
      at com.sun.javafx.font.LogicalFont.getLinkedFonts(LogicalFont.java:214)
      at com.sun.javafx.font.LogicalFont.getNumSlots(LogicalFont.java:223)
      at com.sun.javafx.font.CompositeGlyphMapper.<init>(CompositeGlyphMapper.java:62)
      at com.sun.javafx.font.LogicalFont.getGlyphMapper(LogicalFont.java:440)
      at com.sun.javafx.text.PrismTextLayout.shape(PrismTextLayout.java:917)

      In both cases (LogicalFont and FTFactory), there is a call to FontConfigManager.getFontConfigFont, but then there is no null check, for the possible cases where it might return null.

            jpereda Jose Pereda
            jpereda Jose Pereda
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: