Issue
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);
}
}
javac GetDate.java
2.
java GetDate
Wed Mar 21 14:48:35 CDT 2018
3.
export TZ=:/etc/localtime
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
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
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: