Closed
Description
JVM Version: 1.8.0_77-internal-alpine-r0-b03
INFO [CaptchaImpl] Initializing com.liferay.portal.captcha.simplecaptcha.SimpleCaptchaImpl
Fontconfig warning: ignoring C.UTF-8: not a valid language tag
ERROR [CaptchaPortletAction] null
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.<init>(SunFontManager.java:376)
at sun.awt.FcFontManager.<init>(FcFontManager.java:35)
at sun.awt.X11FontManager.<init>(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.access$000(Font.java:224)
at java.awt.Font$FontAccessImpl.getFont2D(Font.java:228)
at sun.font.FontUtilities.getFont2D(FontUtilities.java:180)
at sun.font.StandardGlyphVector.initFontData(StandardGlyphVector.java:1126)
at sun.font.StandardGlyphVector.init(StandardGlyphVector.java:1115)
at sun.font.StandardGlyphVector.<init>(StandardGlyphVector.java:167)
at java.awt.Font.createGlyphVector(Font.java:2545)
at nl.captcha.text.renderer.DefaultWordRenderer.render(Unknown Source)
at nl.captcha.Captcha$Builder.addText(Unknown Source)
at com.liferay.portal.captcha.simplecaptcha.SimpleCaptchaImpl.getSimpleCaptcha(SimpleCaptchaImpl.java:243)
at com.liferay.portal.captcha.simplecaptcha.SimpleCaptchaImpl.serveImage(SimpleCaptchaImpl.java:159)
at com.liferay.portal.captcha.CaptchaImpl.serveImage(CaptchaImpl.java:100)
at com.liferay.portal.kernel.captcha.CaptchaUtil.serveImage(CaptchaUtil.java:78)
at com.liferay.portal.captcha.CaptchaPortletAction.serveResource(CaptchaPortletAction.java:42)
Activity
md5 commentedon Apr 9, 2016
This is probably the same issue as #46, which was fixed in #48.
It looks like the relevant package may be called
fontconfig
in Alpine.md5 commentedon Apr 9, 2016
As in the Debian case, I think the best fix is actually to add a dependency to the
openjdk8-jre
package in Alpine since the JDK doesn't handle the absence offontconfig
gracefully.jasonmader commentedon Apr 9, 2016
Iʼm not sure. I added the fontconfig package as a test, you can see the message,
Fontconfig warning: ignoring C.UTF-8: not a valid language tag
md5 commentedon Apr 9, 2016
Right. Sorry I missed that part in your original message.
The weird thing is that that error message comes from
fontconfig
, but it seems thatjava:alpine
doesn't havefontconfig
installed. Perhapsfontconfig
is statically linked into the JRE on Alpine?I took a look at the source code for OpenJDK 8 and traced back that NPE (the starting point is here). It looks like the proximate issue is that there is no
fontconfig.properties
orfontconfig.bcf
file (or any OS name-qualified variant), soreadFontConfigFile(File)
never callsloadProperties(InputStream)
orloadBinary(InputStream)
and thehead
variable is never initialized, resulting in aNullPointerException
.I'm not sure the apparent warning from
fontconfig
matters all that much, but that happens here. I'm not well-versed in C code, so that string parsing code makes my eyes glaze over and I'm not sure why it doesn't likeC.UTF-8
, but it seems like the "-" in "UTF-8" may be throwing it off.As an additional data point, when I call
Charset.defaultCharset().name()
in ajava:alpine
container, which is whatFontConfiguration
uses to determine the current encoding, it returns"UTF-8"
. It returns the same value when running underLANG=C.UTF8
orLANG=C.utf8
.I didn't dig into Debian's packaging of
libfontconfig1
to see if they're patching that part offontconfig
to avoid the warning.md5 commentedon Apr 9, 2016
It may be worth pulling
fontconfig.properties
from the Debian-basedjava:8
image and seeing what happens.md5 commentedon Apr 9, 2016
Thinking about it some more, I think the Fontconfig warning happens because “C” is only one character long and the code expects 2-3 characters. There is code earlier in the function that deals with plain “C”, but the codeset qualifier causes that code to be skipped.
Still not sure how Debian is different here (assuming it doesn't also show that warning).
md5 commentedon Apr 9, 2016
I looked through the
fontconfig
code a bit more and it looks like that call toFcNormalizeLang
comes fromFcStrSetAddLangs
, which comes fromFcGetDefaultLangs
. In the case where that warning is generated, the code will fall back to adding "en" as a default language: https://cgit.freedesktop.org/fontconfig/tree/src/fcdefault.c#n70md5 commentedon Apr 9, 2016
I see now that the Debian
java:8-jre
image doesn't actually have afontconfig.properties
file. It looks like that code path only gets used if the JRE can't get any font information fromlibfontconfig
. Here's what I see when I run a variant of the code in https://gist.github.com/md5/7fb07efafee3802da457 using the-Dsun.java2d.debugfonts=true
flag on Alpine:And here's what I see on Debian:
md5 commentedon Apr 9, 2016
It seems like the underlying issue is that
fontconfig
can't find any fonts in thejava:8-jre-alpine
image because there are no fonts:The Debian-based image has just enough fonts to support the default JDK fonts, it seems:
These fonts come from the
fonts-dejavu-core
package, which is a transitive dependency oflibfontconfig1
on Debian.md5 commentedon Apr 9, 2016
@jasonmader Try installing the
ttf-dejavu
package and see what happens. It seems to fix things for me.although it does add 124 MiB of packages to the imageUpdate: There are 124 MiB of packages in the image total after adding
ttf-dejavu
. Looks like it actually adds about 20 MiB to the image:jasonmader commentedon Apr 9, 2016
Thanks, that works.
jasonmader commentedon Apr 10, 2016
Also, I added
ENV LC_CTYPE en_US.UTF-8
to avoid the Fontconfig warning in the log.md5 commentedon Apr 11, 2016
@jasonmader I don't think that the base
alpine
image actually has anen_US
locale exactly (see gliderlabs/docker-alpine#144), but I can't say for certain that setting that will have any ill repercussions. If you want to set it for justfontconfig
, my read of the source discovered thatFC_LANG
takes precedence overLC_CTYPE
(andLANG
).jasonmader commentedon Apr 18, 2016
This doesn’t appear to be a locale setting for
FC_LANG
just the font language, as can be checked withfc-list :lang=en-US
soENV FC_LANG en-US
seems to be the appropriate fix for this.Added fix for Alpine fonts causing style rendering exceptions. Ref do…
71 remaining items