ablog

不器用で落着きのない技術者のメモ

OpenJDK7 のビルドが "java.lang.RuntimeException: time is more than 10 years from present: ..." エラーで失敗する

事象

OpenJDK7u40 のビルドが "java.lang.RuntimeException: time is more than 10 years from present: ..." というエラーで失敗する。

$ make
(中略)
/home/yazekats/Downloads/bin/jdk1.6.0_45/bin/java -XX:-PrintVMOptions -XX:+UnlockDiagnosticVMOptions -XX:-LogVMOutput -Xmx512m -Xms512m -XX:PermSize=32m -XX:MaxPermSize=160m -jar /home/yazekats/Documents/mercurial/jdk7u40/build/linux-amd64/btjars/generatecurrencydata.jar -o /home/yazekats/Documents/mercurial/jdk7u40/build/linux-amd64/lib/currency.data.temp \
		< ../../../src/share/classes/java/util/CurrencyData.properties
Error: time is more than 10 years from present: 1136059200000
java.lang.RuntimeException: time is more than 10 years from present: 1136059200000
	at build.tools.generatecurrencydata.GenerateCurrencyData.makeSpecialCaseEntry(GenerateCurrencyData.java:285)
	at build.tools.generatecurrencydata.GenerateCurrencyData.buildMainAndSpecialCaseTables(GenerateCurrencyData.java:225)
	at build.tools.generatecurrencydata.GenerateCurrencyData.main(GenerateCurrencyData.java:154)
make[4]: *** [/home/yazekats/Documents/mercurial/jdk7u40/build/linux-amd64/lib/currency.data] Error 1
make[4]: Leaving directory `/home/yazekats/Documents/mercurial/jdk7u40/jdk/make/java/java'
make[3]: *** [all] Error 1
make[3]: Leaving directory `/home/yazekats/Documents/mercurial/jdk7u40/jdk/make/java'
make[2]: *** [all] Error 1
make[2]: Leaving directory `/home/yazekats/Documents/mercurial/jdk7u40/jdk/make'
make[1]: *** [jdk-build] Error 2
make[1]: Leaving directory `/home/yazekats/Documents/mercurial/jdk7u40'

原因

GenerateCurrencyData.javajdk/src/share/classes/java/util/CurrencyData.properties に記述されている日付をチェックしていて現在から10年より過去または未来だと例外になる?

Looking at the code in GenerateCurrencyData.java that is used generate some binary information for the JVM reveals some more insights why this error happened.
A simple line of code (285) that throws an exception when the time used the mark the switch from currency 1 to currency 2 differs by more than 10 year from now.

int length = currencyInfo.length();
if (currencyInfo.charAt(3) != ';' || 
    currencyInfo.charAt(length - 4) != ';') {
   throw new RuntimeException("invalid currency info: " + currencyInfo);
 }
 String oldCurrency = currencyInfo.substring(0, 3);
 String newCurrency = currencyInfo.substring(length - 3, length);
 checkCurrencyCode(oldCurrency);
 checkCurrencyCode(newCurrency);
 String timeString = currencyInfo.substring(4, length - 4);
 long time = format.parse(timeString).getTime();
 if (Math.abs(time - System.currentTimeMillis()) > ((long) 10) * 365 * 24 * 60 * 60 * 1000) {
   throw new RuntimeException("time is more than 10 years from present: " + time);
 }

No explanation why. Changing the line within CurrencyData.properties to

TR=TRL;2005-12-31-22-00-00;TRY

solved the problem and I'll be fine with it until I'll print turkey currency values with dates in 2005.

http://www.brainbugs.net/build-openjdk-on-freebsd-9/

対応

CurrencyData.properties の年を現在から10年以内に書換える。

$ cd jdk/src/share/classes/java/util
$ perl -i.org -pe 's/200\d/2015/g' CurrencyData.properties 
$ diff CurrencyData.properties.org CurrencyData.properties
2c2
< # Copyright (c) 2000, 2008, Oracle and/or its affiliates. All rights reserved.
---
> # Copyright (c) 2015, 2015, Oracle and/or its affiliates. All rights reserved.
108c108
< AZ=AZM;2005-12-31-20-00-00;AZN
---
> AZ=AZM;2015-12-31-20-00-00;AZN
210c210
< # USD is also legal currency as of 2001/01/01
---
> # USD is also legal currency as of 2015/01/01
381c381
< MZ=MZM;2006-06-30-22-00-00;MZN
---
> MZ=MZM;2015-06-30-22-00-00;MZN
443c443
< RO=ROL;2005-06-30-21-00-00;RON
---
> RO=ROL;2015-06-30-21-00-00;RON
535c535
< TR=TRL;2004-12-31-22-00-00;TRY
---
> TR=TRL;2015-12-31-22-00-00;TRY
561c561
< VE=VEB;2008-01-01-04-00-00;VEF
---
> VE=VEB;2015-01-01-04-00-00;VEF
  • OpenJDK7u40 をビルドする。
$ make
(中略)
#-- Build times ----------
Target all_product_build
Start 2016-05-17 00:56:36
End   2016-05-17 01:20:22
00:00:10 corba
00:00:13 hotspot
00:00:03 jaxp
00:00:26 jaxws
00:22:52 jdk
00:00:02 langtools
00:23:46 TOTAL
-------------------------
make[1]: Leaving directory `/home/yazekats/Documents/mercurial/jdk7u40'