jlink and jdk.localedata

Sander Mak sander.mak at luminis.eu
Tue Aug 23 19:49:59 UTC 2016


When I create an image with jlink containing a single module that runs this code:

public static void main(String... args) {
    Locale dutchLocale = new Locale.Builder().setLanguage("nl")
    DateFormat df = DateFormat.getDateInstance(DateFormat.SHORT, dutchLocale);
    String formattedDate = df.format(new java.util.Date());

some surprising behavior surfaces. While running on the full JDK this shows the correctly formatted date, running on the image shows the date formatted according to the en_US locale (available through java.base). Adding the jdk.localedata module explicitly to the image fixes this.

I can see how this happens: jdk.localedata is not automatically resolved because it is based on services, and there's a silent fallback to en_US if the nl_NL locale is not found. All perfectly explainable from a module-system technical point of view, but I think this will lead to lots of confused looks in applications relying on locales other than English locales. Not sure what to propose here, other than that this should be very well documented IMO. Maybe jlink could at least warn if the user's system locale is not among the default ones from java.base and suggest to add jdk.localedata to preserve local behavior. Granted, the image is probably targeted to other environments, but at least it's something.


More information about the jigsaw-dev mailing list