Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Snap not runnable due to NullPointerException in java.desktop/sun.awt.FontConfiguration.getVersion(FontConfiguration.java:1262) #4

Open
brlin-tw opened this issue Dec 30, 2023 · 3 comments
Labels
bug Something isn't working

Comments

@brlin-tw
Copy link
Owner

brlin-tw commented Dec 30, 2023

Run the 4 revision of the snap resulted in the following error:

$ snap run bytecode-viewer
https://the.bytecode.club - Created by @Konloch - Bytecode Viewer 2.9.22, Fat-Jar: true
Exception in thread "main" java.lang.InternalError: java.lang.reflect.InvocationTargetException
        at java.desktop/sun.font.FontManagerFactory$1.run(FontManagerFactory.java:86)
        at java.base/java.security.AccessController.doPrivileged(Native Method)
        at java.desktop/sun.font.FontManagerFactory.getInstance(FontManagerFactory.java:74)
        at java.desktop/sun.font.SunFontManager.getInstance(SunFontManager.java:249)
        at java.desktop/sun.font.FontDesignMetrics.getMetrics(FontDesignMetrics.java:265)
        at java.desktop/sun.swing.SwingUtilities2.getFontMetrics(SwingUtilities2.java:1243)
        at java.desktop/javax.swing.JComponent.getFontMetrics(JComponent.java:1646)
        at java.desktop/javax.swing.plaf.basic.BasicGraphicsUtils.getPreferredButtonSize(BasicGraphicsUtils.java:351)
        at java.desktop/javax.swing.plaf.basic.BasicButtonUI.getPreferredSize(BasicButtonUI.java:474)
        at java.desktop/javax.swing.JComponent.getPreferredSize(JComponent.java:1680)
        at java.desktop/javax.swing.plaf.metal.MetalDesktopIconUI.installComponents(MetalDesktopIconUI.java:86)
        at java.desktop/javax.swing.plaf.basic.BasicDesktopIconUI.installUI(BasicDesktopIconUI.java:83)
        at java.desktop/javax.swing.JComponent.setUI(JComponent.java:685)
        at java.desktop/javax.swing.JInternalFrame$JDesktopIcon.setUI(JInternalFrame.java:2162)
        at java.desktop/javax.swing.JInternalFrame$JDesktopIcon.updateUI(JInternalFrame.java:2210)
        at java.desktop/javax.swing.JInternalFrame$JDesktopIcon.<init>(JInternalFrame.java:2142)
        at java.desktop/javax.swing.JInternalFrame.<init>(JInternalFrame.java:348)
        at the.bytecode.club.bytecodeviewer.gui.VisibleComponent.<init>(VisibleComponent.java:42)
        at the.bytecode.club.bytecodeviewer.gui.WorkPane.<init>(WorkPane.java:58)
        at the.bytecode.club.bytecodeviewer.gui.MainViewerGUI.<init>(MainViewerGUI.java:198)
        at the.bytecode.club.bytecodeviewer.BytecodeViewer.main(BytecodeViewer.java:533)
Caused by: java.lang.reflect.InvocationTargetException
        at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
        at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
        at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
        at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:490)
        at java.desktop/sun.font.FontManagerFactory$1.run(FontManagerFactory.java:84)
        ... 20 more
Caused by: java.lang.NullPointerException
        at java.desktop/sun.awt.FontConfiguration.getVersion(FontConfiguration.java:1262)
        at java.desktop/sun.awt.FontConfiguration.readFontConfigFile(FontConfiguration.java:225)
        at java.desktop/sun.awt.FontConfiguration.init(FontConfiguration.java:107)
        at java.desktop/sun.awt.X11FontManager.createFontConfiguration(X11FontManager.java:719)
        at java.desktop/sun.font.SunFontManager$2.run(SunFontManager.java:379)
        at java.base/java.security.AccessController.doPrivileged(Native Method)
        at java.desktop/sun.font.SunFontManager.<init>(SunFontManager.java:324)
        at java.desktop/sun.awt.FcFontManager.<init>(FcFontManager.java:35)
        at java.desktop/sun.awt.X11FontManager.<init>(X11FontManager.java:56)
        ... 25 more

Seems to be related to NPE at sun.awt.FontConfiguration.getVersion(FontConfiguration.java:1264) when using install4j caused by font config missing · Issue #693 · adoptium/temurin-build.

@brlin-tw brlin-tw added the bug Something isn't working label Dec 30, 2023
@brlin-tw
Copy link
Owner Author

Adding the following prime scriptlet to the main part:

      # Fix Java runtime crashes with java.lang.NullPointerException in
      # java.desktop/sun.awt.FontConfiguration.getVersion(FontConfiguration.java)
      # https://github.com/adoptium/adoptium-support/issues/70
      printf \
        'version=1\nsequence.allfonts=default\n' \
        >usr/lib/jvm/java-11-openjdk-${SNAPCRAFT_TARGET_ARCH}/lib/fontconfig.properties

does resolve the error, however, another error is triggered when launching:

$ snap run bytecode-viewer
https://the.bytecode.club - Created by @Konloch - Bytecode Viewer 2.9.22, Fat-Jar: true
Exception in thread "main" java.lang.Error: Probable fatal error: No physical fonts found.
        at java.desktop/sun.font.SunFontManager.lambda$getDefaultPhysicalFont$0(SunFontManager.java:1110)
        at java.base/java.util.Optional.orElseThrow(Optional.java:408)
        at java.desktop/sun.font.SunFontManager.getDefaultPhysicalFont(SunFontManager.java:1110)
        at java.desktop/sun.font.CompositeFont.doDeferredInitialisation(CompositeFont.java:291)
        at java.desktop/sun.font.CompositeFont.getSlotFont(CompositeFont.java:376)
        at java.desktop/sun.font.CompositeStrike.getStrikeForSlot(CompositeStrike.java:80)
        at java.desktop/sun.font.CompositeStrike.getFontMetrics(CompositeStrike.java:95)
        at java.desktop/sun.font.FontDesignMetrics.initMatrixAndMetrics(FontDesignMetrics.java:360)
        at java.desktop/sun.font.FontDesignMetrics.<init>(FontDesignMetrics.java:351)
        at java.desktop/sun.font.FontDesignMetrics.getMetrics(FontDesignMetrics.java:303)
        at java.desktop/sun.swing.SwingUtilities2.getFontMetrics(SwingUtilities2.java:1243)
        at java.desktop/javax.swing.JComponent.getFontMetrics(JComponent.java:1646)
        at java.desktop/javax.swing.plaf.basic.BasicGraphicsUtils.getPreferredButtonSize(BasicGraphicsUtils.java:351)
        at java.desktop/javax.swing.plaf.basic.BasicButtonUI.getPreferredSize(BasicButtonUI.java:518)
        at java.desktop/javax.swing.JComponent.getPreferredSize(JComponent.java:1680)
        at java.desktop/javax.swing.plaf.metal.MetalDesktopIconUI.installComponents(MetalDesktopIconUI.java:86)
        at java.desktop/javax.swing.plaf.basic.BasicDesktopIconUI.installUI(BasicDesktopIconUI.java:83)
        at java.desktop/javax.swing.JComponent.setUI(JComponent.java:685)
        at java.desktop/javax.swing.JInternalFrame$JDesktopIcon.setUI(JInternalFrame.java:2162)
        at java.desktop/javax.swing.JInternalFrame$JDesktopIcon.updateUI(JInternalFrame.java:2210)
        at java.desktop/javax.swing.JInternalFrame$JDesktopIcon.<init>(JInternalFrame.java:2142)
        at java.desktop/javax.swing.JInternalFrame.<init>(JInternalFrame.java:348)
        at the.bytecode.club.bytecodeviewer.gui.VisibleComponent.<init>(VisibleComponent.java:42)
        at the.bytecode.club.bytecodeviewer.gui.WorkPane.<init>(WorkPane.java:58)
        at the.bytecode.club.bytecodeviewer.gui.MainViewerGUI.<init>(MainViewerGUI.java:198)
        at the.bytecode.club.bytecodeviewer.BytecodeViewer.main(BytecodeViewer.java:533)

Adding the fonts-dejavu-core package to the stage-packages stanza doesn't fix the problem... :-/

@Konloch
Copy link
Collaborator

Konloch commented Dec 30, 2023

Would packing our own custom fonts work? I've been considering adding Noto Font support - https://fonts.google.com/noto/specimen/Noto+Sans+Mono

If we supply these fonts and load them, would this possibly resolve this error? I can build a prototype if this might resolve it. I'll do some more research on my end to attempt to fix this.

Thank you for your assistance / help in fixing this!

@brlin-tw
Copy link
Owner Author

brlin-tw commented Dec 30, 2023

Would packing our own custom fonts work?
If we supply these fonts and load them, would this possibly resolve this error?

I don't think so as snap applications should already have access to the font files in the host system, the problem smells like a packaging bug which I suspect will be resolved via #5.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants