Skip to content

Commit b42c992

Browse files
authored
[ErrorProne] Fix BadInstanceof and enable check (#37753)
1 parent 8289148 commit b42c992

18 files changed

Lines changed: 23 additions & 26 deletions

File tree

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1535,7 +1535,6 @@ class BeamModulePlugin implements Plugin<Project> {
15351535
"AutoValueImmutableFields",
15361536
"AutoValueSubclassLeaked",
15371537
"BadImport",
1538-
"BadInstanceof",
15391538
"BigDecimalEquals",
15401539
"ComparableType",
15411540
"DoNotMockAutoValue",

runners/flink/2.0/src/test/java/org/apache/beam/runners/flink/translation/functions/ImpulseSourceFunctionTest.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -201,8 +201,7 @@ private static class ImpulseElementMatcher implements ArgumentMatcher<WindowedVa
201201

202202
@Override
203203
public boolean matches(WindowedValue<byte[]> o) {
204-
return o instanceof WindowedValue
205-
&& Arrays.equals((byte[]) ((WindowedValue) o).getValue(), new byte[] {});
204+
return o != null && Arrays.equals(o.getValue(), new byte[] {});
206205
}
207206
}
208207
}

runners/flink/src/main/java/org/apache/beam/runners/flink/FlinkStreamingTranslationContext.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ public <T> Coder<T> getInputCoder(PCollection<T> collection) {
123123

124124
public Map<TupleTag<?>, Coder<?>> getOutputCoders() {
125125
return currentTransform.getOutputs().entrySet().stream()
126-
.filter(e -> e.getValue() instanceof PCollection)
126+
.filter(e -> e.getValue() != null)
127127
.collect(Collectors.toMap(e -> e.getKey(), e -> ((PCollection) e.getValue()).getCoder()));
128128
}
129129

runners/flink/src/main/java/org/apache/beam/runners/flink/PipelineTranslationModeOptimizer.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ public void visitPrimitiveTransform(TransformHierarchy.Node node) {
7474

7575
private boolean hasUnboundedOutput(AppliedPTransform<?, ?, ?> transform) {
7676
return transform.getOutputs().values().stream()
77-
.filter(value -> value instanceof PCollection)
77+
.filter(value -> value != null)
7878
.map(value -> (PCollection<?>) value)
7979
.anyMatch(collection -> collection.isBounded() == IsBounded.UNBOUNDED);
8080
}

runners/flink/src/main/java/org/apache/beam/runners/flink/translation/utils/LookupPipelineVisitor.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ public <T extends PValue> T getOutput(PTransform<?, T> transform) {
9292
@SuppressWarnings("unchecked")
9393
public Map<TupleTag<?>, Coder<?>> getOutputCoders(PTransform<?, ?> transform) {
9494
return getOutputs(transform).entrySet().stream()
95-
.filter(e -> e.getValue() instanceof PCollection)
95+
.filter(e -> e.getValue() != null)
9696
.collect(Collectors.toMap(Map.Entry::getKey, e -> ((PCollection) e.getValue()).getCoder()));
9797
}
9898
}

runners/flink/src/test/java/org/apache/beam/runners/flink/translation/functions/ImpulseSourceFunctionTest.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -201,8 +201,7 @@ private static class ImpulseElementMatcher implements ArgumentMatcher<WindowedVa
201201

202202
@Override
203203
public boolean matches(WindowedValue<byte[]> o) {
204-
return o instanceof WindowedValue
205-
&& Arrays.equals((byte[]) ((WindowedValue) o).getValue(), new byte[] {});
204+
return o != null && Arrays.equals(o.getValue(), new byte[] {});
206205
}
207206
}
208207
}

runners/jet/src/main/java/org/apache/beam/runners/jet/Utils.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ static <T> Map<T, Coder> getCoders(
147147
static Map<TupleTag<?>, Coder<?>> getOutputValueCoders(
148148
AppliedPTransform<?, ?, ?> appliedTransform) {
149149
return appliedTransform.getOutputs().entrySet().stream()
150-
.filter(e -> e.getValue() instanceof PCollection)
150+
.filter(e -> e.getValue() != null)
151151
.collect(Collectors.toMap(Map.Entry::getKey, e -> ((PCollection) e.getValue()).getCoder()));
152152
}
153153

runners/samza/src/main/java/org/apache/beam/runners/samza/translation/ParDoBoundMultiTranslator.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ private static <InT, OutT> void doTranslate(
113113
final PCollection<? extends InT> input = ctx.getInput(transform);
114114
final Map<TupleTag<?>, Coder<?>> outputCoders =
115115
ctx.getCurrentTransform().getOutputs().entrySet().stream()
116-
.filter(e -> e.getValue() instanceof PCollection)
116+
.filter(e -> e.getValue() != null)
117117
.collect(
118118
Collectors.toMap(e -> e.getKey(), e -> ((PCollection<?>) e.getValue()).getCoder()));
119119

@@ -145,7 +145,7 @@ private static <InT, OutT> void doTranslate(
145145
final Map.Entry<TupleTag<?>, PCollection<?>> taggedOutput = outputs.get(index);
146146
tagToIndexMap.put(taggedOutput.getKey(), index);
147147

148-
if (!(taggedOutput.getValue() instanceof PCollection)) {
148+
if (taggedOutput.getValue() == null) {
149149
throw new IllegalArgumentException(
150150
"Expected side output to be PCollection, but was: " + taggedOutput.getValue());
151151
}

runners/samza/src/main/java/org/apache/beam/runners/samza/translation/SplittableParDoTranslators.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ public void translate(
7878
final Map.Entry<TupleTag<?>, PCollection<?>> taggedOutput = outputs.get(index);
7979
tagToIndexMap.put(taggedOutput.getKey(), index);
8080

81-
if (!(taggedOutput.getValue() instanceof PCollection)) {
81+
if (taggedOutput.getValue() == null) {
8282
throw new IllegalArgumentException(
8383
"Expected side output to be PCollection, but was: " + taggedOutput.getValue());
8484
}

runners/spark/src/main/java/org/apache/beam/runners/spark/translation/EvaluationContext.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ public Map<TupleTag<?>, PCollection<?>> getOutputs(PTransform<?, ?> transform) {
144144

145145
public Map<TupleTag<?>, Coder<?>> getOutputCoders() {
146146
return currentTransform.getOutputs().entrySet().stream()
147-
.filter(e -> e.getValue() instanceof PCollection)
147+
.filter(e -> e.getValue() != null)
148148
.collect(Collectors.toMap(Map.Entry::getKey, e -> ((PCollection) e.getValue()).getCoder()));
149149
}
150150

0 commit comments

Comments
 (0)