java 将 RHEL 从 7.3 升级到 7.4:sun.font.CompositeStrike.getStrikeForSlot 中的 ArrayIndexOutOfBoundsException

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/45569367/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-11-03 08:45:57  来源:igfitidea点击:

Upgrade RHEL from 7.3 to 7.4: ArrayIndexOutOfBoundsException in sun.font.CompositeStrike.getStrikeForSlot

javaawtredhatopenjdkibm-jdk

提问by titou10

We just upgraded a server from RHEL v7.3to v7.4.

我们刚刚将服务器从 升级RHEL v7.3v7.4.

This simple program works in RHEL v7.3 and fails in v7.4

这个简单的程序在 RHEL v7.3 中运行,在 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 :

RHEL 7.4 中的例外是:

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:

在 RHEL v7.3 上的结果是:

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.4includes an update of openjdkfrom 1.8.0.131to 1.8.0.141but this does not seems to be related to the version of openjdk, as the problem is the same with the IBM JDKcoming with WebSphere v9.0(v1.8.0 SR4 FP6). With the same version of the IBM JDKon a RHEL v7.3and RHEL v7.4server, the program works in RH 7.3 and fails in RH 7.4 the same way as with openjdk

的更新RHEL v7.4包括openjdk1.8.0.131到的更新,1.8.0.141但这似乎与 的版本无关openjdk,因为问题与IBM JDK带有WebSphere v9.0( v1.8.0 SR4 FP6)的更新相同。IBM JDK在 aRHEL v7.3RHEL v7.4服务器上使用相同版本的程序,该程序在 RH 7.3 中运行,但在 RH 7.4 中失败的方式与openjdk

Any idea what's going on?

知道发生了什么吗?

回答by titou10

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 Utopiato STIXSo, java now default fonts are mapped to STIX, including thesans-seriffont family
For whatever reason, the STIXfonts 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.confwith this in order to force back Utopiaas the default font, used by java..

我们终于找到了!
RHEL v7.4(从 v7.3 升级或全新安装)随附包stix-fonts.
安装此包后,默认字体从 更改UtopiaSTIX因此,java 现在将默认字体映射为STIX,包括sans-serif字体系列
无论出于何种原因,这些STIX字体似乎与 java ( openjdk+ IBM JDK) 配合不佳并导致异常和计算错误使用时定位java.awt,这是JasperReports
我们结束创建文件名的情况,/etc/fonts/local.conf以强制返回Utopia为默认字体,由 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

[编辑 2018-10-22]
似乎该错误已在 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

[编辑 2019-06-28]
现在有一个修复程序可以解决 IBM JDK v8.05.37 http://www-01.ibm.com/support/docview.wss?uid=swg1IJ16655 中包含的问题

回答by ALi Maken

Environment RHEL 7.4

环境 RHEL 7.4

We are not able to use font sans serif after the upgrade with OpenJDK or IBM JDK.

使用 OpenJDK 或 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

在 openjdk 1.8.0.141-2 中使用字体库的新异常。解决方法 该问题已在 java-1.8.0-openjdk-1.8.0.151-1.b12.el7_4.x86_64 中修复。RHSA-2017:2998 - 安全咨询解决方法

It is observed that in some scenarios installing dejavu-serif-fonts fixes the problem.

据观察,在某些情况下,安装 dejavu-serif-fonts 可以解决该问题。

yum install dejavu-serif-fonts

yum 安装 dejavu-serif-fonts

回答by kfu

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

如果您只安装任何其他字体,如“dejavu-serif-fonts”,问题将得到解决。或者您使用“local.conf”文件进行变通。RedHat 已将该问题列为 7.4 中的错误,并正在寻找真正的解决方案和依赖项:请看这里:https://bugzilla.redhat.com/show_bug.cgi?id=1479563

回答by José Oliveira

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.

如果有人在干净的 Linux 服务器实例上运行应用程序时遇到问题,请运行命令 fc-list 并验证它是否有多种字体和来自不同的文件夹,在我的情况下,我在路径 /usr/share/ 中有一些额外的字体X11/fonts/Type1/,我把文件夹里的东西都去掉了,问题解决了。