timja / jenkins-gh-issues-poc-06-18

0 stars 0 forks source link

[JENKINS-59396] AWT initialized even with -Djava.awt.headless=true #4592

Open timja opened 5 years ago

timja commented 5 years ago

I tried to use AdoptOpenJDK jdk8u222-b10 instead of Oracle JDK 8.

I need to change my JDK, that's not my choice, and I couldn't launch Jenkins because of this issue :

hudson.util.AWTProblem: java.lang.NullPointerException
 at hudson.WebAppMain.contextInitialized(WebAppMain.java:193)
 at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4776)
 at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5240)
 at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
 at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:754)
 at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:730)
 at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:734)
 at org.apache.catalina.startup.HostConfig.deployDescriptor(HostConfig.java:629)
 at org.apache.catalina.startup.HostConfig$DeployDescriptor.run(HostConfig.java:1838)
 at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
 at java.util.concurrent.FutureTask.run(FutureTask.java:266)
 at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
 at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
 at java.lang.Thread.run(Thread.java:748)
Caused by: java.lang.NullPointerException
 at sun.awt.FontConfiguration.getVersion(FontConfiguration.java:1264)
 at sun.awt.FontConfiguration.readFontConfigFile(FontConfiguration.java:219)
 at sun.awt.FontConfiguration.init(FontConfiguration.java:107)
 at sun.awt.X11FontManager.createFontConfiguration(X11FontManager.java:774)
 at sun.font.SunFontManager$2.run(SunFontManager.java:431)
 at java.security.AccessController.doPrivileged(Native Method)
 at sun.font.SunFontManager.(SunFontManager.java:376)
 at sun.awt.FcFontManager.(FcFontManager.java:35)
 at sun.awt.X11FontManager.(X11FontManager.java:57)
 at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
 at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
 at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
 at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
 at java.lang.Class.newInstance(Class.java:442)
 at sun.font.FontManagerFactory$1.run(FontManagerFactory.java:83)
 at java.security.AccessController.doPrivileged(Native Method)
 at sun.font.FontManagerFactory.getInstance(FontManagerFactory.java:74)
 at java.awt.Font.getFont2D(Font.java:491)
 at java.awt.Font.getFamily(Font.java:1220)
 at java.awt.Font.getFamily_NoClientCode(Font.java:1194)
 at java.awt.Font.getFamily(Font.java:1186)
 at java.awt.Font.toString(Font.java:1683)
 at hudson.util.ChartUtil.(ChartUtil.java:260)
 at hudson.WebAppMain.contextInitialized(WebAppMain.java:192)
 ... 13 more

When I rollback to use the Oracle JDK, everything is fine.

The problem seems to be the static initialisation bloc inside hudson.util.ChartUtil :

    static {
try {
    new Font("SansSerif",Font.BOLD,18).toString();
} catch (Throwable t) {
    awtProblemCause = t;
    awtProblem = true;
}
    }
 

With such code, AWT is referenced even with -Djava.awt.headless=true, because it is static.


Originally reported by jbreda, imported from: AWT initialized even with -Djava.awt.headless=true
  • status: Open
  • priority: Major
  • resolution: Unresolved
  • imported: 2022/01/10
timja commented 5 years ago

danielbeck:

Are you sure you're setting the system property correctly? How can you tell?

timja commented 4 years ago

jbreda:

Yes I'm sure : here is the log produces by my Tomcat instance

 

2019-10-11 07:50:40,266 (UTC) - [main] INFO org.apache.catalina.startup.VersionLoggerListener:115 - Command line argument: -Djava.awt.headless=true

timja commented 4 years ago

danielbeck:

Please try this without Tomcat to eliminate a potential source of problems here. /path/to/adoptopenjdk/java -Djava.awt.headless=true -jar /path/to/jenkins.war and nothing else.

 

timja commented 4 years ago

jbreda:

There is no problem without Tomcat : the provided command works almost well.

Despite of this, we don't use the same code to launch the webapp with or without Tomcat :

At this point the problem can be caused by two things (or maybe others I couldn't imagine) :

Moreover, I did a heapdump (when using the Tomcat instance). In this file we can see the system properties.

java.awt.headless appears among them.

Thanks to it, we can tell that Tomcat is not the problem : it doesn't alter the system properties.

I think the static code should be reviewed.

 

timja commented 4 years ago

sao_die:

May be this helps as work-around:

 On Linux systems, the fontconfig.x86_64 package should be installed to avoid a NullPointerException error when the AWT font subsystem is initialized. Work is ongoing at the AdoptOpenJDK project to fix this issue for their OpenJDK binaries.

 

(https://www.eclipse.org/openj9/docs/adoptopenjdk/)

 

timja commented 4 years ago

axmetishe:

Same fix for AWT NPE as sao_die mentioned above can be applied for OpenJDK Runtime Environment AdoptOpenJDK (build 11.0.8+10)

timja commented 3 years ago

JIRAUSER133257:

Thank you sao_die , you save my date. By installing the fontconfig.x86_64, the error is gone.

timja commented 3 years ago

manueljordan:

Hello

 Just to inform I have the same situation at:

In my case for Ubuntu Server 18:04, so the proposed solution was with fontconfig (it because fontconfig.x86_64 does not exist)
Therefore

sudo apt install fontconfig

was used. Working with

java -version
openjdk version "11.0.11" 2021-04-20
OpenJDK Runtime Environment AdoptOpenJDK-11.0.11+9 (build 11.0.11+9)
OpenJDK 64-Bit Server VM AdoptOpenJDK-11.0.11+9 (build 11.0.11+9, mixed mode)

Huge thanks for the solution and a well deserved cold beer for Sascha Dierkes - it is the unique place where the proposed solution works.
I shared it in details on StackOverflow.