3

I have a unit test that throws an exception because it eventually calls

DateTimeUtils.toZonedDateTime(cal);

Setup

We just recently started using the threeten-bp at our project.

The lib is placed at a central project and the exception is thrown from a project, that references the main project.

The exception occurs at two unit tests executed by an ant build script. I can see the threeten lib in the specified jenkins-home/workspace/Trunk/Project/build/project.jar and I can also see the DB-file in there.

Running the unit test from within Eclipse doesn't generate any exception.

The second stack trace suggests, that "Data already loaded for TZDB time-zone rules version: 2014c". The calling unit test was using a Calendar without a time zone set, so I assume the default time zone is used.

I changed the calendar to use UTC time zone and now the test is working without the exception. However, I wonder why it wouldn't be possible to use local time.

Stack traces

1st test

java.lang.NoClassDefFoundError: Could not initialize class org.threeten.bp.zone.ZoneRulesProvider
    at org.threeten.bp.ZoneRegion.ofId(ZoneRegion.java:143)
    at org.threeten.bp.ZoneId.of(ZoneId.java:357)
    at org.threeten.bp.ZoneId.of(ZoneId.java:285)
    at org.threeten.bp.DateTimeUtils.toZoneId(DateTimeUtils.java:141)
    at org.threeten.bp.DateTimeUtils.toZonedDateTime(DateTimeUtils.java:103)
    at ...

2nd test

java.util.ServiceConfigurationError: org.threeten.bp.zone.ZoneRulesProvider: Provider org.threeten.bp.zone.TzdbZoneRulesProvider could not be instantiated: org.threeten.bp.zone.ZoneRulesException: Unable to load TZDB time-zone rules: jar:file:/jenkins-home/workspace/Trunk/Project/build/project.jar!/org/threeten/bp/TZDB.dat
    at java.util.ServiceLoader.fail(ServiceLoader.java:207)
    at java.util.ServiceLoader.access$100(ServiceLoader.java:164)
    at java.util.ServiceLoader$LazyIterator.next(ServiceLoader.java:360)
    at java.util.ServiceLoader$1.next(ServiceLoader.java:428)
    at org.threeten.bp.zone.ZoneRulesProvider.<clinit>(ZoneRulesProvider.java:93)
    at org.threeten.bp.ZoneRegion.ofId(ZoneRegion.java:143)
    at org.threeten.bp.ZoneId.of(ZoneId.java:357)
    at org.threeten.bp.ZoneId.of(ZoneId.java:285)
    at org.threeten.bp.DateTimeUtils.toZoneId(DateTimeUtils.java:141)
    at org.threeten.bp.DateTimeUtils.toZonedDateTime(DateTimeUtils.java:103)
    at ...
Caused by: org.threeten.bp.zone.ZoneRulesException: Unable to load TZDB time-zone rules: jar:file:/var/lib/jenkins/workspace/Virtuelles_Kraftwerk_HEAD/WetterGUIClassic/build/weather-base.jar!/org/threeten/bp/TZDB.dat
    at org.threeten.bp.zone.TzdbZoneRulesProvider.load(TzdbZoneRulesProvider.java:146)
    at org.threeten.bp.zone.TzdbZoneRulesProvider.<init>(TzdbZoneRulesProvider.java:87)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
    at java.lang.Class.newInstance0(Class.java:357)
    at java.lang.Class.newInstance(Class.java:310)
    at java.util.ServiceLoader$LazyIterator.next(ServiceLoader.java:356)

Caused by: org.threeten.bp.zone.ZoneRulesException: Data already loaded for TZDB time-zone rules version: 2014c
    at org.threeten.bp.zone.TzdbZoneRulesProvider.load(TzdbZoneRulesProvider.java:139)
Torsten
  • 1,696
  • 2
  • 21
  • 42
  • Do you have all required dependencies on your classpath? – BlueLettuce16 Nov 05 '14 at 14:41
  • @BlueLettuce16 How can I verify that? I guess so, because the exception doesn't occur on the first call of any threeten class, which would be DateTimeUtils in this case. – Torsten Nov 05 '14 at 14:45
  • Where did you get this library from? I would recommend downloading it from https://github.com/ThreeTen/threetenbp and then building with maven, and then put it to the appropriate lib directory (of the parent project) for Ant usage. – BlueLettuce16 Nov 05 '14 at 14:53
  • @BlueLettuce16 My colleague got it from the mvn repo that is linked at http://www.threeten.org/threetenbp/. However, I also built it (v. 1.1) the way you suggested, but the problem persists. – Torsten Nov 06 '14 at 14:22

1 Answers1

3

this problem appears if two or more threetenbp-libraries are inside the classpath. This even happens if the library-files are identical. In our case, we included the same library twice but from different paths in the filesystem.

Best regards, Christian

  • And the solution was? – StarWind0 Sep 11 '17 at 20:18
  • Obviously, removing the redundant jar files. – Christian Ciach Sep 13 '17 at 13:41
  • My issue ended up being from multi dex / pro guard not loading a library fast enough on older devices. Requiring me to add a keep rule into proguard rules for the library. That said, you only stated the root issue not the fix. Obvious is not always obvious to other people. I found this link helpful to helping improve my own answers https://stackoverflow.com/help/how-to-answer – StarWind0 Sep 13 '17 at 16:10