Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JdkObsolete: Date.from(Instant) #1672

Closed
ben-manes opened this issue Jun 8, 2020 · 5 comments · Fixed by #1677
Closed

JdkObsolete: Date.from(Instant) #1672

ben-manes opened this issue Jun 8, 2020 · 5 comments · Fixed by #1677
Assignees

Comments

@ben-manes
Copy link

Description of the problem / feature request:

warning: [JdkObsolete] Date has a bad API that leads to bugs; prefer java.time.Instant or LocalDate.
    .startAt(Date.from(startTime.toInstant()))
                      ^
    (see https://errorprone.info/bugpattern/JdkObsolete)

Feature requests: what underlying problem are you trying to solve with this feature?

When bridging with legacy, external libraries that use Date then a conversion is needed. While a benefit if those libraries were upgraded, some may be no longer actively maintained while still being useful.

It would be nice if Date.from did not trigger the warning, ideally suppressing it for the entire method block.

@ben-manes
Copy link
Author

Similarly, Date.toInstant() is a warning and should be allowed.

@kluever
Copy link
Member

kluever commented Jun 9, 2020

Hey Ben,

As I'm sure you're aware, the Date API is really bug prone. Given that this is just a warning, I'm inclined to leave it (since Date isn't actually deprecated, this was our next best solution).

Just curious: what legacy API is forcing you to pass a Date?

@ben-manes
Copy link
Author

Yep, I suppressed without much fuss :)

  1. Quickbooks SDK has it in their generated jaxb code. There are 3rd party java.time adapters, but many older vendors don't provide that (though thankfully many offer their xsd / wsdl instead of a client).
  2. Quartz is an old database-driven job scheduler that hasn't been actively developed since Java 6 or so. It was written prior to java.time and uses Dates for setting the start and end time, and to obtain the previous/next fire times when inspecting during a running job. While old and crusty, the library is still quite useful at low scale due to being easy to debug thanks to sql inspection of its core tables. It is a reasonable tool to grow out of when the product needs additional scalability, making it a good fit for an early stage startup where there is limited engineering time.

@boris-petrov
Copy link

This issue is somewhat related/duplicate of #1646.

@kluever
Copy link
Member

kluever commented Jun 9, 2020

I have a fix for this internally.

@kluever kluever self-assigned this Jun 9, 2020
cpovirk pushed a commit that referenced this issue Jun 9, 2020
… these are often needed for interoping with a legacy API.

Fixes #1672

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=315510902
@kluever kluever closed this as completed Jun 9, 2020
cpovirk pushed a commit that referenced this issue Jun 10, 2020
… these are often needed for interoping with a legacy API.

Fixes #1672

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=315510902
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants