Skip to content

Commit

Permalink
[BEAM-10540] Fix nullability in equals methods globally
Browse files Browse the repository at this point in the history
  • Loading branch information
kennknowles committed Jul 22, 2020
1 parent ecedd3e commit 248b794
Show file tree
Hide file tree
Showing 290 changed files with 628 additions and 461 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
public class WriteOneFilePerWindow extends PTransform<PCollection<String>, PDone> {
private static final DateTimeFormatter FORMATTER = ISODateTimeFormat.hourMinute();
private String filenamePrefix;
private @Nullable Integer numShards;
@Nullable private Integer numShards;

public WriteOneFilePerWindow(String filenamePrefix, Integer numShards) {
this.filenamePrefix = filenamePrefix;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
import org.apache.beam.sdk.values.PCollection.IsBounded;
import org.apache.beam.sdk.values.PValue;
import org.apache.beam.vendor.guava.v26_0_jre.com.google.common.base.MoreObjects;
import org.checkerframework.checker.nullness.qual.Nullable;

/**
* A {@link PTransformMatcher} that matches {@link PTransform PTransforms} based on the class of the
Expand Down Expand Up @@ -75,7 +76,7 @@ public String toString() {
}

@Override
public boolean equals(Object o) {
public boolean equals(@Nullable Object o) {
if (this == o) {
return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public Map<TupleTag<?>, PValue> expand() {
}

@Override
public boolean equals(Object other) {
public boolean equals(@Nullable Object other) {
if (!(other instanceof PCollectionView)) {
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import org.apache.beam.sdk.io.FileSystems;
import org.apache.beam.sdk.options.PipelineOptions;
import org.apache.beam.sdk.util.common.ReflectHelpers;
import org.checkerframework.checker.nullness.qual.Nullable;

/**
* Holds a {@link PipelineOptions} in JSON serialized form and calls {@link
Expand Down Expand Up @@ -84,7 +85,7 @@ public String toString() {
}

@Override
public boolean equals(Object o) {
public boolean equals(@Nullable Object o) {
if (this == o) {
return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
import org.apache.beam.sdk.state.Timer;
import org.apache.beam.sdk.state.TimerMap;
import org.apache.beam.sdk.transforms.DoFn;
import org.apache.beam.sdk.transforms.DoFn.StartBundleContext;
import org.apache.beam.sdk.transforms.PTransform;
import org.apache.beam.sdk.transforms.ParDo;
import org.apache.beam.sdk.transforms.Reshuffle;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ public static <K> Timer<K> cleared(
public abstract @Nullable PaneInfo getPane();

@Override
public boolean equals(Object other) {
public boolean equals(@Nullable Object other) {
if (!(other instanceof Timer)) {
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
import org.apache.beam.sdk.values.PCollection;
import org.apache.beam.sdk.values.PCollectionView;
import org.apache.beam.vendor.guava.v26_0_jre.com.google.common.collect.ImmutableList;
import org.checkerframework.checker.nullness.qual.Nullable;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
Expand Down Expand Up @@ -226,7 +227,7 @@ public Void addInput(Void accumulator, Integer input) {
}

@Override
public boolean equals(Object other) {
public boolean equals(@Nullable Object other) {
return other != null && other.getClass().equals(TestCombineFn.class);
}

Expand Down Expand Up @@ -265,7 +266,7 @@ public Integer extractOutput(int[] accumulator, Context c) {
}

@Override
public boolean equals(Object other) {
public boolean equals(@Nullable Object other) {
return other instanceof TestCombineFnWithContext;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import org.apache.beam.sdk.transforms.ViewFn;
import org.apache.beam.sdk.transforms.windowing.GlobalWindows;
import org.apache.beam.sdk.values.TypeDescriptor;
import org.checkerframework.checker.nullness.qual.Nullable;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
Expand Down Expand Up @@ -69,7 +70,7 @@ public TypeDescriptor<Object> getTypeDescriptor() {
}

@Override
public boolean equals(Object obj) {
public boolean equals(@Nullable Object obj) {
return obj instanceof TestViewFn;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,6 @@
import org.apache.beam.sdk.transforms.Combine.BinaryCombineLongFn;
import org.apache.beam.sdk.transforms.Create;
import org.apache.beam.sdk.transforms.DoFn;
import org.apache.beam.sdk.transforms.DoFn.BundleFinalizer;
import org.apache.beam.sdk.transforms.DoFn.ProcessElement;
import org.apache.beam.sdk.transforms.DoFnSchemaInformation;
import org.apache.beam.sdk.transforms.ParDo;
import org.apache.beam.sdk.transforms.ParDo.MultiOutput;
Expand All @@ -69,6 +67,7 @@
import org.apache.beam.sdk.values.TupleTagList;
import org.apache.beam.sdk.values.WindowingStrategy;
import org.apache.beam.vendor.guava.v26_0_jre.com.google.common.collect.ImmutableList;
import org.checkerframework.checker.nullness.qual.Nullable;
import org.junit.Test;
import org.junit.experimental.runners.Enclosed;
import org.junit.runner.RunWith;
Expand Down Expand Up @@ -251,7 +250,7 @@ public void proc(ProcessContext context, BoundedWindow window) {
}

@Override
public boolean equals(Object other) {
public boolean equals(@Nullable Object other) {
return other instanceof DropElementsFn;
}

Expand All @@ -278,7 +277,7 @@ public Integer restriction(@Element KV<Long, String> elem) {
}

@Override
public boolean equals(Object other) {
public boolean equals(@Nullable Object other) {
return other instanceof SplittableDropElementsFn;
}

Expand Down Expand Up @@ -337,7 +336,7 @@ public void onEventTime(OnTimerContext context) {}
public void onProcessingTime(OnTimerContext context) {}

@Override
public boolean equals(Object other) {
public boolean equals(@Nullable Object other) {
return other instanceof StateTimerDropElementsFn;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ public Coder<String> getOutputCoder() {
}

@Override
public boolean equals(Object other) {
public boolean equals(@Nullable Object other) {
return other != null && other.getClass().equals(TestBoundedSource.class);
}

Expand Down Expand Up @@ -148,7 +148,7 @@ public Coder<CheckpointMark> getCheckpointMarkCoder() {
}

@Override
public boolean equals(Object other) {
public boolean equals(@Nullable Object other) {
return other != null && other.getClass().equals(TestUnboundedSource.class);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
import org.apache.beam.sdk.transforms.windowing.WindowFn;
import org.apache.beam.vendor.grpc.v1p26p0.com.google.protobuf.InvalidProtocolBufferException;
import org.apache.beam.vendor.guava.v26_0_jre.com.google.common.collect.ImmutableList;
import org.checkerframework.checker.nullness.qual.Nullable;
import org.joda.time.Duration;
import org.joda.time.Instant;
import org.junit.Rule;
Expand Down Expand Up @@ -112,7 +113,7 @@ public Coder<BoundedWindow> windowCoder() {
}

@Override
public boolean equals(Object other) {
public boolean equals(@Nullable Object other) {
return other != null && other.getClass().equals(this.getClass());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ public WriteOperation<Void, Object> createWriteOperation() {
}

@Override
public boolean equals(Object other) {
public boolean equals(@Nullable Object other) {
if (!(other instanceof DummySink)) {
return false;
}
Expand Down Expand Up @@ -174,7 +174,7 @@ public ResourceId unwindowedFilename(
}

@Override
public boolean equals(Object other) {
public boolean equals(@Nullable Object other) {
return other instanceof DummyFilenamePolicy;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

import java.nio.charset.StandardCharsets;
import org.apache.beam.model.pipeline.v1.RunnerApi;
import org.apache.beam.model.pipeline.v1.RunnerApi.AccumulationMode.Enum;
import org.apache.beam.model.pipeline.v1.RunnerApi.AccumulationMode;
import org.apache.beam.model.pipeline.v1.RunnerApi.Coder;
import org.apache.beam.model.pipeline.v1.RunnerApi.Components;
import org.apache.beam.model.pipeline.v1.RunnerApi.ComponentsOrBuilder;
Expand Down Expand Up @@ -80,7 +80,9 @@ public void replacesOnlyMatching() {
ByteString.copyFrom("foo-bar-baz".getBytes(StandardCharsets.UTF_8))))
.build();
WindowingStrategy introducedWS =
WindowingStrategy.newBuilder().setAccumulationMode(Enum.ACCUMULATING).build();
WindowingStrategy.newBuilder()
.setAccumulationMode(AccumulationMode.Enum.ACCUMULATING)
.build();
RunnerApi.Components extraComponents =
Components.newBuilder()
.putPcollections(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import org.apache.beam.sdk.util.WindowedValue;
import org.apache.beam.vendor.guava.v26_0_jre.com.google.common.base.MoreObjects;
import org.apache.beam.vendor.guava.v26_0_jre.com.google.common.collect.Iterables;
import org.checkerframework.checker.nullness.qual.Nullable;

/** Static utility methods that provide {@link KeyedWorkItem} implementations. */
public class KeyedWorkItems {
Expand Down Expand Up @@ -93,7 +94,7 @@ public Iterable<WindowedValue<ElemT>> elementsIterable() {
}

@Override
public boolean equals(Object other) {
public boolean equals(@Nullable Object other) {
if (other == null || !(other instanceof ComposedKeyedWorkItem)) {
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,7 @@ public String toString() {
}

@Override
public boolean equals(Object o) {
public boolean equals(@Nullable Object o) {
if (!(o instanceof MergingActiveWindowSet)) {
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

import java.io.IOException;
import java.util.Objects;
import org.checkerframework.checker.nullness.qual.Nullable;

/** A simple {@link StateNamespace} used for testing. */
public class StateNamespaceForTest implements StateNamespace {
Expand All @@ -39,7 +40,7 @@ public Object getCacheKey() {
}

@Override
public boolean equals(Object obj) {
public boolean equals(@Nullable Object obj) {
if (this == obj) {
return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import org.apache.beam.sdk.transforms.windowing.BoundedWindow;
import org.apache.beam.sdk.util.CoderUtils;
import org.apache.beam.vendor.guava.v26_0_jre.com.google.common.base.Splitter;
import org.checkerframework.checker.nullness.qual.Nullable;

/** Factory methods for creating the {@link StateNamespace StateNamespaces}. */
public class StateNamespaces {
Expand Down Expand Up @@ -66,7 +67,7 @@ public Object getCacheKey() {
}

@Override
public boolean equals(Object obj) {
public boolean equals(@Nullable Object obj) {
return obj == this || obj instanceof GlobalNamespace;
}

Expand Down Expand Up @@ -123,7 +124,7 @@ public Object getCacheKey() {
}

@Override
public boolean equals(Object obj) {
public boolean equals(@Nullable Object obj) {
if (obj == this) {
return true;
}
Expand Down Expand Up @@ -204,7 +205,7 @@ public Object getCacheKey() {
}

@Override
public boolean equals(Object obj) {
public boolean equals(@Nullable Object obj) {
if (obj == this) {
return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
import org.apache.beam.sdk.transforms.windowing.TimestampCombiner;
import org.apache.beam.vendor.guava.v26_0_jre.com.google.common.base.Equivalence;
import org.apache.beam.vendor.guava.v26_0_jre.com.google.common.base.MoreObjects;
import org.checkerframework.checker.nullness.qual.Nullable;

/** Static utility methods for creating {@link StateTag} instances. */
public class StateTags {
Expand Down Expand Up @@ -255,7 +256,7 @@ public String toString() {
}

@Override
public boolean equals(Object obj) {
public boolean equals(@Nullable Object obj) {
if (obj == this) {
return true;
}
Expand Down Expand Up @@ -319,7 +320,7 @@ public StateTag<StateT> asKind(StateKind kind) {
}

@Override
public boolean equals(Object other) {
public boolean equals(@Nullable Object other) {
if (!(other instanceof SimpleStateTag)) {
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import org.apache.beam.sdk.metrics.Counter;
import org.apache.beam.sdk.metrics.MetricName;
import org.apache.beam.sdk.metrics.MetricsContainer;
import org.checkerframework.checker.nullness.qual.Nullable;

/**
* Tracks the current value (and delta) for a Counter metric for a specific context and bundle.
Expand Down Expand Up @@ -94,7 +95,7 @@ public MetricName getName() {
}

@Override
public boolean equals(Object object) {
public boolean equals(@Nullable Object object) {
if (object instanceof CounterCell) {
CounterCell counterCell = (CounterCell) object;
return Objects.equals(dirty, counterCell.dirty)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import java.io.Serializable;
import java.util.Objects;
import java.util.concurrent.atomic.AtomicReference;
import org.checkerframework.checker.nullness.qual.Nullable;

/**
* Atomically tracks the dirty-state of a metric.
Expand Down Expand Up @@ -93,7 +94,7 @@ public void afterCommit() {
}

@Override
public boolean equals(Object object) {
public boolean equals(@Nullable Object object) {
if (object instanceof DirtyState) {
DirtyState dirtyState = (DirtyState) object;
return Objects.equals(dirty.get(), dirtyState.dirty.get());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import org.apache.beam.sdk.metrics.Distribution;
import org.apache.beam.sdk.metrics.MetricName;
import org.apache.beam.sdk.metrics.MetricsContainer;
import org.checkerframework.checker.nullness.qual.Nullable;

/**
* Tracks the current value (and delta) for a Distribution metric.
Expand Down Expand Up @@ -88,7 +89,7 @@ public MetricName getName() {
}

@Override
public boolean equals(Object object) {
public boolean equals(@Nullable Object object) {
if (object instanceof DistributionCell) {
DistributionCell distributionCell = (DistributionCell) object;
return Objects.equals(dirty, distributionCell.dirty)
Expand Down
Loading

0 comments on commit 248b794

Please sign in to comment.