Uploaded image for project: 'RHEL'
  1. RHEL
  2. RHEL-3407

Setting the TZ environment variable breaks TimeZone in Java

Linking RHIVOS CVEs to...Migration: Automation ...SWIFT: POC ConversionSync from "Extern...XMLWordPrintable

    • None
    • Moderate
    • rhel-sst-java
    • None
    • False
    • False
    • Hide

      None

      Show
      None
    • None
    • None
    • None
    • None
    • If docs needed, set a value
    • None
    • 57,005

      Description of problem:
      If the TZ environment variable is set to the absolute filepath of the TimeZone, java fall back to setting the timezone in GMT time.
      This caused incorrect times to be reported in a java/tomcat application. Every time when daylight savings time is active, between March and November in the US.

      Version-Release number of selected component (if applicable):
      Red Hat Enterprise Linux 7.4
      java-1.8.0-openjdk-1.8.0.161-0.b14.el7_4.x86_64
      tzdata-java-2018d-1.el7.noarch
      tzdata-2018d-1.el7.noarch

      Also reproduced on java-1.7.0-openjdk and java-1.6.0-openjdk .

      How reproducible:
      Always

      Steps to Reproduce:
      1. # cat 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); }

      }

      1. javac GetDate.java

      2.

      1. java GetDate
        Wed Mar 21 14:48:35 CDT 2018

      3.

      1. export TZ=:/etc/localtime
      2. java GetDate
        Wed Mar 21 13:50:04 GMT-06:00 2018

      With date command, I get the correct time, even with the environment variable

      1. date
        Wed Mar 21 14:50:06 CDT 2018
      1. ls -hla /etc/localtime
        lrwxrwxrwx. 1 root root 37 Mar 21 13:28 /etc/localtime -> ../usr/share/zoneinfo/America/Chicago

      4.
      If the TZ environment variable is unset, it provides the correct output.
      $ unset TZ
      $ java GetDate
      Wed Mar 21 14:52:38 CDT 2018

      Actual results:
      When TZ is set to absolute path of the TimeZone file, it fails to output the TimeZone but prints the GMT time.

      Expected results:
      Expected to return the TimeZone correctly even when TZ environment variable is set.

      Additional info:

              rhn-engineering-ahughes Andrew Hughes
              rhn-support-dkochuka Deepu Kochukaleekal (Inactive)
              Andrew Hughes Andrew Hughes
              David Kutalek David Kutalek
              Votes:
              0 Vote for this issue
              Watchers:
              12 Start watching this issue

                Created:
                Updated:
                Resolved: