question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

java.time.Duration not present before SDK 26

See original GitHub issue

Unable to use Mockito 3.1.7+ with Android on lower SDK devices.

Reason:

https://developer.android.com/reference/java/time/Duration <-- This was not added to Android until SDK 26.

https://developer.android.com/about/dashboards <-- here are some distribution stats. Most noticeably, this would impact testing for 70% of the market and is not ideal.

java.lang.NoClassDefFoundError: java.time.Duration
at org.mockito.Mockito.timeout(Mockito.java:2856)

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:1
  • Comments:15 (10 by maintainers)

github_iconTop GitHub Comments

3reactions
TimvdLippecommented, Dec 16, 2019

I’d rather revert #1845, and instead introduces compatibility verification modes for pre Java 8 users.

Yeah I would like to recommit java.time.Duration, but would like to solve the problem of compatibility first. Since it is unlikely anyone used this method in the short period (<1 week) it was unavailable, I think the overall impact has been minimal. Given that the value is minimal, but would break the majority of Android users, I think reverting is the correct choice.

We might be able to add the API in a separate class and exclude it in mockito-android? The more prominent problem is that Android has not supported Java 8 features for a long time, which is now a problem.

2reactions
TimvdLippecommented, Dec 19, 2019

I dont have time to provide a full comment (1AM here), but will provide one tomorrow.

For now: please accept my apology for those who used the new Duration API and were impacted by the revert. This has been an unfortunate change that broke a lot of existing Android users. Given the widespread usage of Mockito in the Android community and thus the large impact of the breaking change by relying on java.time.Duration, reverting felt like the least intrusive option. Yes, this would again break users who used the new api, but my assumption was that the amount of users that eagerly upgraded to the new api would be minimal, compared to existing users.

However, we do need to resolve this issue at large, as we should not hold back improvements on Mockito itself, because a different ecosystem is/was lacking behind. For this, I wanted to provide myself and the other core maintainers some more time to make a decision. That’s why I reverted the PR in question, to allow us to make a sensible and thoughtful decision.

I will do a full write-up tomorrow and also notify the Android folks at Google of this issue. Hopefully they can figure out a solution that would not hold libraries like Mockito (but I imagine a lot of other libraries as well) back.

I apologize for any inconvenience caused. Thank you for your understanding. I will comment further tomorrow.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Call requires API level 26 (current min is 23): java.time.Instant ...
My app supports minSdkVersion 23 and java.time.Instant is not supported here. Is there a solution for this, or should i just check for...
Read more >
Duration | Android Developers
This class models a quantity or amount of time in terms of seconds and nanoseconds. It can be accessed using other duration-based units,...
Read more >
Java 8 Date - LocalDate, LocalDateTime, Instant - DigitalOcean
Java Date Time classes are not defined consistently, we have Date Class in both java.util as well as java.sql packages. Again formatting and ......
Read more >
Joda-Time - Home
Joda-Time provides a quality replacement for the Java date and time classes. Joda-Time is the de facto standard date and time library for...
Read more >
Readme — clojure.java-time 1.1.0 - cljdoc
A Clojure wrapper for Java 8 Date-Time API. Note: This library has no relation to Clojure's (or Java's) core team. It's naming is...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found