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

[Linux] AWT should start in Headless mode if headful AWT library not installed

XMLWordPrintable

    • Icon: CSR CSR
    • Resolution: Unresolved
    • Icon: P4 P4
    • 17-pool
    • client-libs
    • None
    • behavioral
    • minimal
    • Hide
      It only affects headless builds of the JDK, and it would make the check more correct.

      Previously, `java.awt.GraphicsEnvironment#isHeadless` may return `false` in an environment that doesn't have the `libawt_xawt.so` library available. If the user didn't try to load AWT following that check then nothing changes, and if the user did try to load AWT after that call then the user will not run into the exception anymore (as they won't try to load AWT).
      Show
      It only affects headless builds of the JDK, and it would make the check more correct. Previously, `java.awt.GraphicsEnvironment#isHeadless` may return `false` in an environment that doesn't have the `libawt_xawt.so` library available. If the user didn't try to load AWT following that check then nothing changes, and if the user did try to load AWT after that call then the user will not run into the exception anymore (as they won't try to load AWT).

      Summary

      Fix headless detection when AWT library not installed

      Problem

      Currently on jdk17u, a call to java.awt.GraphicsEnvironment#isHeadless will return true only if the DISPLAY environment variable is not defined. When this environment variable is defined but the JDK has been built in headless mode, this method will return false, leading some code to try to load the AWT libraries. However, a JDK built in headless mode does not have these libraries. This will then lead to throwing a java.lang.UnsatisfiedLinkError: Can't load library: /path/to/lib/libawt_xawt.so which will generally not be handled.

      That case if being met in some jpackage test cases in OpenJDK, so trying to run the jpackage test suite on jdk17u will lead to the test failing due to this exception, even though the exact same tests work perfectly fine on JDK 19 and later

      Solution

      The solution has already been merged into JDK 19 with https://bugs.openjdk.org/browse/JDK-8286447.

      Specification

      The change consists in backporting the fix for https://bugs.openjdk.org/browse/JDK-8286447 to jdk17u-dev. It will extend the check for headless builds to the presence of libawt_xawt.so on the library path, leading to stricter headless check. That would lead java.awt.GraphicsEnvironment#isHeadless to return true in stricter but more correct cases.

            luhenry Ludovic Henry
            kcr Kevin Rushforth
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated: