Error updating tzdata 2018f (Released 2018-10-18)

2019-01-23 04:55发布

I'm trying to update JVM's Time Zone info using TZUpdater 2.2.0.

> [root@local tzupdater-2.2.0]# java -jar tzupdater.jar -V
  tzupdater version 2.2.0-b01
  JRE tzdata version: tzdata2018d
  tzupdater tool would update with tzdata version: tzdata2018f

So, I'm running the command below:

> [root@local tzupdater-2.2.0]# java -jar tzupdater.jar -l

However, I'm getting this error message:

Failed: java.lang.Exception: Failed while parsing file '/tmp/tz.tmp_1/asia' on line 1655 'Rule  Japan   1948    1951    -   Sep Sat>=8  25:000S'
java.lang.Exception: Failed while parsing file '/tmp/tz.tmp_1/asia' on line 1655 'Rule  Japan   1948    1951    -   Sep Sat>=8  25:00   0   S'
    at tools.tzdb.TzdbZoneRulesCompiler.parseFile(TzdbZoneRulesCompiler.java:377)
    at tools.tzdb.TzdbZoneRulesCompiler.compile(TzdbZoneRulesCompiler.java:191)
    at tools.tzdb.TzdbZoneRulesCompiler.<init>(TzdbZoneRulesCompiler.java:307)
    at com.sun.tools.tzupdater.ExternalModule.compileToJSRBinary(ExternalModule.java:153)
    at com.sun.tools.tzupdater.TimezoneUpdater.run(TimezoneUpdater.java:230)
    at com.sun.tools.tzupdater.TimezoneUpdater.main(TimezoneUpdater.java:634)
Caused by: tools.tzdb.DateTimeException: Invalid value for SecondOfDay value: 90000
    at tools.tzdb.ChronoField.checkValidValue(ChronoField.java:173)
    at tools.tzdb.LocalTime.ofSecondOfDay(LocalTime.java:210)
    at tools.tzdb.TzdbZoneRulesCompiler.parseMonthDayTime(TzdbZoneRulesCompiler.java:475)
    at tools.tzdb.TzdbZoneRulesCompiler.parseRuleLine(TzdbZoneRulesCompiler.java:399)
    at tools.tzdb.TzdbZoneRulesCompiler.parseFile(TzdbZoneRulesCompiler.java:354)
    ... 5 more

I'm using https://www.iana.org/time-zones/repository/tzdata-latest.tar.gz as the source for the tzdata bundle.

Edited - In addition, I'm using either Java(TM) SE Runtime Environment (build 1.8.0_66-b17) and OpenJDK Runtime Environment (build 1.8.0_181-8u181-b13-1~deb9u1-b13), meanwhile I have same reported problem using TZUpdater or ZIUpdater

Can anyone help me about this issue? Any comment will be appreciated.

Many thanks.

标签: java timezone
8条回答
够拽才男人
2楼-- · 2019-01-23 05:30

Update your version of Java 8; the tzupdater tool just works in Java 8 update 181.

查看更多
ゆ 、 Hurt°
3楼-- · 2019-01-23 05:31

If you need to use version 2018f but not the Asia timezone you can use it from 2018e and the other files from 2018f.

I've created the file tzdata2018f-01.tar.gz in my repository https://github.com/lucasbasquerotto/my-projects/tree/master/tz for anyone that wants to avoid making these manual changes.

There is an example of using ziupdater when creating a docker image with OpenJDK, but if you use Oracle JDK you should be able to use almost the same code to use tzupdater changing

java -jar /app/tmp/ziupdater-1.0.1.2.jar -l file:///app/tmp/tzdata2018f-01.tar.gz

to

java -jar /app/tmp/tzupdater.jar -l file:///app/tmp/tzdata2018f-01.tar.gz

or even

java -jar tzupdater.jar -l https://github.com/lucasbasquerotto/my-projects/raw/master/tz/tzdata2018f-01.tar.gz

if you don't want to download it manually.

In the example in my repository it generates a Docker image, but you can use it without docker, with Java installed directly in your OS.

I executed the last example above on my local machine (that uses Oracle JDK) and the timezone was corrected successfully:

public static void main(String[] args) {        
    System.out.println("Date: " + new Date()); // prints correctly now
}

Just make sure that you aren't using some third-party library (like Joda Time) that uses timezone data hardcoded in its own jar (or generate a jar from the source with updated timezone data, like in https://www.joda.org/joda-time/tz_update.html).

查看更多
闹够了就滚
4楼-- · 2019-01-23 05:38

Yes, the rules for Japan in 1948-1951 changed in 2018f in an "interesting" way: officially, Japan's fall back occurred at 25:00 on Saturday, instead of 01:00 on the Sunday. That confused the Java time zone updater, as well as my own Noda Time project.

There's now a commit to avoid 25:00 in the "rearguard" format - the rearguard format is basically more conservative, avoiding things like Ireland's negative DST.

I would expect a 2018g release at some point reasonably soon, to include that fix. Assuming the tzupdater tool uses the rearguard appropriately, I'd expect that to sort things out. If you can possibly wait until then, I'd do so. Otherwise, use the -l flag on tzupdater to specify a different data source, e.g. for 2018e: https://data.iana.org/time-zones/releases/tzdata2018e.tar.gz

查看更多
女痞
5楼-- · 2019-01-23 05:42

Since tzdata2018g is already released with the fix provided in rearguard format, please use the rearguard tzdata bundle with -l option.

For tzdata2018g the command will look like this:
java -jar tzupdater.jar -l https://web.cs.ucla.edu/~eggert/tz/release/2018g/tzdata2018g-rearguard.tar.gz

查看更多
姐就是有狂的资本
6楼-- · 2019-01-23 05:45

I was running into the same error, then I fixed the downloaded file from IANA, using the following shell script, which replaces the troublesome line in the file by the previous version of "asia" file, as described by @lucas-basquerotto in his post below. I've tested and it works fine!

Please, download the TZUpdater bundle, extract the tzupdater.jar and update the variable TZUPDATER_JAR with the full file path of the downloaded jar file in order to run the script successfully.

#!/bin/bash

#FULL PATH TO tzupdater.jar
TZUPDATER_JAR='/home/user/tzupdater.jar'

OUTPUT_ALL=$(java -jar $TZUPDATER_JAR -l 2>&1 >/dev/null)
echo "$OUTPUT_ALL" | grep -e "Caused by: tools.tzdb.DateTimeException: Invalid value for SecondOfDay value: 90000" > /dev/null
if [ $? -eq 0 ]
then
        FIXME_FILE=$(echo "$OUTPUT_ALL" | grep -Po "(?<=java.lang.Exception: Failed while parsing file ').+(?=' on line 1655 'Rul)")
        echo "file $FIXME_FILE contains a syntax error"

        ERROR_LINE=$(sed -n '1656,1656p' $FIXME_FILE )
        echo "Line 1655 \"$ERROR_LINE\" contains an error"
        FIXED_LINE=${ERROR_LINE/Sat>=8/Sun>=9}
        FIXED_LINE=${FIXED_LINE/25:00/0:00}
        echo "Line 1655 fixed: \"$FIXED_LINE\" ( rule \"Sat>=8 25:00\" replaced by \"Sun>=9 0:00\" as it was used to be on previous version )"
        sed -i "s/$ERROR_LINE/$FIXED_LINE/" $FIXME_FILE
        TEMP_DIR_NAME=$(dirname $FIXME_FILE)
        cd $TEMP_DIR_NAME
        mkdir tzdata
        mv tzdata.tar.gz tzdata/
        cd tzdata/
        echo "untar original tzdata.tar.gz"
        tar -xf tzdata.tar.gz
        rm tzdata.tar.gz

        FIXME_FILENAME=$(basename $FIXME_FILE)
        echo "replacing original $FIXME_FILENAME file"
        rm $FIXME_FILENAME
        cp ../$FIXME_FILENAME $FIXME_FILENAME
        echo "building a new tar ball with the fixing"
        tar -czf ../tzdata-updated.tar.gz *
        echo "installing the updated tar file (requires elevation sudo)"
        sudo java -jar $TZUPDATER_JAR -l "file:///$TEMP_DIR_NAME/tzdata-updated.tar.gz"
        if [ $? -ne 0 ]
        then
                echo "something went wrong!"
                exit 2
        fi
fi
echo "installation successful!"

Save this is script under the name update_jdk_tzdata.sh and grant it permission to execute: chmod +x update_jdk_tzdata.sh and execute it ./update_jdk_tzdata.sh (it requires sudo in order to update JRE files)

查看更多
聊天终结者
7楼-- · 2019-01-23 05:47

Had the same issue here, and the problem seems to be just on the latest version.

Using

java -jar tzupdater.jar -l https://data.iana.org/time-zones/releases/tzdata2018d.tar.gz

(if "2018d" is enough for you) should work fine.

For some reason, after that, upgrading to the latest tzdata also worked fine (with just a warning).

查看更多
登录 后发表回答