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

PRP-10968 Introduce TimeZoneUsageCheck #9

Merged
merged 5 commits into from
Mar 1, 2021
Merged

Conversation

anna8712
Copy link
Contributor

Introduce a new Error Prone plugin which flags bad practices with objects related to time, which might be critical when we'll handle different time zones in our systems.

This check will flag the bad usages, as a build Warning.

Copy link
Member

@Stephan202 Stephan202 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rebased and added a commit. Suggested commit message:

PRP-10968 Flag discouraged time zone-dependent APIs (#9)

Will merge if you're okay with my changes.

LocalDate.class.getName(),
LocalDateTime.class.getName(),
LocalTime.class.getName())
.namedAnyOf("now"));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
.namedAnyOf("now"));
.named("now"));

@AutoService(BugChecker.class)
@BugPattern(
name = "TimeZoneUsageCheck",
summary = "Avoid illegal operations on assorted time related objects",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
summary = "Avoid illegal operations on assorted time related objects",
summary = "Derive the current time from an existing `Clock` Spring bean, and don't rely on a `Clock`'s time zone",

/** A {@link BugChecker} which flags illegal time-zone related operations. */
@AutoService(BugChecker.class)
@BugPattern(
name = "TimeZoneUsageCheck",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
name = "TimeZoneUsageCheck",
name = "TimeZoneUsage",

"clock.instant();",
"clock.millis();",
"Clock.offset(clock, Duration.ZERO);",
"Clock.tick(clock, Duration.ZERO);",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indentation.

}

@Test
public void testIdentifyCases() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We generally just combine this into a single test class.

Comment on lines 58 to 61
if (!IS_BANNED_TIME_METHOD.matches(tree, state)) {
return Description.NO_MATCH;
}
return buildDescription(tree).build();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rickie why the removed newline? Seems nicer with it :)

Alternatively, let's do:

Suggested change
if (!IS_BANNED_TIME_METHOD.matches(tree, state)) {
return Description.NO_MATCH;
}
return buildDescription(tree).build();
return IS_BANNED_TIME_METHOD.matches(tree, state)
? return buildDescription(tree).build()
: Description.NO_MATCH;

Copy link
Member

@rickie rickie Feb 15, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The line felt more like a direct else that needed to be close to the if, so I removed the line.

I applied the alternative, way better :) @Stephan202

Copy link
Member

@Stephan202 Stephan202 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rebased. @anna8712 okay to merge? :)

@Stephan202
Copy link
Member

^ @anna8712 question about whether to merge this one stands :)

@anna8712
Copy link
Contributor Author

anna8712 commented Mar 1, 2021

^ @anna8712 question about whether to merge this one stands :)

Yes, please! Thanks, @rickie for your contribution! :)

@Stephan202 Stephan202 merged commit f9a1c82 into master Mar 1, 2021
@Stephan202 Stephan202 deleted the anna8712/PRP-10968 branch March 1, 2021 22:08
@Stephan202 Stephan202 added this to the 0.1.0 milestone Apr 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

3 participants