Fontconfig issues in Java applications that use fonts

  • Done
  • quality assurance status badge
Details
5 participants
  • Björn Höfling
  • Fabien SK
  • Jonathan Frederickson
  • Leo Prikler
  • Ludovic Courtès
Owner
unassigned
Submitted by
Jonathan Frederickson
Severity
normal
J
J
Jonathan Frederickson wrote on 10 May 2020 17:55
(name . bug-guix)(address . bug-guix@gnu.org)
1589126137.10294.0@terracrypt.net
I realized I forgot to submit a bug report for this after I posted on
help-guix a while back, and looks like it's still an issue, so... I get
a null pointer exception when attempting to run any Java application
that uses fonts. I've attached an example of the error output I get,
and you can find more info in this thread:

jfred@lambdacrypt ~/Downloads/pcgen$ java -jar pcgen.jar
11:52:16.300 INFO main Main:138 Starting PCGen v6.08.00 RC6
11:52:16.390 INFO main LanguageBundle:134 Initialising language bundle with locale en_US.
11:52:16.631 SEVERE main Main:484 Uncaught error - ignoring
java.lang.InternalError: java.lang.reflect.InvocationTargetException
at java.desktop/sun.font.FontManagerFactory$1.run(Unknown Source)
at java.base/java.security.AccessController.doPrivileged(Unknown Source)
at java.desktop/sun.font.FontManagerFactory.getInstance(Unknown Source)
at java.desktop/sun.font.FontUtilities.getFontConfigFUIR(Unknown Source)
at java.desktop/javax.swing.plaf.nimbus.NimbusDefaults.<init>(Unknown Source)
at java.desktop/javax.swing.plaf.nimbus.NimbusLookAndFeel.<init>(Unknown Source)
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.base/java.lang.reflect.Constructor.newInstanceWithCaller(Unknown Source)
at java.base/java.lang.reflect.ReflectAccess.newInstance(Unknown Source)
at java.base/jdk.internal.reflect.ReflectionFactory.newInstance(Unknown Source)
at java.base/java.lang.Class.newInstance(Unknown Source)
at java.desktop/javax.swing.UIManager.setLookAndFeel(Unknown Source)
at pcgen.gui2.plaf.LookAndFeelManager.setLookAndFeel(LookAndFeelManager.java:231)
at pcgen.gui2.plaf.LookAndFeelManager.initLookAndFeel(LookAndFeelManager.java:151)
at pcgen.system.Main.configureUI(Main.java:273)
at pcgen.system.Main.startupWithGUI(Main.java:228)
at pcgen.system.Main.main(Main.java:157)
Caused by: java.lang.reflect.InvocationTargetException
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.base/java.lang.reflect.Constructor.newInstanceWithCaller(Unknown Source)
at java.base/java.lang.reflect.Constructor.newInstance(Unknown Source)
... 19 more
Caused by: java.lang.NullPointerException
at java.desktop/sun.awt.FontConfiguration.getVersion(Unknown Source)
at java.desktop/sun.awt.FontConfiguration.readFontConfigFile(Unknown Source)
at java.desktop/sun.awt.FontConfiguration.init(Unknown Source)
at java.desktop/sun.awt.X11FontManager.createFontConfiguration(Unknown Source)
at java.desktop/sun.font.SunFontManager$2.run(Unknown Source)
at java.base/java.security.AccessController.doPrivileged(Unknown Source)
at java.desktop/sun.font.SunFontManager.<init>(Unknown Source)
at java.desktop/sun.awt.FcFontManager.<init>(Unknown Source)
at java.desktop/sun.awt.X11FontManager.<init>(Unknown Source)
... 24 more
F
F
Fabien SK wrote on 3 Jan 2021 15:48
(address . 41177@debbugs.gnu.org)
11250641-ee7a-94e8-d3c4-ebdabc1c5036@free.fr
I faced the issue when running josm (downloaded from
josm.openstreetmap.de, not the guix package). Using "strace" showed me
that it failed because it cannot load "libfontconfig.so" (it tries in
several directories). If I add the directory of libfontconfig.so to
LD_LIBRARY_PATH, then it starts.
I have limited knowledge about how shared libraries are found. I tried
to understand how "geany" manages to load libfontconfig.so. It looks
like it depends on libgeany, libgtk3 and libpango which depend on
libfontconfig. When I do a "readelf -a" on these libraries, I can see in
their "RUNPATH" the path of "libfontconfig.so":
0x000000000000001d (RUNPATH)            Bibliothèque
runpath:[/gnu/store/avjxs6qgyginkiq6qpk9280zakkaj35h-graphite2-1.3.13/lib:/gnu/store/xwl0p4m34bcan0v9vkjkyzwi6znsv4dm-pixman-0.38.4/lib:/gnu/store/y9fdy234r6hqiacd7hgwlmbdsngbp8p1-fontconfig-2.13.1/lib:…

Regarding Java, I think (but I'm not sure) that it's loaded by
"libawt_xawt.so". In fontpath.c [1], there is a dlopen of libfontconfig.
But if I do a "ldd" on the shared library itself, it looks like it does
not depend on libfontconfig.so.
[1]
Also libfontconfig is not on its RUNPATH:

0x000000000000001d (RUNPATH)            Bibliothèque
runpath:[$ORIGIN:/gnu/store/fa6wj5bxkj5ll1d7292a70knmyl7a0cr-glibc-2.31/lib:/gnu/store/01b4w3m6mp55y531kyi1g8shh722kwqm-gcc-7.5.0-lib/lib:/gnu/store/w09mqfj1yy32r2fr02nndzs34m4f9ipp-libxext-1.3.4/lib:/gnu/store/4ildmh169dixyn05mlgjz07x4d2hcq2g-libx11-1.6.A/lib:/gnu/store/8m6368gv4z10n6i31ppbr8nxziwmlp3f-libxrender-0.9.10/lib:/gnu/store/cgsk20z1gcw78fdm7bwlb2l49xh7bmzk-libxtst-1.2.3/lib:/gnu/store/b4dk2y4vf98dhxnr0p6f5h4d86vqndkc-libxi-1.7.10/lib:/gnu/store/01b4w3m6mp55y531kyi1g8shh722kwqm-gcc-7.5.0-lib/lib/gcc/x86_64-unknown-linux-gnu/7.5.0/../../..]

I'm quite a beginner in term of Guix (I only played with it in a VM),
and I hope this information will be useful to somebody. I don't
understand how the dependencies between executable and libraries are
supposed to be done in Guix. I can see that sometimes in /gnu/store
there are symbolic links of shared libraries into other packages. I
assume that sometimes this RUNPATH is used.
L
L
Ludovic Courtès wrote on 6 Jan 2021 12:05
(name . Fabien SK)(address . fabsk@free.fr)(address . 41177@debbugs.gnu.org)
877doqnx4d.fsf@gnu.org
Hi,

Fabien SK <fabsk@free.fr> skribis:

Toggle quote (8 lines)
> Regarding Java, I think (but I'm not sure) that it's loaded by
> "libawt_xawt.so". In fontpath.c [1], there is a dlopen of
> libfontconfig. But if I do a "ldd" on the shared library itself, it
> looks like it does not depend on libfontconfig.so.
> [1]
> https://github.com/openjdk/jdk16/blob/37043b05576c8b81b43ac41a8f06de0d0bbb3f5b/src/java.desktop/unix/native/common/awt/fontpath.c#L566
> Also libfontconfig is not on its RUNPATH:

Indeed, all the ‘openjdk’ packages have fontconfig has an input, but
‘guix size openjdk | grep fontconfig’ shows it’s not there, meaning that
nothing actually linked against fontconfig.

Perhaps we should patch this ‘fontpath.c’, with ‘substitute*’, so that
it refers to libfontconfig.so by its absolute file name?

Thanks,
Ludo’.
B
B
Björn Höfling wrote on 2 Feb 2021 10:11
(name . Ludovic Courtès)(address . ludo@gnu.org)
20210202101146.1e221a52@alma-ubu.fritz.box
On Wed, 06 Jan 2021 12:05:54 +0100
Ludovic Courtès <ludo@gnu.org> wrote:

Toggle quote (19 lines)
> Hi,
>
> Fabien SK <fabsk@free.fr> skribis:
>
> > Regarding Java, I think (but I'm not sure) that it's loaded by
> > "libawt_xawt.so". In fontpath.c [1], there is a dlopen of
> > libfontconfig. But if I do a "ldd" on the shared library itself, it
> > looks like it does not depend on libfontconfig.so.
> > [1]
> > https://github.com/openjdk/jdk16/blob/37043b05576c8b81b43ac41a8f06de0d0bbb3f5b/src/java.desktop/unix/native/common/awt/fontpath.c#L566
> > Also libfontconfig is not on its RUNPATH:
>
> Indeed, all the ‘openjdk’ packages have fontconfig has an input, but
> ‘guix size openjdk | grep fontconfig’ shows it’s not there, meaning
> that nothing actually linked against fontconfig.
>
> Perhaps we should patch this ‘fontpath.c’, with ‘substitute*’, so that
> it refers to libfontconfig.so by its absolute file name?

We do that for icedtea (i.e. OpenJDK until version 8), but not for
OpenJDK. I applied the same trick for OpenJDK 9 and will no longer get
the NullPointerException.

Let me clean it up a bit and apply it to all later OpenJDKs as well
(might be already done through inheritence, but let me check), then I
will send out a patch.

Björn
-----BEGIN PGP SIGNATURE-----

iF0EARECAB0WIQQiGUP0np8nb5SZM4K/KGy2WT5f/QUCYBkXUwAKCRC/KGy2WT5f
/SvIAJ4wc3LJ+QXm2Q839alqUR+L4dgFgACgifsxhvuksQqSrxdwPjAEvEhjYQU=
=EkXe
-----END PGP SIGNATURE-----


B
B
Björn Höfling wrote on 12 Feb 2021 00:23
(name . Ludovic Courtès)(address . ludo@gnu.org)
20210212002309.75690e60@alma-ubu.fritz.box
On Tue, 2 Feb 2021 10:11:46 +0100
Björn Höfling <bjoern.hoefling@bjoernhoefling.de> wrote:

Toggle quote (14 lines)
> On Wed, 06 Jan 2021 12:05:54 +0100
> Ludovic Courtès <ludo@gnu.org> wrote:

> > Perhaps we should patch this ‘fontpath.c’, with ‘substitute*’, so
> > that it refers to libfontconfig.so by its absolute file name?
>
> We do that for icedtea (i.e. OpenJDK until version 8), but not for
> OpenJDK. I applied the same trick for OpenJDK 9 and will no longer get
> the NullPointerException.
>
> Let me clean it up a bit and apply it to all later OpenJDKs as well
> (might be already done through inheritence, but let me check), then I
> will send out a patch.

-----BEGIN PGP SIGNATURE-----

iF0EARECAB0WIQQiGUP0np8nb5SZM4K/KGy2WT5f/QUCYCW8XQAKCRC/KGy2WT5f
/aaRAJ0YuWVEjlPxTNsyQ2wtmu3YmqglGgCglwH/N7RxlevWLzBrjCOanNjVAAo=
=vvU0
-----END PGP SIGNATURE-----


L
L
Leo Prikler wrote on 12 Feb 2021 11:52
Re: [PATCH 0/2] OpenJDK: Fix NullPointerException when accessing fonts
(name . Björn Höfling)(address . bjoern.hoefling@bjoernhoefling.de)
7cfa2fd2c86b16bee0eeb5e9d9de658e895292ec.camel@student.tugraz.at
Hi Björn

Am Freitag, den 12.02.2021, 00:14 +0100 schrieb Björn Höfling:
Toggle quote (35 lines)
> These two patches fix a NullPointerException in the OpenJDK packages.
>
> The patches apply only to OpenJDK9 and OpenJDK11, but with
> inheritence
> all OpenJDKx with x\in[9..14] are covered.
>
> Here is the bug report:
>
> https://debbugs.gnu.org/cgi/bugreport.cgi?bug=41177
>
> In order to test it you can use the following Main.java:
>
> ~~~~~~
> import java.awt.*;
>
> public class Main {
>
> public static void main(String[] args)
> {
> String fonts[] =
> GraphicsEnvironment.getLocalGraphicsEnvironment().getAvai
> lableFontFamilyNames();
>
> for ( int i = 0; i < fonts.length; i++ )
> {
> System.out.println(fonts[i]);
> }
> }
> }
>
> ~~~~~~~~
> Compile: javac Main.java
> Run: java -cp . Main
>
> It should print a list of the available fonts.
Indeed, that it does. At least for 9 and 11, which I've invoked
directly from their store paths.

I've pushed your patches with small changes to the commit messages and
followed up with an indentation fix.

Regards,
Leo
Closed
B
B
Björn Höfling wrote on 12 Feb 2021 20:59
(name . Leo Prikler)(address . leo.prikler@student.tugraz.at)
20210212205939.7499cadb@alma-ubu
On Fri, 12 Feb 2021 11:52:50 +0100
Leo Prikler <leo.prikler@student.tugraz.at> wrote:

Toggle quote (3 lines)
> I've pushed your patches with small changes to the commit messages and
> followed up with an indentation fix.

Thanks!

Björn
-----BEGIN PGP SIGNATURE-----

iF0EARECAB0WIQQiGUP0np8nb5SZM4K/KGy2WT5f/QUCYCbeLAAKCRC/KGy2WT5f
/fktAKCOAflKrfCOboAiCylI7Fopaq6+uACdF1RrWQ4LaICqj5//wWZwsHyKsts=
=jXbW
-----END PGP SIGNATURE-----


Closed
?