Skip to content

Commit 3a19ef1

Browse files
authored
Enable error-prone checks: ClassInitializationDeadlock, Finalize, NullableTypeParameter, ThreadPriorityCheck (#37788)
1 parent ff68119 commit 3a19ef1

12 files changed

Lines changed: 22 additions & 11 deletions

File tree

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

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1546,22 +1546,15 @@ class BeamModulePlugin implements Plugin<Project> {
15461546
"PreferJavaTimeOverload",
15471547
"NonCanonicalType",
15481548
"Slf4jSignOnlyFormat",
1549-
"ThreadPriorityCheck",
15501549
"UndefinedEquals",
15511550
"UnescapedEntity",
15521551
"UnrecognisedJavadocTag",
15531552
// errorprone 3.2.0+ checks
15541553
"DirectInvocationOnMock",
1555-
"Finalize",
15561554
"JUnitIncompatibleType",
15571555
"MockNotUsedInProduction",
1558-
"NullableTypeParameter",
15591556
"NullableWildcard",
15601557
"SuperCallToObjectMethod",
1561-
// intended suppressions emerged in newer protobuf versions
1562-
// For backward compatibility. Public method checked in before this check impl
1563-
// Possible use in interface subclasses
1564-
"ClassInitializationDeadlock",
15651558
// for encoding efficiency and backward compatibility
15661559
"EnumOrdinal",
15671560
// widely used in non-public methods

runners/google-cloud-dataflow-java/worker/src/main/java/org/apache/beam/runners/dataflow/worker/ApplianceShuffleReader.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ public void close() {
7777
}
7878

7979
@Override
80+
@SuppressWarnings("Finalize")
8081
protected void finalize() {
8182
destroySynchronized();
8283
}

runners/google-cloud-dataflow-java/worker/src/main/java/org/apache/beam/runners/dataflow/worker/ApplianceShuffleWriter.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ public ApplianceShuffleWriter(
5555
}
5656

5757
@Override
58+
@SuppressWarnings("Finalize")
5859
protected void finalize() {
5960
destroy();
6061
}

runners/google-cloud-dataflow-java/worker/src/main/java/org/apache/beam/runners/dataflow/worker/BatchDataflowWorker.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,7 @@ private static DebugCapture.Manager initializeAndStartDebugCaptureManager(
180180
return result;
181181
}
182182

183+
@SuppressWarnings("ThreadPriorityCheck")
183184
private static Thread startMemoryMonitorThread(MemoryMonitor memoryMonitor) {
184185
Thread result = new Thread(memoryMonitor);
185186
result.setDaemon(true);

runners/google-cloud-dataflow-java/worker/src/main/java/org/apache/beam/runners/dataflow/worker/windmill/WindmillServerBase.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ protected WindmillServerBase(String host) {
4545
}
4646

4747
@Override
48+
@SuppressWarnings("Finalize")
4849
protected void finalize() {
4950
destroy(nativePointer);
5051
}

sdks/java/core/src/main/java/org/apache/beam/sdk/io/UnboundedSource.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,7 @@ public interface CheckpointMark {
145145
*/
146146
void finalizeCheckpoint() throws IOException;
147147

148+
@SuppressWarnings("ClassInitializationDeadlock")
148149
NoopCheckpointMark NOOP_CHECKPOINT_MARK = new NoopCheckpointMark();
149150

150151
/** A checkpoint mark that does nothing when finalized. */

sdks/java/core/src/main/java/org/apache/beam/sdk/transforms/reflect/DoFnSignature.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,7 @@ default boolean observesWindow() {
284284
}
285285

286286
/** A descriptor for an optional parameter of the {@link DoFn.ProcessElement} method. */
287+
@SuppressWarnings("ClassInitializationDeadlock")
287288
public abstract static class Parameter {
288289

289290
// Private as no extensions other than those nested here are permitted

sdks/java/core/src/main/java/org/apache/beam/sdk/util/UnboundedScheduledExecutorService.java

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ public final class UnboundedScheduledExecutorService implements ScheduledExecuto
7777
value = "EQ_COMPARETO_USE_OBJECT_EQUALS",
7878
justification =
7979
"Default equals/hashCode is what we want since two scheduled tasks are only equivalent if they point to the same instance.")
80+
@SuppressWarnings("NullableTypeParameter")
8081
final class ScheduledFutureTask<@Nullable @KeyForBottom V> extends FutureTask<V>
8182
implements RunnableScheduledFuture<V> {
8283

@@ -373,6 +374,7 @@ public void execute(Runnable command) {
373374
}
374375

375376
@Override
377+
@SuppressWarnings("NullableTypeParameter")
376378
public Future<@Nullable ?> submit(Runnable command) {
377379
if (command == null) {
378380
throw new NullPointerException();
@@ -384,7 +386,7 @@ public void execute(Runnable command) {
384386

385387
@Override
386388
/* Ignore improper flag since FB detects that ScheduledExecutorService can't have nullable V. */
387-
@SuppressWarnings("override.return")
389+
@SuppressWarnings({"override.return", "NullableTypeParameter"})
388390
public <@Nullable @KeyForBottom T> Future<T> submit(Runnable command, T result) {
389391
if (command == null) {
390392
throw new NullPointerException();
@@ -396,7 +398,7 @@ public void execute(Runnable command) {
396398

397399
@Override
398400
/* Ignore improper flag since FB detects that ScheduledExecutorService can't have nullable V. */
399-
@SuppressWarnings({"override.param", "override.return"})
401+
@SuppressWarnings({"override.param", "override.return", "NullableTypeParameter"})
400402
public <@Nullable @KeyForBottom T> Future<T> submit(Callable<T> command) {
401403
if (command == null) {
402404
throw new NullPointerException();
@@ -436,6 +438,7 @@ public void execute(Runnable command) {
436438
}
437439

438440
@Override
441+
@SuppressWarnings("NullableTypeParameter")
439442
public ScheduledFuture<@Nullable ?> schedule(Runnable command, long delay, TimeUnit unit) {
440443
if (command == null || unit == null) {
441444
throw new NullPointerException();
@@ -448,7 +451,7 @@ public void execute(Runnable command) {
448451

449452
@Override
450453
/* Ignore improper flag since FB detects that ScheduledExecutorService can't have nullable V. */
451-
@SuppressWarnings({"override.param", "override.return"})
454+
@SuppressWarnings({"override.param", "override.return", "NullableTypeParameter"})
452455
public <@Nullable @KeyForBottom V> ScheduledFuture<V> schedule(
453456
Callable<V> callable, long delay, TimeUnit unit) {
454457
if (callable == null || unit == null) {
@@ -460,6 +463,7 @@ public void execute(Runnable command) {
460463
}
461464

462465
@Override
466+
@SuppressWarnings("NullableTypeParameter")
463467
public ScheduledFuture<@Nullable ?> scheduleAtFixedRate(
464468
Runnable command, long initialDelay, long period, TimeUnit unit) {
465469
if (command == null || unit == null) {
@@ -476,6 +480,7 @@ public void execute(Runnable command) {
476480
}
477481

478482
@Override
483+
@SuppressWarnings("NullableTypeParameter")
479484
public ScheduledFuture<@Nullable ?> scheduleWithFixedDelay(
480485
Runnable command, long initialDelay, long delay, TimeUnit unit) {
481486
if (command == null || unit == null) {
@@ -491,6 +496,7 @@ public void execute(Runnable command) {
491496
return task;
492497
}
493498

499+
@SuppressWarnings("NullableTypeParameter")
494500
private <@Nullable @KeyForBottom T> void runNowOrScheduleInTheFuture(
495501
ScheduledFutureTask<T> task) {
496502
long nanosToWait = LongMath.saturatedSubtract(task.time, clock.nanoTime());

sdks/java/harness/src/main/java/org/apache/beam/fn/harness/status/BeamFnStatusClient.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ public class BeamFnStatusClient implements AutoCloseable {
5959
private final MemoryMonitor memoryMonitor;
6060
private final Cache<?, ?> cache;
6161

62+
@SuppressWarnings("ThreadPriorityCheck")
6263
@SuppressFBWarnings("SC_START_IN_CTOR") // for memory monitor thread
6364
public BeamFnStatusClient(
6465
ApiServiceDescriptor apiServiceDescriptor,

sdks/java/io/iceberg/src/test/java/org/apache/beam/sdk/io/iceberg/catalog/hiveutils/ScriptRunner.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
* href="https://github.com/apache/iceberg/blob/main/hive-metastore/src/test/java/org/apache/iceberg/hive/ScriptRunner.java">Iceberg's
3535
* integration testing</a>
3636
*/
37-
@SuppressWarnings({"OperatorPrecedence", "DefaultCharset"})
37+
@SuppressWarnings({"OperatorPrecedence", "DefaultCharset", "ThreadPriorityCheck"})
3838
public class ScriptRunner {
3939

4040
private static final String DEFAULT_DELIMITER = ";";

0 commit comments

Comments
 (0)