openjdk: NullPointerException in Alpine JRE 8 Font
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)
About this issue
- Original URL
- State: closed
- Created 8 years ago
- Reactions: 11
- Comments: 31 (13 by maintainers)
Commits related to this issue
- Added fix for Alpine fonts causing style rendering exceptions. Ref https://github.com/docker-library/openjdk/issues/73 — committed to ais-open/dockerfiles by gisjedi 8 years ago
- android-studio: use a dedicated fontconfig file — committed to NixOS/nixpkgs by phunehehe 8 years ago
- ensure libfontconfig1 is installed workaround for docker-library/openjdk/issues/73 — committed to hossman/solr-jdk9-jenkins-on-docker by hossman 7 years ago
- Improve font configuration Due to some standard fonts missing, JRE was failing to load the fonts. DejaVu fonts are added to mitigate this, as per: https://github.com/docker-library/openjdk/issues/... — committed to stanch/scastie by stanch 7 years ago
- Improve font configuration Due to some standard fonts missing in the SBT runner image, the JVM was failing to load the fonts when running any font-related code. DejaVu fonts are added to mitigate thi... — committed to stanch/scastie by stanch 7 years ago
- Improve font configuration Due to some standard fonts missing in the SBT runner image, the JVM was failing to load the fonts when running any font-related code. DejaVu fonts are added to mitigate thi... — committed to scalacenter/scastie by stanch 7 years ago
- add font to docker image, see https://github.com/docker-library/openjdk/issues/73 — committed to HSLdevcom/OpenTripPlanner by siren 7 years ago
- Add libfontconfig1 dependency See https://github.com/docker-library/openjdk/issues/73 — committed to MarkEWaite/docker-lfs by MarkEWaite 7 years ago
- Install ttf-dejavu for some basic fonts (needed for charts) I've used the alpine image instead of the debian and all charts did not work anymore. After finding: https://github.com/docker-library/open... — committed to FlorianSW/openhab-docker by shaguarger 7 years ago
- Install ttf-dejavu for some basic fonts (needed for charts) I've used the alpine image instead of the debian and all charts did not work anymore. After finding: https://github.com/docker-library/open... — committed to FlorianSW/openhab-docker by FlorianSW 7 years ago
- Install ttf-dejavu for some basic fonts (needed for charts) (#113) * Install ttf-dejavu for some basic fonts (needed for charts) I've used the alpine image instead of the debian and all charts did n... — committed to openhab/openhab-docker by FlorianSW 7 years ago
- NullPointerException in Alpine Font see https://github.com/docker-library/openjdk/issues/73 Signed-off-by: in_dow <in_dow@hotmail.com> — committed to indication/docker-gitbucket by deleted user 7 years ago
- Added the ttf-dejavu package Without this, some Confluence macros do not work (repro'd for the Page Tree macro). The POST request for returns a 500 error, caused by a NullPointerException in Java whi... — committed to agronholm/docker-atlassian-confluence by agronholm 6 years ago
- Fix NPE on font rendering https://github.com/docker-library/openjdk/issues/73 — committed to int128/gitbucket-docker by int128 6 years ago
- Add fontconfig and ttf-dejavu package to fix docker-library/openjdk#73 — committed to yakworks/dockers by snimavat 6 years ago
- Merge pull request #1 from yakworks/fontconfig-fix Add fontconfig and ttf-dejavu package to fix docker-library/openjdk#73 — committed to yakworks/dockers by basejump 6 years ago
- Added some fonts (~20MB) to render legend-image for analyst extensions web display (https://github.com/docker-library/openjdk/issues/73) — committed to 1tchy/opentripplanner-docker-ch by 1tchy 6 years ago
- Add fontconfig & ttf-dejavu (see docker-library/openjdk#73) — committed to HiromuHota/webspoon-docker by deleted user 5 years ago
- fix for java font dependent tools Conda-installed tools such as fastqc hanging but not exiting. see https://github.com/docker-library/openjdk/issues/73 — committed to rsuchecki/miniconda3 by rsuchecki 5 years ago
- Switched from 8-jre-alpine to 8-jre-slim to fix NPE when JFreeChart makes a call that leads to sun.awt.FontConfiguration.getVersion(FontConfiguration.java:1264) See: https://github.com/docker-library/... — committed to aic-sri-international/praise-wm by d-dunkley 6 years ago
@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: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.Same issue in jre-10 while generating excel reports, ubuntu 16.04 installing fontconfig ttf-dejavu solved this issues
full ack @jnunderwood Another idea might therefore be to add some “notable problems” in the docker hub description at https://hub.docker.com/_/openjdk/ which points out, that the alpine image is missing fonts, which might break the functionality of OpenJDK (may be there are some other issues which should be described).
installing ttf-dejavu packge fixed it.
FYI: Same problem seems to afflict openjdk:9-jdk (9-b158)
workaround as noted in #48 …
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.I don’t think a
_with_fonts
image would improve much, as you still don’t know that you need this image (as there is no meaningful exception thrown). And if you actually know that you need this image, you can apply the appropriateRUN
command in your Dockerfile.AFAICT 8-jre-alpine still has that issue. 8-jre-slim works as expected. Can this only be fixed by installing a new package in the container?
Quite hard to debug and find the source of this error. For me it even crashed with diverse errors (which I paste, so somebody might find it on Google):
or
(I think there had also been a NullPointerException, but I could not find it anymore.)
Adding
RUN apk add --no-cache ttf-dejavu
to the Dockerfile fixes the issue.I wonder if this could also be an upstream issue for the OpenJDK developers, as throwing those Exceptions is really not helpful to point out that there are fonts missing.
Also, I added
ENV LC_CTYPE en_US.UTF-8
to avoid the Fontconfig warning in the log.