Skip to content

Commit 7ba0efd

Browse files
authored
[ErrorProne] Enable MutablePublicArray Error Prone Check (#37761)
1 parent eb5f995 commit 7ba0efd

7 files changed

Lines changed: 40 additions & 43 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
@@ -1559,7 +1559,6 @@ class BeamModulePlugin implements Plugin<Project> {
15591559
"MissingSummary",
15601560
"MixedMutabilityReturnType",
15611561
"PreferJavaTimeOverload",
1562-
"MutablePublicArray",
15631562
"NonCanonicalType",
15641563
"ProtectedMembersInFinalClass",
15651564
"Slf4jFormatShouldBeConst",

sdks/java/core/src/test/java/org/apache/beam/sdk/TestUtils.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,11 @@ public class TestUtils {
2929
// Do not instantiate.
3030
private TestUtils() {}
3131

32-
public static final String[] NO_LINES_ARRAY = new String[] {};
32+
private static final String[] NO_LINES_ARRAY = new String[] {};
3333

3434
public static final List<String> NO_LINES = Arrays.asList(NO_LINES_ARRAY);
3535

36-
public static final String[] LINES_ARRAY =
36+
private static final String[] LINES_ARRAY =
3737
new String[] {
3838
"To be, or not to be: that is the question: ",
3939
"Whether 'tis nobler in the mind to suffer ",
@@ -74,15 +74,15 @@ private TestUtils() {}
7474

7575
public static final List<String> LINES = Arrays.asList(LINES_ARRAY);
7676

77-
public static final String[] LINES2_ARRAY = new String[] {"hi", "there", "bob!"};
77+
private static final String[] LINES2_ARRAY = new String[] {"hi", "there", "bob!"};
7878

7979
public static final List<String> LINES2 = Arrays.asList(LINES2_ARRAY);
8080

81-
public static final Integer[] NO_INTS_ARRAY = new Integer[] {};
81+
private static final Integer[] NO_INTS_ARRAY = new Integer[] {};
8282

8383
public static final List<Integer> NO_INTS = Arrays.asList(NO_INTS_ARRAY);
8484

85-
public static final Integer[] INTS_ARRAY =
85+
private static final Integer[] INTS_ARRAY =
8686
new Integer[] {3, 42, Integer.MAX_VALUE, 0, -1, Integer.MIN_VALUE, 666};
8787

8888
public static final List<Integer> INTS = Arrays.asList(INTS_ARRAY);

sdks/java/core/src/test/java/org/apache/beam/sdk/io/TextIOReadTest.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@
1818
package org.apache.beam.sdk.io;
1919

2020
import static java.nio.charset.StandardCharsets.UTF_8;
21-
import static org.apache.beam.sdk.TestUtils.LINES_ARRAY;
22-
import static org.apache.beam.sdk.TestUtils.NO_LINES_ARRAY;
21+
import static org.apache.beam.sdk.TestUtils.LINES;
22+
import static org.apache.beam.sdk.TestUtils.NO_LINES;
2323
import static org.apache.beam.sdk.io.Compression.AUTO;
2424
import static org.apache.beam.sdk.io.Compression.BZIP2;
2525
import static org.apache.beam.sdk.io.Compression.DEFLATE;
@@ -767,13 +767,13 @@ public void testReadStringsWithCustomDelimiter_PartialDelimiterMatchedAtBoundary
767767
@Test
768768
@Category(NeedsRunner.class)
769769
public void testReadStrings() throws Exception {
770-
runTestRead(LINES_ARRAY);
770+
runTestRead(LINES.toArray(new String[0]));
771771
}
772772

773773
@Test
774774
@Category(NeedsRunner.class)
775775
public void testReadEmptyStrings() throws Exception {
776-
runTestRead(NO_LINES_ARRAY);
776+
runTestRead(NO_LINES.toArray(new String[0]));
777777
}
778778

779779
@Test

sdks/java/core/src/test/java/org/apache/beam/sdk/io/TextIOWriteTest.java

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@
1717
*/
1818
package org.apache.beam.sdk.io;
1919

20-
import static org.apache.beam.sdk.TestUtils.LINES2_ARRAY;
21-
import static org.apache.beam.sdk.TestUtils.LINES_ARRAY;
22-
import static org.apache.beam.sdk.TestUtils.NO_LINES_ARRAY;
20+
import static org.apache.beam.sdk.TestUtils.LINES;
21+
import static org.apache.beam.sdk.TestUtils.LINES2;
22+
import static org.apache.beam.sdk.TestUtils.NO_LINES;
2323
import static org.apache.beam.sdk.io.fs.MatchResult.Status.NOT_FOUND;
2424
import static org.apache.beam.sdk.transforms.display.DisplayDataMatchers.hasDisplayItem;
2525
import static org.apache.beam.vendor.guava.v32_1_2_jre.com.google.common.base.MoreObjects.firstNonNull;
@@ -551,49 +551,49 @@ private static Predicate<List<String>> haveProperHeaderAndFooter(
551551
@Test
552552
@Category(NeedsRunner.class)
553553
public void testWriteStrings() throws Exception {
554-
runTestWrite(LINES_ARRAY);
554+
runTestWrite(LINES.toArray(new String[0]));
555555
}
556556

557557
@Test
558558
@Category(NeedsRunner.class)
559559
public void testWriteEmptyStringsNoSharding() throws Exception {
560-
runTestWrite(NO_LINES_ARRAY, 0);
560+
runTestWrite(NO_LINES.toArray(new String[0]), 0);
561561
}
562562

563563
@Test
564564
@Category(NeedsRunner.class)
565565
public void testWriteEmptyStrings() throws Exception {
566-
runTestWrite(NO_LINES_ARRAY);
566+
runTestWrite(NO_LINES.toArray(new String[0]));
567567
}
568568

569569
@Test
570570
@Category(NeedsRunner.class)
571571
public void testWriteEmptyStringsSkipIfEmpty() throws Exception {
572-
runTestWrite(NO_LINES_ARRAY, null, null, 0, true);
572+
runTestWrite(NO_LINES.toArray(new String[0]), null, null, 0, true);
573573
}
574574

575575
@Test
576576
@Category(NeedsRunner.class)
577577
public void testShardedWrite() throws Exception {
578-
runTestWrite(LINES_ARRAY, 5);
578+
runTestWrite(LINES.toArray(new String[0]), 5);
579579
}
580580

581581
@Test
582582
@Category(NeedsRunner.class)
583583
public void testWriteWithHeader() throws Exception {
584-
runTestWrite(LINES_ARRAY, MY_HEADER, null);
584+
runTestWrite(LINES.toArray(new String[0]), MY_HEADER, null);
585585
}
586586

587587
@Test
588588
@Category(NeedsRunner.class)
589589
public void testWriteWithFooter() throws Exception {
590-
runTestWrite(LINES_ARRAY, null, MY_FOOTER);
590+
runTestWrite(LINES.toArray(new String[0]), null, MY_FOOTER);
591591
}
592592

593593
@Test
594594
@Category(NeedsRunner.class)
595595
public void testWriteWithHeaderAndFooter() throws Exception {
596-
runTestWrite(LINES_ARRAY, MY_HEADER, MY_FOOTER);
596+
runTestWrite(LINES.toArray(new String[0]), MY_HEADER, MY_FOOTER);
597597
}
598598

599599
@Test
@@ -605,7 +605,8 @@ public void testWriteWithWritableByteChannelFactory() throws Exception {
605605
FileSystems.matchNewResource(
606606
Files.createTempDirectory(tempFolder.getRoot().toPath(), "testwrite").toString(), true);
607607

608-
PCollection<String> input = p.apply(Create.of(Arrays.asList(LINES2_ARRAY)).withCoder(coder));
608+
PCollection<String> input =
609+
p.apply(Create.of(Arrays.asList(LINES2.toArray(new String[0]))).withCoder(coder));
609610

610611
final WritableByteChannelFactory writableByteChannelFactory =
611612
new DrunkWritableByteChannelFactory();
@@ -624,8 +625,8 @@ public void testWriteWithWritableByteChannelFactory() throws Exception {
624625

625626
p.run();
626627

627-
final List<String> drunkElems = new ArrayList<>(LINES2_ARRAY.length * 2 + 2);
628-
for (String elem : LINES2_ARRAY) {
628+
final List<String> drunkElems = new ArrayList<>(LINES2.toArray(new String[0]).length * 2 + 2);
629+
for (String elem : LINES2.toArray(new String[0])) {
629630
drunkElems.add(elem);
630631
drunkElems.add(elem);
631632
}
@@ -715,7 +716,7 @@ public void testWriteUnboundedWithCustomBatchParameters() throws Exception {
715716
FileBasedSink.convertToFileResourceIfPossible(baseDir.resolve(outputName).toString());
716717

717718
PCollection<String> input =
718-
p.apply(Create.of(Arrays.asList(LINES2_ARRAY)).withCoder(coder))
719+
p.apply(Create.of(Arrays.asList(LINES2.toArray(new String[0]))).withCoder(coder))
719720
.setIsBoundedInternal(PCollection.IsBounded.UNBOUNDED)
720721
.apply(Window.into(FixedWindows.of(Duration.standardSeconds(10))));
721722

@@ -741,7 +742,7 @@ public void testWriteUnboundedWithCustomBatchParameters() throws Exception {
741742

742743
// Now assert file contents irrespective of exact shard indices.
743744
assertOutputFiles(
744-
LINES2_ARRAY,
745+
LINES2.toArray(new String[0]),
745746
null,
746747
null,
747748
0, // match all files by prefix

sdks/java/core/src/test/java/org/apache/beam/sdk/transforms/CreateTest.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,7 @@
1818
package org.apache.beam.sdk.transforms;
1919

2020
import static org.apache.beam.sdk.TestUtils.LINES;
21-
import static org.apache.beam.sdk.TestUtils.LINES_ARRAY;
22-
import static org.apache.beam.sdk.TestUtils.NO_LINES_ARRAY;
21+
import static org.apache.beam.sdk.TestUtils.NO_LINES;
2322
import static org.hamcrest.MatcherAssert.assertThat;
2423
import static org.hamcrest.Matchers.equalTo;
2524
import static org.hamcrest.Matchers.hasSize;
@@ -96,7 +95,7 @@ public class CreateTest {
9695
public void testCreate() {
9796
PCollection<String> output = p.apply(Create.of(LINES));
9897

99-
PAssert.that(output).containsInAnyOrder(LINES_ARRAY);
98+
PAssert.that(output).containsInAnyOrder(LINES.toArray(new String[0]));
10099
p.run();
101100
}
102101

@@ -105,7 +104,7 @@ public void testCreate() {
105104
public void testCreateEmpty() {
106105
PCollection<String> output = p.apply(Create.empty(StringUtf8Coder.of()));
107106

108-
PAssert.that(output).containsInAnyOrder(NO_LINES_ARRAY);
107+
PAssert.that(output).containsInAnyOrder(NO_LINES.toArray(new String[0]));
109108

110109
assertEquals(StringUtf8Coder.of(), output.getCoder());
111110
p.run();

sdks/java/core/src/test/java/org/apache/beam/sdk/transforms/FlattenTest.java

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,7 @@
1919

2020
import static org.apache.beam.sdk.TestUtils.LINES;
2121
import static org.apache.beam.sdk.TestUtils.LINES2;
22-
import static org.apache.beam.sdk.TestUtils.LINES_ARRAY;
2322
import static org.apache.beam.sdk.TestUtils.NO_LINES;
24-
import static org.apache.beam.sdk.TestUtils.NO_LINES_ARRAY;
2523
import static org.hamcrest.MatcherAssert.assertThat;
2624
import static org.hamcrest.Matchers.equalTo;
2725
import static org.hamcrest.Matchers.not;
@@ -255,7 +253,7 @@ public void testFlattenIterables() {
255253

256254
PCollection<String> output = input.apply(Flatten.iterables());
257255

258-
PAssert.that(output).containsInAnyOrder(LINES_ARRAY);
256+
PAssert.that(output).containsInAnyOrder(LINES.toArray(new String[0]));
259257

260258
p.run();
261259
}
@@ -268,7 +266,7 @@ public void testFlattenIterablesLists() {
268266

269267
PCollection<String> output = input.apply(Flatten.iterables());
270268

271-
PAssert.that(output).containsInAnyOrder(LINES_ARRAY);
269+
PAssert.that(output).containsInAnyOrder(LINES.toArray(new String[0]));
272270

273271
p.run();
274272
}
@@ -283,7 +281,7 @@ public void testFlattenIterablesSets() {
283281

284282
PCollection<String> output = input.apply(Flatten.iterables());
285283

286-
PAssert.that(output).containsInAnyOrder(LINES_ARRAY);
284+
PAssert.that(output).containsInAnyOrder(LINES.toArray(new String[0]));
287285

288286
p.run();
289287
}
@@ -300,7 +298,7 @@ public void testFlattenIterablesCollections() {
300298

301299
PCollection<String> output = input.apply(Flatten.iterables());
302300

303-
PAssert.that(output).containsInAnyOrder(LINES_ARRAY);
301+
PAssert.that(output).containsInAnyOrder(LINES.toArray(new String[0]));
304302

305303
p.run();
306304
}
@@ -315,7 +313,7 @@ public void testFlattenIterablesEmpty() {
315313

316314
PCollection<String> output = input.apply(Flatten.iterables());
317315

318-
PAssert.that(output).containsInAnyOrder(NO_LINES_ARRAY);
316+
PAssert.that(output).containsInAnyOrder(NO_LINES.toArray(new String[0]));
319317

320318
p.run();
321319
}

sdks/java/io/contextualtextio/src/test/java/org/apache/beam/sdk/io/contextualtextio/ContextualTextIOTest.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@
2222
import static junit.framework.Assert.assertFalse;
2323
import static junit.framework.Assert.assertNotNull;
2424
import static junit.framework.Assert.assertTrue;
25-
import static org.apache.beam.sdk.TestUtils.LINES_ARRAY;
26-
import static org.apache.beam.sdk.TestUtils.NO_LINES_ARRAY;
25+
import static org.apache.beam.sdk.TestUtils.LINES;
26+
import static org.apache.beam.sdk.TestUtils.NO_LINES;
2727
import static org.apache.beam.sdk.io.Compression.AUTO;
2828
import static org.apache.beam.sdk.io.Compression.BZIP2;
2929
import static org.apache.beam.sdk.io.Compression.DEFLATE;
@@ -951,25 +951,25 @@ public void testReadStringsWithCustomDelimiterAndContext() throws Exception {
951951
@Test
952952
@Category(NeedsRunner.class)
953953
public void testReadStrings() throws Exception {
954-
runTestRead(LINES_ARRAY);
954+
runTestRead(LINES.toArray(new String[0]));
955955
}
956956

957957
@Test
958958
@Category(NeedsRunner.class)
959959
public void testReadStringsWithContext() throws Exception {
960-
runTestReadLineNumsAndFileName(LINES_ARRAY);
960+
runTestReadLineNumsAndFileName(LINES.toArray(new String[0]));
961961
}
962962

963963
@Test
964964
@Category(NeedsRunner.class)
965965
public void testReadEmptyStrings() throws Exception {
966-
runTestRead(NO_LINES_ARRAY);
966+
runTestRead(NO_LINES.toArray(new String[0]));
967967
}
968968

969969
@Test
970970
@Category(NeedsRunner.class)
971971
public void testReadEmptyStringsWithContext() throws Exception {
972-
runTestReadLineNumsAndFileName(NO_LINES_ARRAY);
972+
runTestReadLineNumsAndFileName(NO_LINES.toArray(new String[0]));
973973
}
974974

975975
@Test

0 commit comments

Comments
 (0)