Bug 1562837
| Summary: | Setting the TZ environment variable breaks TimeZone in Java | ||
|---|---|---|---|
| Product: | Red Hat Enterprise Linux 8 | Reporter: | Deepu K S <dkochuka> |
| Component: | java-1.8.0-openjdk | Assignee: | Andrew John Hughes <ahughes> |
| Status: | CLOSED MIGRATED | QA Contact: | OpenJDK QA <java-qa> |
| Severity: | medium | Docs Contact: | |
| Priority: | medium | ||
| Version: | 8.2 | CC: | ahughes, cww, dbhole, jandrlik, jdoyle, jvanek, jwright, mmillson, vpakolu |
| Target Milestone: | rc | Keywords: | MigratedToJIRA, Triaged |
| Target Release: | 8.4 | Flags: | pm-rhel:
mirror+
|
| Hardware: | x86_64 | ||
| OS: | Linux | ||
| Whiteboard: | |||
| Fixed In Version: | Doc Type: | If docs needed, set a value | |
| Doc Text: | Story Points: | --- | |
| Clone Of: | Environment: | ||
| Last Closed: | 2023-09-12 21:51:43 UTC | Type: | Bug |
| Regression: | --- | Mount Type: | --- |
| Documentation: | --- | CRM: | |
| Verified Versions: | Category: | --- | |
| oVirt Team: | --- | RHEL 7.3 requirements from Atomic Host: | |
| Cloudforms Team: | --- | Target Upstream Version: | |
| Embargoed: | |||
| Bug Depends On: | |||
| Bug Blocks: | 1594286, 1894575 | ||
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.
Below is the Bug that was opened Oracle Java BugZilla. https://bugs.java.com/bugdatabase/view_bug.do?bug_id=JDK-8200722 Andrew, can you please provide a status update? 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. Moving to RHEL 7.8. 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. 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. |
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: