This bug has been migrated to another issue tracking site. It has been closed here and may no longer be being monitored.

If you would like to get updates for this issue, or to participate in it, you may do so at Red Hat Issue Tracker .
RHEL Engineering is moving the tracking of its product development work on RHEL 6 through RHEL 9 to Red Hat Jira (issues.redhat.com). If you're a Red Hat customer, please continue to file support cases via the Red Hat customer portal. If you're not, please head to the "RHEL project" in Red Hat Jira and file new tickets here. Individual Bugzilla bugs in the statuses "NEW", "ASSIGNED", and "POST" are being migrated throughout September 2023. Bugs of Red Hat partners with an assigned Engineering Partner Manager (EPM) are migrated in late September as per pre-agreed dates. Bugs against components "kernel", "kernel-rt", and "kpatch" are only migrated if still in "NEW" or "ASSIGNED". If you cannot log in to RH Jira, please consult article #7032570. That failing, please send an e-mail to the RH Jira admins at rh-issues@redhat.com to troubleshoot your issue as a user management inquiry. The email creates a ServiceNow ticket with Red Hat. Individual Bugzilla bugs that are migrated will be moved to status "CLOSED", resolution "MIGRATED", and set with "MigratedToJIRA" in "Keywords". The link to the successor Jira issue will be found under "Links", have a little "two-footprint" icon next to it, and direct you to the "RHEL project" in Red Hat Jira (issue links are of type "https://issues.redhat.com/browse/RHEL-XXXX", where "X" is a digit). This same link will be available in a blue banner at the top of the page informing you that that bug has been migrated.
Bug 1562837 - Setting the TZ environment variable breaks TimeZone in Java
Summary: Setting the TZ environment variable breaks TimeZone in Java
Keywords:
Status: CLOSED MIGRATED
Alias: None
Product: Red Hat Enterprise Linux 8
Classification: Red Hat
Component: java-1.8.0-openjdk
Version: 8.2
Hardware: x86_64
OS: Linux
medium
medium
Target Milestone: rc
: 8.4
Assignee: Andrew John Hughes
QA Contact: OpenJDK QA
URL:
Whiteboard:
Depends On:
Blocks: 1594286 1894575
TreeView+ depends on / blocked
 
Reported: 2018-04-02 16:29 UTC by Deepu K S
Modified: 2024-06-13 21:55 UTC (History)
9 users (show)

Fixed In Version:
Doc Type: If docs needed, set a value
Doc Text:
Clone Of:
Environment:
Last Closed: 2023-09-12 21:51:43 UTC
Type: Bug
Target Upstream Version:
Embargoed:


Attachments (Terms of Use)


Links
System ID Private Priority Status Summary Last Updated
Red Hat Issue Tracker   RHEL-3407 0 None Migrated None 2023-09-12 21:51:38 UTC
openjdk bug system JDK-8200722 0 None None None 2018-11-06 19:07:35 UTC

Description Deepu K S 2018-04-02 16:29:15 UTC
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:

Comment 2 Deepu K S 2018-04-02 16:34:09 UTC
Another test that we ran locally;

# cat test.java
class test {
  /** Print a hello message */
  public static void main(String[] args) {
    System.out.println(java.util.TimeZone.getDefault());
  }
}

# javac test.java

# export TZ="/usr/share/zoneinfo/America/New_York"

# java test
sun.util.calendar.ZoneInfo[id="GMT-05:00",offset=-18000000,dstSavings=0,useDaylight=false,transitions=0,lastRule=null] <<<<<<<<<---timezone id is set to GMT -05, it should be America/New_York.

# unset TZ

# java test
sun.util.calendar.ZoneInfo[id="America/New_York",offset=-18000000,dstSavings=3600000,useDaylight=true,transitions=235,lastRule=java.util.SimpleTimeZone[id=America/New_York,offset=-18000000,dstSavings=3600000,useDaylight=true,startYear=0,startMode=3,startMonth=2,startDay=8,startDayOfWeek=1,startTime=7200000,startTimeMode=0,endMode=3,endMonth=10,endDay=1,endDayOfWeek=1,endTime=7200000,endTimeMode=0]]

If we export TZ to just the timezone as below, it works.
# export TZ=":America/New_York"

# java test
sun.util.calendar.ZoneInfo[id="America/New_York",offset=-18000000,dstSavings=3600000,useDaylight=true,transitions=235,lastRule=java.util.SimpleTimeZone[id=America/New_York,offset=-18000000,dstSavings=3600000,useDaylight=true,startYear=0,startMode=3,startMonth=2,startDay=8,startDayOfWeek=1,startTime=7200000,startTimeMode=0,endMode=3,endMonth=10,endDay=1,endDayOfWeek=1,endTime=7200000,endTimeMode=0]]

The issue is seen when we export TZ to the absolute filepath or /etc/localtime.

Comment 3 Deepu K S 2018-04-06 08:42:10 UTC
Below is the Bug that was opened Oracle Java BugZilla.
https://bugs.java.com/bugdatabase/view_bug.do?bug_id=JDK-8200722

Comment 6 Deepak Bhole 2018-11-22 20:24:44 UTC
Andrew, can you please provide a status update?

Comment 7 Andrew John Hughes 2018-12-12 05:31:12 UTC
Sorry, I mixed this up with a similar bug (bug 1536048) and thought I'd answered it.

Looking over the code, I see the issue is that any value of TZ is assumed to be a zonename. So, America/New_York works, but if it's a file path, the path is sent back to the calling Java code unaltered, which can't match it to a zone and instead falls back to GMT.

I believe different behaviour should be used if the TZ value starts with a '/' (or ':/', but it already just drops the ':')

1. If the path is /etc/localtime, use the existing logic to find out which zone that points to.
2. If it's a timezone path, use getZoneName to strip the beginning and return the zone name

The logic for both these options is already there for the case where TZ is unset. It's just ignored where TZ is set, preferring to just use that value as is. A patch for this should be fairly trivial.

Comment 8 Andrew John Hughes 2019-06-28 17:15:08 UTC
Moving to RHEL 7.8.

Comment 43 RHEL Program Management 2023-09-12 21:50:04 UTC
Issue migration from Bugzilla to Jira is in process at this time. This will be the last message in Jira copied from the Bugzilla bug.

Comment 44 RHEL Program Management 2023-09-12 21:51:43 UTC
This BZ has been automatically migrated to the issues.redhat.com Red Hat Issue Tracker. All future work related to this report will be managed there.

Due to differences in account names between systems, some fields were not replicated.  Be sure to add yourself to Jira issue's "Watchers" field to continue receiving updates and add others to the "Need Info From" field to continue requesting information.

To find the migrated issue, look in the "Links" section for a direct link to the new issue location. The issue key will have an icon of 2 footprints next to it, and begin with "RHEL-" followed by an integer.  You can also find this issue by visiting https://issues.redhat.com/issues/?jql= and searching the "Bugzilla Bug" field for this BZ's number, e.g. a search like:

"Bugzilla Bug" = 1234567

In the event you have trouble locating or viewing this issue, you can file an issue by sending mail to rh-issues. You can also visit https://access.redhat.com/articles/7032570 for general account information.


Note You need to log in before you can comment on or make changes to this bug.