quarkus: Native image does not inherit system time zone

Native image does ignore system time zone, assumes GMT instead. Code snippet to verify:

@ApplicationScoped
public class Startup {
    
    public void startup(@Observes StartupEvent ev) {
        System.out.println("--- default time zone id is: " + ZoneId.systemDefault());
    }
    
}

Output (no matter system timezone is):

--- default time zone id is: GMT

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Comments: 29 (19 by maintainers)

Most upvoted comments

I’m looking at the source code and it looks like this:

@AutomaticFeature
final class TimeZoneFeature implements Feature {
    static class Options {
        @Option(help = "When true, all time zones will be pre-initialized in the image.")//
        public static final HostedOptionKey<Boolean> IncludeAllTimeZones = new HostedOptionKey<>(false);
    }

    @Override
    public void afterRegistration(AfterRegistrationAccess access) {
        TimeZone defaultZone = TimeZone.getDefault();
        String[] supportedZoneIDs = Options.IncludeAllTimeZones.getValue() ? TimeZone.getAvailableIDs() : new String[]{"GMT", "UTC", defaultZone.getID()};
        Map<String, TimeZone> supportedZones = Arrays.stream(supportedZoneIDs)
                        .map(TimeZone::getTimeZone)
                        .collect(toMap(TimeZone::getID, tz -> tz, (tz1, tz2) -> tz1));
        ImageSingletons.add(TimeZoneSupport.class, new TimeZoneSupport(supportedZones, defaultZone));
    }
}

So it looks to me like it’s only including, by default, GMT, UTC, and whatever the build host’s time zone is. So if the run host has a different time zone, you won’t get it and it’ll fall back to UTC. This should be verifiable by building a native image with a different value set for the TZ env. variable and then running it to see if it falls back to UTC.

Setting -H:+IncludeAllTimeZones should “fix” the problem but might inflate the image significantly.

Stupid question but would the timezone be fixed at build time?

On Thu, Oct 31, 2019 at 4:09 PM sgerr notifications@github.com wrote:

Hello, @jaikiran https://github.com/jaikiran

I’m building native image using maven with docker on Windows 10, running it on Oracle Linux 7 or even Fedora 30. To reproduce:

  1. Create project

mvn io.quarkus:quarkus-maven-plugin:0.27.0:create -DprojectGroupId=com.sgerr -DprojectArtifactId=tztest -Dextensions=“undertow” -Dpath=tz

  1. Create class Starter, use code snippet above.
  2. Build native image

mvnw package -Pnative -Dquarkus.native.container-build=true

Docker command is:

[INFO] [io.quarkus.deployment.pkg.steps.NativeImageBuildStep] docker run -v C:\work\sandbox\SandboxProjects\tztest\target\tztest-1.0-SNAPSHOT-native-image-source-jar:/project:z --rm quay.io/quarkus/ubi-quarkus-native-image:19.2.1 -J-Dsu n.nio.ch.maxUpdateArraySize=100 -J-Djava.util.logging.manager=org.jboss.logmanager.LogManager -J-Dvertx.logger-delegate-factory-class-name=io.quarkus.vertx.core.runtime.VertxLogDelegateFactory -J-Dvertx.disableDnsResolver=true -J-Dio.ne tty.leakDetection.level=DISABLED -J-Dio.netty.allocator.maxOrder=1 --initialize-at-build-time= -H:InitialCollectionPolicy=com.oracle.svm.core.genscavenge.CollectionPolicy$BySpaceAndTime -jar tztest-1.0-SNAPSHOT-runner.jar -J-Djava.util. concurrent.ForkJoinPool.common.parallelism=1 -H:FallbackThreshold=0 -H:+ReportExceptionStackTraces -H:-AddAllCharsets -H:EnableURLProtocols=http -H:-JNI -H:-UseServiceLoaderFeature -H:+StackTrace tztest-1.0-SNAPSHOT-runner

  1. Copy and run it on Linux.

date +%z && ./tztest -Dquarkus.http.port=9999

+0300 — default time zone id is: GMT 2019-10-31 15:04:57,611 INFO [io.quarkus] (main) tztest 1.0-SNAPSHOT (running on Quarkus 0.27.0) started in 0.016s. Listening on: http://0.0.0.0:9999 2019-10-31 15:04:57,611 INFO [io.quarkus] (main) Profile prod activated. 2019-10-31 15:04:57,611 INFO [io.quarkus] (main) Installed features: [cdi, resteasy, servlet]

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/quarkusio/quarkus/issues/5016?email_source=notifications&email_token=AAJYOBMRTBIBDBKFOP4WLI3QRLYJNA5CNFSM4JGU4C32YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOECYEAFI#issuecomment-548421653, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAJYOBNMXOM2SPSJGFTUN5DQRLYJNANCNFSM4JGU4C3Q .

I’ve raised a graal PR https://github.com/oracle/graal/pull/1819 to see if we can have timezone support enhanced to allow more fine grained control on how users or Quarkus can configure the available timezones in native-image.