Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8200722

Java does support the :characters format of the TZ environment variable

    Details

    • Subcomponent:
    • CPU:
      x86_64
    • OS:
      linux

      Description

      FULL PRODUCT VERSION :
      java 9.0.4
      Java(TM) SE Runtime Environment (build 9.0.4+11)
      Java HotSpot(TM) 64-Bit Server VM (build 9.0.4+11, mixed mode)


      ADDITIONAL OS VERSION INFORMATION :
      Red Hat Enterprise Linux Server release 7.4 (Maipo)
      Linux alexrhel7test.mpr.org 3.10.0-693.21.1.el7.x86_64 #1 SMP Fri Feb 23 18:54:16 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux

      EXTRA RELEVANT SYSTEM CONFIGURATION :
      Brand new VM, nothing unique as far as the configuration.
      Installed using Redhat 7.4 minimal

      A DESCRIPTION OF THE PROBLEM :
      It seems that java doesn't support a format of the TZ environment variable in Linux. On http://www.gnu.org/software/libc/manual/html_node/TZ-Variable.html at the bottom the of document, the format :characters is defined.

      Java doesn't seem properly read the variable if TZ is set to a file path. When the TZ variable is set to :/etc/localtime, the java timezone doesn't properly honor daylight savings time and all time operations are an hour off.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      I installed a fresh RHEL7.4 minimal system, updated it with yum update and rebooted.
      During installation I set the timezone to American/Chicago
      Then I downloaded jdk-9.0.4_linux-x64_bin.rpm from Oracle's website
      Then I ran "yum install jdk-9.0.4_linux-x64_bin.rpm"

      I used this sample java code in a file called GetDate.java:
      import java.util.Date;

      class GetDate {
        /** Print a hello message */
        public static void main(String[] args) {
          Date today = new Date();
          System.out.println(today);
        }
      }

      Then I ran "javac GetDate.java"
      Then I ran "java GetDate"

      The output was
      $ java GetDate
      Wed Mar 21 14:48:35 CDT 2018

      If I create a timezone environment variable:
      export TZ=:/etc/localtime

      Then run the java command again, I get different result, one hour off:
      $ java GetDate
      Wed Mar 21 13:50:04 GMT-06:00 2018

      If I run the local date command, I get the correct time, even with the environment variable
      $ date
      Wed Mar 21 14:50:06 CDT 2018


      $ ls -hla /etc/localtime
      lrwxrwxrwx. 1 root root 37 Mar 21 13:28 /etc/localtime -> ../usr/share/zoneinfo/America/Chicago

      If I unset the TZ environment variable, it works
      $ unset TZ
      $ java GetDate
      Wed Mar 21 14:52:38 CDT 2018

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      I expect the test script to show the correct time with the correct hour based on daylight savings.
      ACTUAL -
      Instead I see time that is an hour off.

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      import java.util.Date;

      class GetDate {
        /** Print a hello message */
        public static void main(String[] args) {
          Date today = new Date();
          System.out.println(today);
        }
      }
      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      Unsetting the TZ variable works.
      Setting the TZ variable to "American/Chicago" works.

        Attachments

          Activity

            People

            • Assignee:
              naoto Naoto Sato
              Reporter:
              webbuggrp Webbug Group
            • Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

              • Created:
                Updated: