This is an automated email from the ASF dual-hosted git repository.
yhu pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/beam.git
The following commit(s) were added to refs/heads/master by this push:
new 7ba0efd4d24 [ErrorProne] Enable `MutablePublicArray` Error Prone Check
(#37761)
7ba0efd4d24 is described below
commit 7ba0efd4d24316a11a63d77e6040dafc35d67862
Author: Radosław Stankiewicz <[email protected]>
AuthorDate: Wed Mar 4 15:59:08 2026 +0100
[ErrorProne] Enable `MutablePublicArray` Error Prone Check (#37761)
---
.../org/apache/beam/gradle/BeamModulePlugin.groovy | 1 -
.../test/java/org/apache/beam/sdk/TestUtils.java | 10 +++----
.../org/apache/beam/sdk/io/TextIOReadTest.java | 8 +++---
.../org/apache/beam/sdk/io/TextIOWriteTest.java | 33 +++++++++++-----------
.../org/apache/beam/sdk/transforms/CreateTest.java | 7 ++---
.../apache/beam/sdk/transforms/FlattenTest.java | 12 ++++----
.../io/contextualtextio/ContextualTextIOTest.java | 12 ++++----
7 files changed, 40 insertions(+), 43 deletions(-)
diff --git
a/buildSrc/src/main/groovy/org/apache/beam/gradle/BeamModulePlugin.groovy
b/buildSrc/src/main/groovy/org/apache/beam/gradle/BeamModulePlugin.groovy
index d9f3de5ea76..a83fc22934f 100644
--- a/buildSrc/src/main/groovy/org/apache/beam/gradle/BeamModulePlugin.groovy
+++ b/buildSrc/src/main/groovy/org/apache/beam/gradle/BeamModulePlugin.groovy
@@ -1559,7 +1559,6 @@ class BeamModulePlugin implements Plugin<Project> {
"MissingSummary",
"MixedMutabilityReturnType",
"PreferJavaTimeOverload",
- "MutablePublicArray",
"NonCanonicalType",
"ProtectedMembersInFinalClass",
"Slf4jFormatShouldBeConst",
diff --git a/sdks/java/core/src/test/java/org/apache/beam/sdk/TestUtils.java
b/sdks/java/core/src/test/java/org/apache/beam/sdk/TestUtils.java
index d37b50e1ff8..b79fe0f4403 100644
--- a/sdks/java/core/src/test/java/org/apache/beam/sdk/TestUtils.java
+++ b/sdks/java/core/src/test/java/org/apache/beam/sdk/TestUtils.java
@@ -29,11 +29,11 @@ public class TestUtils {
// Do not instantiate.
private TestUtils() {}
- public static final String[] NO_LINES_ARRAY = new String[] {};
+ private static final String[] NO_LINES_ARRAY = new String[] {};
public static final List<String> NO_LINES = Arrays.asList(NO_LINES_ARRAY);
- public static final String[] LINES_ARRAY =
+ private static final String[] LINES_ARRAY =
new String[] {
"To be, or not to be: that is the question: ",
"Whether 'tis nobler in the mind to suffer ",
@@ -74,15 +74,15 @@ public class TestUtils {
public static final List<String> LINES = Arrays.asList(LINES_ARRAY);
- public static final String[] LINES2_ARRAY = new String[] {"hi", "there",
"bob!"};
+ private static final String[] LINES2_ARRAY = new String[] {"hi", "there",
"bob!"};
public static final List<String> LINES2 = Arrays.asList(LINES2_ARRAY);
- public static final Integer[] NO_INTS_ARRAY = new Integer[] {};
+ private static final Integer[] NO_INTS_ARRAY = new Integer[] {};
public static final List<Integer> NO_INTS = Arrays.asList(NO_INTS_ARRAY);
- public static final Integer[] INTS_ARRAY =
+ private static final Integer[] INTS_ARRAY =
new Integer[] {3, 42, Integer.MAX_VALUE, 0, -1, Integer.MIN_VALUE, 666};
public static final List<Integer> INTS = Arrays.asList(INTS_ARRAY);
diff --git
a/sdks/java/core/src/test/java/org/apache/beam/sdk/io/TextIOReadTest.java
b/sdks/java/core/src/test/java/org/apache/beam/sdk/io/TextIOReadTest.java
index 39d039f5bb9..c475d6d203b 100644
--- a/sdks/java/core/src/test/java/org/apache/beam/sdk/io/TextIOReadTest.java
+++ b/sdks/java/core/src/test/java/org/apache/beam/sdk/io/TextIOReadTest.java
@@ -18,8 +18,8 @@
package org.apache.beam.sdk.io;
import static java.nio.charset.StandardCharsets.UTF_8;
-import static org.apache.beam.sdk.TestUtils.LINES_ARRAY;
-import static org.apache.beam.sdk.TestUtils.NO_LINES_ARRAY;
+import static org.apache.beam.sdk.TestUtils.LINES;
+import static org.apache.beam.sdk.TestUtils.NO_LINES;
import static org.apache.beam.sdk.io.Compression.AUTO;
import static org.apache.beam.sdk.io.Compression.BZIP2;
import static org.apache.beam.sdk.io.Compression.DEFLATE;
@@ -767,13 +767,13 @@ public class TextIOReadTest {
@Test
@Category(NeedsRunner.class)
public void testReadStrings() throws Exception {
- runTestRead(LINES_ARRAY);
+ runTestRead(LINES.toArray(new String[0]));
}
@Test
@Category(NeedsRunner.class)
public void testReadEmptyStrings() throws Exception {
- runTestRead(NO_LINES_ARRAY);
+ runTestRead(NO_LINES.toArray(new String[0]));
}
@Test
diff --git
a/sdks/java/core/src/test/java/org/apache/beam/sdk/io/TextIOWriteTest.java
b/sdks/java/core/src/test/java/org/apache/beam/sdk/io/TextIOWriteTest.java
index bb60c7aef1d..2f965c8e5b9 100644
--- a/sdks/java/core/src/test/java/org/apache/beam/sdk/io/TextIOWriteTest.java
+++ b/sdks/java/core/src/test/java/org/apache/beam/sdk/io/TextIOWriteTest.java
@@ -17,9 +17,9 @@
*/
package org.apache.beam.sdk.io;
-import static org.apache.beam.sdk.TestUtils.LINES2_ARRAY;
-import static org.apache.beam.sdk.TestUtils.LINES_ARRAY;
-import static org.apache.beam.sdk.TestUtils.NO_LINES_ARRAY;
+import static org.apache.beam.sdk.TestUtils.LINES;
+import static org.apache.beam.sdk.TestUtils.LINES2;
+import static org.apache.beam.sdk.TestUtils.NO_LINES;
import static org.apache.beam.sdk.io.fs.MatchResult.Status.NOT_FOUND;
import static
org.apache.beam.sdk.transforms.display.DisplayDataMatchers.hasDisplayItem;
import static
org.apache.beam.vendor.guava.v32_1_2_jre.com.google.common.base.MoreObjects.firstNonNull;
@@ -551,49 +551,49 @@ public class TextIOWriteTest {
@Test
@Category(NeedsRunner.class)
public void testWriteStrings() throws Exception {
- runTestWrite(LINES_ARRAY);
+ runTestWrite(LINES.toArray(new String[0]));
}
@Test
@Category(NeedsRunner.class)
public void testWriteEmptyStringsNoSharding() throws Exception {
- runTestWrite(NO_LINES_ARRAY, 0);
+ runTestWrite(NO_LINES.toArray(new String[0]), 0);
}
@Test
@Category(NeedsRunner.class)
public void testWriteEmptyStrings() throws Exception {
- runTestWrite(NO_LINES_ARRAY);
+ runTestWrite(NO_LINES.toArray(new String[0]));
}
@Test
@Category(NeedsRunner.class)
public void testWriteEmptyStringsSkipIfEmpty() throws Exception {
- runTestWrite(NO_LINES_ARRAY, null, null, 0, true);
+ runTestWrite(NO_LINES.toArray(new String[0]), null, null, 0, true);
}
@Test
@Category(NeedsRunner.class)
public void testShardedWrite() throws Exception {
- runTestWrite(LINES_ARRAY, 5);
+ runTestWrite(LINES.toArray(new String[0]), 5);
}
@Test
@Category(NeedsRunner.class)
public void testWriteWithHeader() throws Exception {
- runTestWrite(LINES_ARRAY, MY_HEADER, null);
+ runTestWrite(LINES.toArray(new String[0]), MY_HEADER, null);
}
@Test
@Category(NeedsRunner.class)
public void testWriteWithFooter() throws Exception {
- runTestWrite(LINES_ARRAY, null, MY_FOOTER);
+ runTestWrite(LINES.toArray(new String[0]), null, MY_FOOTER);
}
@Test
@Category(NeedsRunner.class)
public void testWriteWithHeaderAndFooter() throws Exception {
- runTestWrite(LINES_ARRAY, MY_HEADER, MY_FOOTER);
+ runTestWrite(LINES.toArray(new String[0]), MY_HEADER, MY_FOOTER);
}
@Test
@@ -605,7 +605,8 @@ public class TextIOWriteTest {
FileSystems.matchNewResource(
Files.createTempDirectory(tempFolder.getRoot().toPath(),
"testwrite").toString(), true);
- PCollection<String> input =
p.apply(Create.of(Arrays.asList(LINES2_ARRAY)).withCoder(coder));
+ PCollection<String> input =
+ p.apply(Create.of(Arrays.asList(LINES2.toArray(new
String[0]))).withCoder(coder));
final WritableByteChannelFactory writableByteChannelFactory =
new DrunkWritableByteChannelFactory();
@@ -624,8 +625,8 @@ public class TextIOWriteTest {
p.run();
- final List<String> drunkElems = new ArrayList<>(LINES2_ARRAY.length * 2 +
2);
- for (String elem : LINES2_ARRAY) {
+ final List<String> drunkElems = new ArrayList<>(LINES2.toArray(new
String[0]).length * 2 + 2);
+ for (String elem : LINES2.toArray(new String[0])) {
drunkElems.add(elem);
drunkElems.add(elem);
}
@@ -715,7 +716,7 @@ public class TextIOWriteTest {
FileBasedSink.convertToFileResourceIfPossible(baseDir.resolve(outputName).toString());
PCollection<String> input =
- p.apply(Create.of(Arrays.asList(LINES2_ARRAY)).withCoder(coder))
+ p.apply(Create.of(Arrays.asList(LINES2.toArray(new
String[0]))).withCoder(coder))
.setIsBoundedInternal(PCollection.IsBounded.UNBOUNDED)
.apply(Window.into(FixedWindows.of(Duration.standardSeconds(10))));
@@ -741,7 +742,7 @@ public class TextIOWriteTest {
// Now assert file contents irrespective of exact shard indices.
assertOutputFiles(
- LINES2_ARRAY,
+ LINES2.toArray(new String[0]),
null,
null,
0, // match all files by prefix
diff --git
a/sdks/java/core/src/test/java/org/apache/beam/sdk/transforms/CreateTest.java
b/sdks/java/core/src/test/java/org/apache/beam/sdk/transforms/CreateTest.java
index 03f4f1c67c6..e79913c7cf5 100644
---
a/sdks/java/core/src/test/java/org/apache/beam/sdk/transforms/CreateTest.java
+++
b/sdks/java/core/src/test/java/org/apache/beam/sdk/transforms/CreateTest.java
@@ -18,8 +18,7 @@
package org.apache.beam.sdk.transforms;
import static org.apache.beam.sdk.TestUtils.LINES;
-import static org.apache.beam.sdk.TestUtils.LINES_ARRAY;
-import static org.apache.beam.sdk.TestUtils.NO_LINES_ARRAY;
+import static org.apache.beam.sdk.TestUtils.NO_LINES;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.hasSize;
@@ -96,7 +95,7 @@ public class CreateTest {
public void testCreate() {
PCollection<String> output = p.apply(Create.of(LINES));
- PAssert.that(output).containsInAnyOrder(LINES_ARRAY);
+ PAssert.that(output).containsInAnyOrder(LINES.toArray(new String[0]));
p.run();
}
@@ -105,7 +104,7 @@ public class CreateTest {
public void testCreateEmpty() {
PCollection<String> output = p.apply(Create.empty(StringUtf8Coder.of()));
- PAssert.that(output).containsInAnyOrder(NO_LINES_ARRAY);
+ PAssert.that(output).containsInAnyOrder(NO_LINES.toArray(new String[0]));
assertEquals(StringUtf8Coder.of(), output.getCoder());
p.run();
diff --git
a/sdks/java/core/src/test/java/org/apache/beam/sdk/transforms/FlattenTest.java
b/sdks/java/core/src/test/java/org/apache/beam/sdk/transforms/FlattenTest.java
index 7a02d95a504..74fb2dc99c8 100644
---
a/sdks/java/core/src/test/java/org/apache/beam/sdk/transforms/FlattenTest.java
+++
b/sdks/java/core/src/test/java/org/apache/beam/sdk/transforms/FlattenTest.java
@@ -19,9 +19,7 @@ package org.apache.beam.sdk.transforms;
import static org.apache.beam.sdk.TestUtils.LINES;
import static org.apache.beam.sdk.TestUtils.LINES2;
-import static org.apache.beam.sdk.TestUtils.LINES_ARRAY;
import static org.apache.beam.sdk.TestUtils.NO_LINES;
-import static org.apache.beam.sdk.TestUtils.NO_LINES_ARRAY;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.not;
@@ -255,7 +253,7 @@ public class FlattenTest implements Serializable {
PCollection<String> output = input.apply(Flatten.iterables());
- PAssert.that(output).containsInAnyOrder(LINES_ARRAY);
+ PAssert.that(output).containsInAnyOrder(LINES.toArray(new String[0]));
p.run();
}
@@ -268,7 +266,7 @@ public class FlattenTest implements Serializable {
PCollection<String> output = input.apply(Flatten.iterables());
- PAssert.that(output).containsInAnyOrder(LINES_ARRAY);
+ PAssert.that(output).containsInAnyOrder(LINES.toArray(new String[0]));
p.run();
}
@@ -283,7 +281,7 @@ public class FlattenTest implements Serializable {
PCollection<String> output = input.apply(Flatten.iterables());
- PAssert.that(output).containsInAnyOrder(LINES_ARRAY);
+ PAssert.that(output).containsInAnyOrder(LINES.toArray(new String[0]));
p.run();
}
@@ -300,7 +298,7 @@ public class FlattenTest implements Serializable {
PCollection<String> output = input.apply(Flatten.iterables());
- PAssert.that(output).containsInAnyOrder(LINES_ARRAY);
+ PAssert.that(output).containsInAnyOrder(LINES.toArray(new String[0]));
p.run();
}
@@ -315,7 +313,7 @@ public class FlattenTest implements Serializable {
PCollection<String> output = input.apply(Flatten.iterables());
- PAssert.that(output).containsInAnyOrder(NO_LINES_ARRAY);
+ PAssert.that(output).containsInAnyOrder(NO_LINES.toArray(new String[0]));
p.run();
}
diff --git
a/sdks/java/io/contextualtextio/src/test/java/org/apache/beam/sdk/io/contextualtextio/ContextualTextIOTest.java
b/sdks/java/io/contextualtextio/src/test/java/org/apache/beam/sdk/io/contextualtextio/ContextualTextIOTest.java
index 2cc89a2a0dc..68a1dd3395c 100644
---
a/sdks/java/io/contextualtextio/src/test/java/org/apache/beam/sdk/io/contextualtextio/ContextualTextIOTest.java
+++
b/sdks/java/io/contextualtextio/src/test/java/org/apache/beam/sdk/io/contextualtextio/ContextualTextIOTest.java
@@ -22,8 +22,8 @@ import static junit.framework.Assert.assertEquals;
import static junit.framework.Assert.assertFalse;
import static junit.framework.Assert.assertNotNull;
import static junit.framework.Assert.assertTrue;
-import static org.apache.beam.sdk.TestUtils.LINES_ARRAY;
-import static org.apache.beam.sdk.TestUtils.NO_LINES_ARRAY;
+import static org.apache.beam.sdk.TestUtils.LINES;
+import static org.apache.beam.sdk.TestUtils.NO_LINES;
import static org.apache.beam.sdk.io.Compression.AUTO;
import static org.apache.beam.sdk.io.Compression.BZIP2;
import static org.apache.beam.sdk.io.Compression.DEFLATE;
@@ -951,25 +951,25 @@ public class ContextualTextIOTest {
@Test
@Category(NeedsRunner.class)
public void testReadStrings() throws Exception {
- runTestRead(LINES_ARRAY);
+ runTestRead(LINES.toArray(new String[0]));
}
@Test
@Category(NeedsRunner.class)
public void testReadStringsWithContext() throws Exception {
- runTestReadLineNumsAndFileName(LINES_ARRAY);
+ runTestReadLineNumsAndFileName(LINES.toArray(new String[0]));
}
@Test
@Category(NeedsRunner.class)
public void testReadEmptyStrings() throws Exception {
- runTestRead(NO_LINES_ARRAY);
+ runTestRead(NO_LINES.toArray(new String[0]));
}
@Test
@Category(NeedsRunner.class)
public void testReadEmptyStringsWithContext() throws Exception {
- runTestReadLineNumsAndFileName(NO_LINES_ARRAY);
+ runTestReadLineNumsAndFileName(NO_LINES.toArray(new String[0]));
}
@Test