On Tue, 7 Feb 2023 17:20:19 GMT, Alexander Scherbatiy <alex...@openjdk.org> wrote:
>> [JDK-8278549](https://bugs.openjdk.org/browse/JDK-8278549)` UNIX sun/font >> coding misses SUSE distro detection on recent distro SUSE 15` adds SuSE >> detection by checking SLES os name property in `/etc/os-release` file. >> >> `opensuse/leap:15.4` docker defines os name property as `"openSUSE Leap"` in >> `/etc/os-release` file which is not recognized as SuSE. >> >> The issue is reproduced with Oracle jdk-19.0.2 with custom >> fontconfig.SuSE.properties file copied to jdk-19.0.2/lib directory. >> >> The fix checks if os name property from `/etc/os-release` contains `SUSE` >> substring. >> >> Steps to reproduce. >> - Download Oracle jdk-19.0.2 >> - Copy custom >> [fontconfig.SuSE.properties](https://bugs.openjdk.org/secure/attachment/102435/fontconfig.SuSE.properties) >> file to jdk-19.0.2/lib directory. >> - Run the `opensuse/leap:15.4` docker and install freetype and dejavu fonts >> (do not install fontconfig) >> >> docker run --rm --security-opt seccomp=unconfined -it opensuse/leap:15.4 bash >> zypper install -y dejavu-fonts >> zypper install -y freetype2 >> >> - Run HelloImage java sample in the docker >> >> import javax.imageio.ImageIO; >> import java.awt.*; >> import java.awt.image.BufferedImage; >> import java.io.File; >> >> public class HelloImage { >> >> public static void main(String[] args) throws Exception { >> >> BufferedImage buff = new BufferedImage(300, 200, >> BufferedImage.TYPE_INT_RGB); >> Graphics2D g = buff.createGraphics(); >> g.setColor(Color.WHITE); >> g.fillRect(0, 0, buff.getWidth(), buff.getHeight()); >> >> g.setColor(Color.BLUE); >> g.setFont(g.getFont().deriveFont(32f)); >> g.drawString("Hello, Image!", 50, 50); >> g.dispose(); >> >> File file = new File("hello-image.png"); >> ImageIO.write(buff, "png", file); >> } >> } >> >> >> >> ./jdk-19.0.2/bin/javac HelloImage.java >> ./jdk-19.0.2/bin/java HelloImage >> Exception in thread "main" java.lang.NullPointerException: Cannot load from >> short array because "sun.awt.FontConfiguration.head" is null >> at >> java.desktop/sun.awt.FontConfiguration.getVersion(FontConfiguration.java:1261) >> at >> java.desktop/sun.awt.FontConfiguration.readFontConfigFile(FontConfiguration.java:221) >> at >> java.desktop/sun.awt.FontConfiguration.init(FontConfiguration.java:105) >> at >> java.desktop/sun.awt.X11FontManager.createFontConfiguration(X11FontManager.java:706) >> at java.desktop/sun.font.SunFontManager$2.run(SunFontManager.java:352) >> at java.desktop/sun.font.SunFontManager$2.run(SunFontManager.java:309) >> at >> java.base/java.security.AccessController.doPrivileged(AccessController.java:318) >> at java.desktop/sun.font.SunFontManager.<init>(SunFontManager.java:309) >> at java.desktop/sun.awt.FcFontManager.<init>(FcFontManager.java:35) >> at java.desktop/sun.awt.X11FontManager.<init>(X11FontManager.java:56) >> at >> java.desktop/sun.font.PlatformFontInfo.createFontManager(PlatformFontInfo.java:37) >> at >> java.desktop/sun.font.FontManagerFactory.getInstance(FontManagerFactory.java:51) >> at java.desktop/java.awt.Font.getFont2D(Font.java:526) >> at java.desktop/java.awt.Font$FontAccessImpl.getFont2D(Font.java:265) >> at java.desktop/sun.font.FontUtilities.getFont2D(FontUtilities.java:151) >> at >> java.desktop/sun.java2d.SunGraphics2D.checkFontInfo(SunGraphics2D.java:671) >> at >> java.desktop/sun.java2d.SunGraphics2D.getFontInfo(SunGraphics2D.java:837) >> at >> java.desktop/sun.java2d.pipe.GlyphListPipe.drawString(GlyphListPipe.java:46) >> at >> java.desktop/sun.java2d.SunGraphics2D.drawString(SunGraphics2D.java:2931) >> at HelloImage.main(HelloImage.java:17) > > Alexander Scherbatiy has updated the pull request incrementally with one > additional commit since the last revision: > > Extract os name as ID from /etc/os-release file for fonts configuration Could you review the updated fix? - `ID` property from `/etc/os-release` file is used for os name when the `/etc/os-release` file is handled. - `NAME` property for `SUSE` check is left as is to not break the [JDK-8278549](https://bugs.openjdk.org/browse/JDK-8278549) fix. - `extractOsInfo()` method is renamed to `extractInfo()`. It now checks the input string to null and replaces white characters to underscores. - There are operation systems that have both `/etc/lsb-release` and `/etc/os-release` files. For example, Photon OS have: `/etc/os-release` NAME="VMware Photon OS" ID=photon VERSION_ID=4.0 `/etc/lsb-release` DISTRIB_ID="VMware Photon OS" DISTRIB_RELEASE="4.0" The `extractInfo()` method is added for os name/version parsing during `/etc/lsb-release` file handling as well. Some improvements can be added. - May be it has sense to allow to configure os name for `fontconfig.properties` file by a Java property. It allows to use a simple custom os name in the `fontconfig.properties` and reuse the same property file on several systems like SLES, openSUSE Leap, and openSUSE Tumbleweed. - Running a java program with `-Dsun.java2d.debugfonts=true` property lists checked `fontconfig.properties` files: INFO: Looking for text fontconfig file : /build/jdk/images/jdk/lib/fontconfig.opensuse-leap.15.4.properties Feb 07, 2023 5:43:30 PM sun.awt.FontConfiguration findImpl INFO: Looking for binary fontconfig file : /build/jdk/images/jdk/lib/fontconfig.opensuse-leap.15.4.bfc Feb 07, 2023 5:43:30 PM sun.awt.FontConfiguration findImpl It could be a good idea to add logging for os name and version in `setOsNameAndVersion()` method as well. - The code for os name/version detection is duplicated in FcFontConfiguration and MFontConfiguration classes. It would be good to unify them. Though they have different files parsing order: FcFontConfiguration: `lsb-release, redhat-release, SuSE-release, turbolinux-release, fedora-release, os-release` MFontConfiguration: `fedora-release, redhat-release, turbolinux-release, SuSE-release, lsb-release` ------------- PR: https://git.openjdk.org/jdk/pull/12260