[ErrorProne] JodaConstructors check - Use JodaTime's static factories instead of the ambiguous constructors.#37744
[ErrorProne] JodaConstructors check - Use JodaTime's static factories instead of the ambiguous constructors.#37744stankiewicz wants to merge 4 commits intoapache:masterfrom
Conversation
|
partially fixes #37743 |
Summary of ChangesHello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request refactors the codebase to exclusively use JodaTime's static factory methods for Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Changelog
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
|
Assigning reviewers: R: @chamikaramj for label java. Note: If you would like to opt out of this review, comment Available commands:
The PR bot will only process comments in the main thread (not review comments). |
|
Run Java_IOs_Direct PreCommit |
|
investigating why HCatalog has some different joda time dependency |
|
This change has my support. I haven't looked at every instance but LGTM for the idea and trusting our tests. And I'll ask for AI review to see if it catches anything. |
|
/gemini review |
|
no-op? :) |
There was a problem hiding this comment.
Code Review
This pull request consistently replaces ambiguous Joda-Time constructors like new Instant() and new DateTime() with their corresponding static factory methods (Instant.ofEpochMilli(), Instant.now(), DateTime.now()). This is a good practice that improves code clarity and avoids potential bugs. The changes are applied correctly across the codebase. I've noted a couple of minor improvement opportunities where Instant.now() is called multiple times, which could be refactored for better robustness.
Note: Security Review did not run due to the size of the PR.
| Instant.now().getMillis() | ||
| + windowSize.getMillis() | ||
| - Instant.now().plus(windowSize).getMillis() % windowSize.getMillis()); |
There was a problem hiding this comment.
Calling Instant.now() multiple times within the same expression can lead to inconsistencies if the system clock ticks between the calls. It's safer to call it once and store the result in a local variable before using it. For example:
final Instant now = Instant.now();
Instant nextWindowStart =
Instant.ofEpochMilli(
now.getMillis()
+ windowSize.getMillis()
- now.plus(windowSize).getMillis() % windowSize.getMillis());| TimestampedValue.of( | ||
| new TableRow().set("user", "mobile").set("score", 12).set("gap", 5), | ||
| new Instant()), | ||
| Instant.now()), | ||
| TimestampedValue.of( | ||
| new TableRow().set("user", "desktop").set("score", 4), new Instant()), | ||
| new TableRow().set("user", "desktop").set("score", 4), Instant.now()), | ||
| TimestampedValue.of( | ||
| new TableRow().set("user", "mobile").set("score", -3).set("gap", 5), | ||
| new Instant().plus(Duration.millis(2000))), | ||
| Instant.now().plus(Duration.millis(2000))), | ||
| TimestampedValue.of( | ||
| new TableRow().set("user", "mobile").set("score", 2).set("gap", 5), | ||
| new Instant().plus(Duration.millis(9000))), | ||
| Instant.now().plus(Duration.millis(9000))), | ||
| TimestampedValue.of( | ||
| new TableRow().set("user", "mobile").set("score", 7).set("gap", 5), | ||
| new Instant().plus(Duration.millis(12000))), | ||
| Instant.now().plus(Duration.millis(12000))), | ||
| TimestampedValue.of( | ||
| new TableRow().set("user", "desktop").set("score", 10), | ||
| new Instant().plus(Duration.millis(12000))))); | ||
| Instant.now().plus(Duration.millis(12000))))); |
There was a problem hiding this comment.
There are multiple calls to Instant.now() here. This will result in slightly different timestamps for each TimestampedValue. If the intention is for these events to be relative to a single point in time, it would be better to call Instant.now() once and reuse the value. For example:
final Instant now = Instant.now();
PCollection<TableRow> pc =
p.apply(
"Create Events",
Create.timestamped(
TimestampedValue.of(
new TableRow().set("user", "mobile").set("score", 12).set("gap", 5),
now),
TimestampedValue.of(
new TableRow().set("user", "desktop").set("score", 4), now),
TimestampedValue.of(
new TableRow().set("user", "mobile").set("score", -3).set("gap", 5),
now.plus(Duration.millis(2000))),
// ... and so on
));
Fixes https://errorprone.info/bugpattern/JodaConstructors
Thank you for your contribution! Follow this checklist to help us incorporate your contribution quickly and easily:
addresses #123), if applicable. This will automatically add a link to the pull request in the issue. If you would like the issue to automatically close on merging the pull request, commentfixes #<ISSUE NUMBER>instead.CHANGES.mdwith noteworthy changes.See the Contributor Guide for more tips on how to make review process smoother.
To check the build health, please visit https://github.com/apache/beam/blob/master/.test-infra/BUILD_STATUS.md
GitHub Actions Tests Status (on master branch)
See CI.md for more information about GitHub Actions CI or the workflows README to see a list of phrases to trigger workflows.