Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8370563

21's API appears to lack an expected null check present in older versions.

XMLWordPrintable

      ADDITIONAL SYSTEM INFORMATION :
      openjdk version "17.0.16" 2025-07-15
      OpenJDK Runtime Environment Temurin-17.0.16+8 (build 17.0.16+8)
      OpenJDK 64-Bit Server VM Temurin-17.0.16+8 (build 17.0.16+8, mixed mode, sharing)

      openjdk version "21.0.8" 2025-07-15 LTS
      OpenJDK Runtime Environment Temurin-21.0.8+9 (build 21.0.8+9-LTS)
      OpenJDK 64-Bit Server VM Temurin-21.0.8+9 (build 21.0.8+9-LTS, mixed mode, sharing)

      A DESCRIPTION OF THE PROBLEM :
      When I try to call the getFontMetrics() method of javax.swing.DebugGraphics (which is under the java.desktop module), I've found that the behavior in OpenJDK 21 is different from other OpenJDK versions.

      For example, OpenJDK 8 reports a NullPointerException, which is because getFontMetrics attempts to access a null object. OpenJDK 11 and OpenJDK 17 provide a more detailed error message: Cannot invoke "java.awt.Graphics.getFontMetrics()" because "this.graphics" is null.

      However, when executing this with OpenJDK 21, it produces no output at all. Does this imply that the check for this condition is missing in OpenJDK 21?

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      Exception in thread "main" java.lang.NullPointerException

      ---------- BEGIN SOURCE ----------
      import javax.swing.DebugGraphics;

      public class test {
          public static void main(String[] var0) {
              DebugGraphics var = new DebugGraphics();
              var.getFontMetrics();
          }
      }

      ---------- END SOURCE ----------

            Unassigned Unassigned
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: