Skip to content

Commit 4221266

Browse files
authored
[ErrorProne] enable JavaUtilDate, TimeUnitConversionChecker, InvalidThrows checks (#37791)
* enable JavaUtilDate, TimeUnitConversionChecker, InvalidThrows checks * fix outstanding JavaUtilDate and invalidThrows violations
1 parent 4163dc7 commit 4221266

50 files changed

Lines changed: 133 additions & 91 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

buildSrc/src/main/groovy/org/apache/beam/gradle/BeamModulePlugin.groovy

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1542,16 +1542,13 @@ class BeamModulePlugin implements Plugin<Project> {
15421542
"ExtendsAutoValue",
15431543
"InlineMeSuggester",
15441544
"InvalidBlockTag",
1545-
"InvalidThrows",
15461545
"JavaTimeDefaultTimeZone",
1547-
"JavaUtilDate",
15481546
"JodaConstructors",
15491547
"MixedMutabilityReturnType",
15501548
"PreferJavaTimeOverload",
15511549
"NonCanonicalType",
15521550
"Slf4jSignOnlyFormat",
15531551
"ThreadPriorityCheck",
1554-
"TimeUnitConversionChecker",
15551552
"UndefinedEquals",
15561553
"UnescapedEntity",
15571554
"UnnecessaryParentheses",

examples/java/src/main/java/org/apache/beam/examples/complete/datatokenization/utils/SchemasUtils.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,6 @@ public String getJsonBeamSchema() {
132132
*
133133
* @param filePath path to file in GCS
134134
* @return contents of the file as a string
135-
* @throws IOException thrown if not able to read file
136135
*/
137136
public static String getGcsFileAsString(String filePath) {
138137
MatchResult result;

examples/java/src/test/java/org/apache/beam/examples/WindowedWordCountIT.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,10 @@
2020
import static org.hamcrest.MatcherAssert.assertThat;
2121
import static org.hamcrest.Matchers.equalTo;
2222

23+
import java.time.LocalDateTime;
24+
import java.time.ZoneId;
2325
import java.util.ArrayList;
2426
import java.util.Collections;
25-
import java.util.Date;
2627
import java.util.List;
2728
import java.util.SortedMap;
2829
import java.util.TreeMap;
@@ -128,7 +129,9 @@ private WindowedWordCountITOptions defaultOptions() throws Exception {
128129
.resolve(
129130
String.format(
130131
"WindowedWordCountIT.%s-%tFT%<tH:%<tM:%<tS.%<tL+%s",
131-
testName.getMethodName(), new Date(), ThreadLocalRandom.current().nextInt()),
132+
testName.getMethodName(),
133+
LocalDateTime.now(ZoneId.of("UTC")),
134+
ThreadLocalRandom.current().nextInt()),
132135
StandardResolveOptions.RESOLVE_DIRECTORY)
133136
.resolve("output", StandardResolveOptions.RESOLVE_DIRECTORY)
134137
.resolve("results", StandardResolveOptions.RESOLVE_FILE)

examples/java/src/test/java/org/apache/beam/examples/WordCountIT.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@
2020
import static org.apache.beam.sdk.testing.FileChecksumMatcher.fileContentsHaveChecksum;
2121
import static org.hamcrest.MatcherAssert.assertThat;
2222

23-
import java.util.Date;
23+
import java.time.LocalDateTime;
24+
import java.time.ZoneId;
2425
import org.apache.beam.examples.WordCount.WordCountOptions;
2526
import org.apache.beam.sdk.io.FileSystems;
2627
import org.apache.beam.sdk.io.fs.ResolveOptions.StandardResolveOptions;
@@ -61,7 +62,8 @@ public void testE2EWordCount() throws Exception {
6162
options.setOutput(
6263
FileSystems.matchNewResource(options.getTempRoot(), true)
6364
.resolve(
64-
String.format("WordCountIT-%tF-%<tH-%<tM-%<tS-%<tL", new Date()),
65+
String.format(
66+
"WordCountIT-%tF-%<tH-%<tM-%<tS-%<tL", LocalDateTime.now(ZoneId.of("UTC"))),
6567
StandardResolveOptions.RESOLVE_DIRECTORY)
6668
.resolve("output", StandardResolveOptions.RESOLVE_DIRECTORY)
6769
.resolve("results", StandardResolveOptions.RESOLVE_FILE)

examples/java/src/test/java/org/apache/beam/examples/complete/TfIdfIT.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@
2020
import static org.apache.beam.sdk.testing.FileChecksumMatcher.fileContentsHaveChecksum;
2121
import static org.hamcrest.MatcherAssert.assertThat;
2222

23-
import java.util.Date;
23+
import java.time.LocalDateTime;
24+
import java.time.ZoneId;
2425
import java.util.regex.Pattern;
2526
import org.apache.beam.examples.complete.TfIdf.Options;
2627
import org.apache.beam.sdk.io.FileSystems;
@@ -62,7 +63,8 @@ public void testE2ETfIdf() throws Exception {
6263
options.setOutput(
6364
FileSystems.matchNewResource(options.getTempRoot(), true)
6465
.resolve(
65-
String.format("TfIdfIT-%tF-%<tH-%<tM-%<tS-%<tL", new Date()),
66+
String.format(
67+
"TfIdfIT-%tF-%<tH-%<tM-%<tS-%<tL", LocalDateTime.now(ZoneId.of("UTC"))),
6668
StandardResolveOptions.RESOLVE_DIRECTORY)
6769
.resolve("output", StandardResolveOptions.RESOLVE_DIRECTORY)
6870
.resolve("results", StandardResolveOptions.RESOLVE_FILE)

examples/java/src/test/java/org/apache/beam/examples/complete/TopWikipediaSessionsIT.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@
2020
import static org.apache.beam.sdk.testing.FileChecksumMatcher.fileContentsHaveChecksum;
2121
import static org.hamcrest.MatcherAssert.assertThat;
2222

23-
import java.util.Date;
23+
import java.time.LocalDateTime;
24+
import java.time.ZoneId;
2425
import org.apache.beam.sdk.io.FileSystems;
2526
import org.apache.beam.sdk.io.fs.ResolveOptions.StandardResolveOptions;
2627
import org.apache.beam.sdk.options.PipelineOptionsFactory;
@@ -58,7 +59,9 @@ public void testE2ETopWikiPages() throws Exception {
5859
options.setOutput(
5960
FileSystems.matchNewResource(options.getTempRoot(), true)
6061
.resolve(
61-
String.format("topwikisessions-it-%tF-%<tH-%<tM-%<tS-%<tL", new Date()),
62+
String.format(
63+
"topwikisessions-it-%tF-%<tH-%<tM-%<tS-%<tL",
64+
LocalDateTime.now(ZoneId.of("UTC"))),
6265
StandardResolveOptions.RESOLVE_DIRECTORY)
6366
.resolve("output", StandardResolveOptions.RESOLVE_DIRECTORY)
6467
.resolve("results", StandardResolveOptions.RESOLVE_FILE)

examples/java/src/test/java/org/apache/beam/examples/cookbook/DistinctExampleIT.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@
2020
import static org.apache.beam.sdk.testing.FileChecksumMatcher.fileContentsHaveChecksum;
2121
import static org.hamcrest.MatcherAssert.assertThat;
2222

23-
import java.util.Date;
23+
import java.time.LocalDateTime;
24+
import java.time.ZoneId;
2425
import java.util.regex.Pattern;
2526
import org.apache.beam.sdk.io.FileSystems;
2627
import org.apache.beam.sdk.io.fs.ResolveOptions;
@@ -73,7 +74,8 @@ public void testE2EDistinctExample() throws Exception {
7374
options.setOutput(
7475
FileSystems.matchNewResource(options.getTempRoot(), true)
7576
.resolve(
76-
String.format("DistinctExample-%tF-%<tH-%<tM-%<tS-%<tL", new Date()),
77+
String.format(
78+
"DistinctExample-%tF-%<tH-%<tM-%<tS-%<tL", LocalDateTime.now(ZoneId.of("UTC"))),
7779
ResolveOptions.StandardResolveOptions.RESOLVE_DIRECTORY)
7880
.resolve("output", ResolveOptions.StandardResolveOptions.RESOLVE_DIRECTORY)
7981
.resolve("results", ResolveOptions.StandardResolveOptions.RESOLVE_FILE)

examples/java/src/test/java/org/apache/beam/examples/cookbook/JoinExamplesIT.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@
2020
import static org.apache.beam.sdk.testing.FileChecksumMatcher.fileContentsHaveChecksum;
2121
import static org.hamcrest.MatcherAssert.assertThat;
2222

23-
import java.util.Date;
23+
import java.time.LocalDateTime;
24+
import java.time.ZoneId;
2425
import java.util.regex.Pattern;
2526
import org.apache.beam.sdk.io.FileSystems;
2627
import org.apache.beam.sdk.io.fs.ResolveOptions;
@@ -55,7 +56,8 @@ public void testE2EJoinExamples() throws Exception {
5556
options.setOutput(
5657
FileSystems.matchNewResource(options.getTempRoot(), true)
5758
.resolve(
58-
String.format("JoinExamples-%tF-%<tH-%<tM-%<tS-%<tL", new Date()),
59+
String.format(
60+
"JoinExamples-%tF-%<tH-%<tM-%<tS-%<tL", LocalDateTime.now(ZoneId.of("UTC"))),
5961
ResolveOptions.StandardResolveOptions.RESOLVE_DIRECTORY)
6062
.resolve("output", ResolveOptions.StandardResolveOptions.RESOLVE_DIRECTORY)
6163
.resolve("results", ResolveOptions.StandardResolveOptions.RESOLVE_FILE)

examples/java/twitter/src/main/java/org/apache/beam/examples/twitterstreamgenerator/ReadFromTwitterDoFn.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,8 @@ public DoFn.ProcessContinuation processElement(
189189
return DoFn.ProcessContinuation.stop();
190190
}
191191
if (status != null) {
192-
Instant currentInstant = Instant.ofEpochMilli(status.getCreatedAt().getTime());
192+
Instant currentInstant =
193+
Instant.ofEpochMilli(status.getCreatedAt().toInstant().toEpochMilli());
193194
watermarkEstimator.setWatermark(currentInstant);
194195
out.outputWithTimestamp(status.getText(), currentInstant);
195196
}

examples/java/twitter/src/test/java/org/apache/beam/examples/twitterstreamgenerator/ReadFromTwitterDoFnTest.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ public class ReadFromTwitterDoFnTest {
5757
LinkedBlockingQueue<Status> queue2 = new LinkedBlockingQueue<>();
5858

5959
@Before
60+
@SuppressWarnings("JavaUtilDate")
6061
public void setUp() throws JsonProcessingException {
6162
MockitoAnnotations.initMocks(this);
6263
when(status1.getText()).thenReturn("Breaking News1");

0 commit comments

Comments
 (0)