JDK-8368882 : NPE during text drawing on machine with JP locale
  • Type: Bug
  • Component: client-libs
  • Sub-Component: 2d
  • Affected Version: 17,21,25,26
  • Priority: P4
  • Status: Resolved
  • Resolution: Fixed
  • OS: windows
  • Submitted: 2025-09-29
  • Updated: 2025-12-03
  • Resolved: 2025-11-03
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 17 JDK 21 JDK 25 JDK 26
17.0.19Fixed 21.0.11Fixed 25.0.3Fixed 26 b23Fixed
Related Reports
Relates :  
Description
This issue cannot be reproduced on a clean machine and requires several prerequisites.
1. JP should be the default local on the Windows machine.
2. The EUDC font should be installed (created with eudcedit.exe).
3. The fallback font is present at <jdk>/lib/fonts.

The Japanese locale (https://github.com/openjdk/jdk/blob/63688d894e2157bb091be3aa62946f7e5830f384/src/java.desktop/windows/native/libawt/windows/awt_Win32GraphicsEnv.cpp#L244) and the EUDC font (which is not present by default) execute a branch in the CompositeFont constructor that contains a bug (https://github.com/openjdk/jdk/blob/63688d894e2157bb091be3aa62946f7e5830f384/src/java.desktop/share/classes/sun/font/CompositeFont.java#L118) involving deferred font initialisation. The initialisation loop should install false only for the EUDC font instantiated a few lines above. 
The reason the NPE is not shown without the fallback fonts is the guard at CompositeFont.getSlotFont (https://github.com/openjdk/jdk/blob/63688d894e2157bb091be3aa62946f7e5830f384/src/java.desktop/share/classes/sun/font/CompositeFont.java#L383). I'm not very familiar with the font subsystem, but those fonts are installed without component names (https://github.com/openjdk/jdk/blob/63688d894e2157bb091be3aa62946f7e5830f384/src/java.desktop/share/classes/sun/awt/FontConfiguration.java#L1055). So that findFont2D returns null, resulting in a NPE.

2 09:58:13.032625001 GUI_COMMON:://CommonGuiUtils setText: caught exception :REAL_EXCEPTION:: Cannot invoke "sun.font.PhysicalFont.getMapper()" because the return value of "sun.font.CompositeFont.getSlotFont(int)" is null
2     java.lang.NullPointerException: Cannot invoke "sun.font.PhysicalFont.getMapper()" because the return value of "sun.font.CompositeFont.getSlotFont(int)" is null
2         at java.desktop/sun.font.CompositeGlyphMapper.getSlotMapper(Unknown Source)
2         at java.desktop/sun.font.CompositeGlyphMapper.convertToGlyph(Unknown Source)
2         at java.desktop/sun.font.CompositeGlyphMapper.charToGlyph(Unknown Source)
2         at java.desktop/sun.font.FontRunIterator.next(Unknown Source)
2         at java.desktop/sun.font.GlyphLayout.layout(Unknown Source)
2         at java.desktop/sun.font.ExtendedTextSourceLabel.createGV(Unknown Source)
2         at java.desktop/sun.font.ExtendedTextSourceLabel.getGV(Unknown Source)
2         at java.desktop/sun.font.ExtendedTextSourceLabel.createCharinfo(Unknown Source)
2         at java.desktop/sun.font.ExtendedTextSourceLabel.getCharinfo(Unknown Source)
2         at java.desktop/sun.font.ExtendedTextSourceLabel.getLineBreakIndex(Unknown Source)
2         at java.desktop/java.awt.font.TextMeasurer.calcLineBreak(Unknown Source)
2         at java.desktop/java.awt.font.TextMeasurer.getLineBreakIndex(Unknown Source)
2         at java.desktop/java.awt.font.LineBreakMeasurer.nextOffset(Unknown Source)
2         at java.desktop/java.awt.font.LineBreakMeasurer.nextLayout(Unknown Source)
2         at java.desktop/javax.swing.text.TextLayoutStrategy.sync(Unknown Source)

Comments
[jdk25u-fix-request] Approval Request from snazarkin Fix the bug in the edge case of font rendering code. Tested with reproducer from the bug report
06-11-2025

[jdk17u-fix-request] Approval Request from snazarkin Fix the bug in the edge case of font rendering code. Tested with reproducer from the bug report.
05-11-2025

A pull request was submitted for review. Branch: master URL: https://git.openjdk.org/jdk17u-dev/pull/4159 Date: 2025-11-05 11:12:29 +0000
05-11-2025

[jdk21u-fix-request] Approval Request from snazarkin Fix the bug in the edge case of font rendering code. Tested with reproducer from the bug report.
05-11-2025

A pull request was submitted for review. Branch: master URL: https://git.openjdk.org/jdk21u-dev/pull/2448 Date: 2025-11-05 10:43:11 +0000
05-11-2025

Changeset: 4520983e Branch: master Author: Sergey Nazarkin <snazarki@openjdk.org> Committer: Dmitry Cherepanov <dcherepanov@openjdk.org> Date: 2025-11-03 12:56:42 +0000 URL: https://git.openjdk.org/jdk/commit/4520983e8e5fcfb22e04508d50676df6831fa636
03-11-2025

Attached simplified test with OS preparation/cleanup.
29-10-2025

This issue can also be reproduced on the host with the EN_US locale. All other prerequisites remain.
21-10-2025

A pull request was submitted for review. Branch: master URL: https://git.openjdk.org/jdk/pull/27551 Date: 2025-09-29 16:15:45 +0000
29-09-2025