Reputation: 2977
We just upgraded a server from RHEL v7.3
to v7.4
.
This simple program works in RHEL v7.3 and fails in v7.4
public class TestJava {
public static void main(String[] args) {
Font font = new Font("SansSerif", Font.PLAIN, 12);
FontRenderContext frc = new FontRenderContext(null, false, false);
TextLayout layout = new TextLayout("\ude00", font, frc);
layout.getCaretShapes(0);
System.out.println(layout);
}
}
The exception in RHEL 7.4 is :
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 0
at sun.font.CompositeStrike.getStrikeForSlot(CompositeStrike.java:75)
at sun.font.CompositeStrike.getFontMetrics(CompositeStrike.java:93)
at sun.font.Font2D.getFontMetrics(Font2D.java:415)
at java.awt.Font.defaultLineMetrics(Font.java:2176)
at java.awt.Font.getLineMetrics(Font.java:2283)
at java.awt.font.TextLayout.fastInit(TextLayout.java:598)
at java.awt.font.TextLayout.<init>(TextLayout.java:393)
Te result on RHEL v7.3 is:
sun.font.StandardTextSource@7ba4f24f[start:0, len:1, cstart:0, clen:1, chars:"de00", level:0, flags:0, font:java.awt.Font[family=SansSerif,name=SansSerif,style=plain,size=12], frc:java.awt.font.FontRenderContext@c14b833b, cm:sun.font.CoreMetrics@412ae196]
The update of RHEL v7.4
includes an update of openjdk
from 1.8.0.131
to 1.8.0.141
but this does not seems to be related to the version of openjdk
, as the problem is the same with the IBM JDK
coming with WebSphere v9.0
(v1.8.0 SR4 FP6
). With the same version of the IBM JDK
on a RHEL v7.3
and RHEL v7.4
server, the program works in RH 7.3 and fails in RH 7.4 the same way as with openjdk
Any idea what's going on?
Upvotes: 10
Views: 22150
Reputation: 2977
We finally found it !
RHEL v7.4 (upgraded from v7.3 or fresh install) comes with package stix-fonts
.
When this package is installed, the default font changed from Utopia
to STIX
So, java now default fonts are mapped to STIX
, including thesans-serif
font family
For whatever reason, the STIX
fonts does not seem to play well with java (openjdk
+ IBM JDK
) and cause exceptions and bad calculated artefacts positionning when using java.awt
, which is the case with JasperReports
We ended creating a file name /etc/fonts/local.conf
with this in order to force back Utopia
as the default font, used by java..
<?xml version='1.0'?>
<!DOCTYPE fontconfig SYSTEM 'fonts.dtd'>
<fontconfig>
<alias>
<family>serif</family>
<prefer><family>Utopia</family></prefer>
</alias>
<alias>
<family>sans-serif</family>
<prefer><family>Utopia</family></prefer>
</alias>
<alias>
<family>monospace</family>
<prefer><family>Utopia</family></prefer>
</alias>
<alias>
<family>dialog</family>
<prefer><family>Utopia</family></prefer>
</alias>
<alias>
<family>dialoginput</family>
<prefer><family>Utopia</family></prefer>
</alias>
</fontconfig>
[EDITED 2018-10-22]
It seems the bug is fixed in JDK 1.8.192: https://bugs.java.com/view_bug.do?bug_id=JDK-8188030
[EDITED 2019-06-28]
There is now a fix to work around the problem included in IBM JDK v8.05.37
http://www-01.ibm.com/support/docview.wss?uid=swg1IJ16655
Upvotes: 20
Reputation: 121
If someone is having problems running an application on a clean Linux server instance, run the command fc-list and verify if it has multiple fonts and from different folders, in my case, I had some extra fonts in the path /usr/share/X11/fonts/Type1/, I removed everything on the folder, and the problem was solved.
Upvotes: 0
Reputation: 137
We are not able to use font sans serif after the upgrade with OpenJDK or IBM JDK.
New Exception using fonts libraries in openjdk 1.8.0.141-2 . Resolution The issue is fixed in java-1.8.0-openjdk-1.8.0.151-1.b12.el7_4.x86_64 . RHSA-2017:2998 - Security Advisory Workaround
It is observed that in some scenarios installing dejavu-serif-fonts fixes the problem.
Upvotes: 7
Reputation: 41
if you only install any other font like "dejavu-serif-fonts" the problem will be solved. Or you do the workaroundwith the "local.conf" file. RedHat has listet the problem as a bug in 7.4 and is searching for a real solution and dependencies: have a look here: https://bugzilla.redhat.com/show_bug.cgi?id=1479563
Upvotes: 4