Skip to content

Commit 5ae1b3a

Browse files
committed
[SPARK-53821] Ban org.apache.commons.lang3 package
### What changes were proposed in this pull request? This PR aims to ban `org.apache.commons.lang3` package. ### Why are the changes needed? To be independent from 3rd party library as much as possible. Currently, we only use 3 places in test code. ``` $ git grep org.apache.commons.lang3 | grep -v checkstyle spark-operator/src/test/java/org/apache/spark/k8s/operator/utils/TestUtils.java:import org.apache.commons.lang3.reflect.FieldUtils; spark-submission-worker/src/test/java/org/apache/spark/k8s/operator/SparkAppDriverConfTest.java:import org.apache.commons.lang3.RandomStringUtils; spark-submission-worker/src/test/java/org/apache/spark/k8s/operator/SparkAppSubmissionWorkerTest.java:import org.apache.commons.lang3.RandomStringUtils; ``` ### Does this PR introduce _any_ user-facing change? No behavior change. ### How was this patch tested? Pass the CIs. ### Was this patch authored or co-authored using generative AI tooling? No. Closes #371 from dongjoon-hyun/SPARK-53821. Authored-by: Dongjoon Hyun <[email protected]> Signed-off-by: Dongjoon Hyun <[email protected]>
1 parent 034cefc commit 5ae1b3a

File tree

4 files changed

+12
-8
lines changed

4 files changed

+12
-8
lines changed

config/checkstyle/checkstyle.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@
204204
<property name="illegalPkgs" value="org.apache.log4j"/>
205205
<property name="illegalPkgs" value="org.apache.commons.lang"/>
206206
<property name="illegalPkgs" value="org.apache.commons.collections"/>
207-
<property name="illegalPkgs" value="org.apache.commons.lang3.tuple" />
207+
<property name="illegalPkgs" value="org.apache.commons.lang3" />
208208
</module>
209209
</module>
210210
</module>

spark-operator/src/test/java/org/apache/spark/k8s/operator/utils/TestUtils.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,10 @@
2323
import static org.apache.spark.k8s.operator.Constants.API_VERSION;
2424

2525
import java.io.File;
26+
import java.lang.reflect.Field;
2627
import java.util.Map;
2728

2829
import io.fabric8.kubernetes.api.model.ObjectMeta;
29-
import org.apache.commons.lang3.reflect.FieldUtils;
3030

3131
import org.apache.spark.k8s.operator.Constants;
3232
import org.apache.spark.k8s.operator.SparkApplication;
@@ -66,9 +66,15 @@ public static long calculateElapsedTimeInMills(long startTime) {
6666
return System.currentTimeMillis() - startTime;
6767
}
6868

69+
@SuppressWarnings("PMD.AvoidAccessibilityAlteration")
6970
public static <T> void setConfigKey(ConfigOption<T> configKey, T newValue) {
7071
try {
71-
FieldUtils.writeField(configKey, "defaultValue", newValue, true);
72+
Class<?> targetClass = configKey.getClass();
73+
Field field = targetClass.getDeclaredField("defaultValue");
74+
field.setAccessible(true);
75+
field.set(configKey, newValue);
76+
} catch (NoSuchFieldException e) {
77+
throw new IllegalStateException(e);
7278
} catch (IllegalAccessException e) {
7379
throw new UnsupportedOperationException(e);
7480
}

spark-submission-worker/src/test/java/org/apache/spark/k8s/operator/SparkAppDriverConfTest.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727

2828
import scala.Option;
2929

30-
import org.apache.commons.lang3.RandomStringUtils;
3130
import org.junit.jupiter.api.Test;
3231

3332
import org.apache.spark.SparkConf;
@@ -63,7 +62,7 @@ void testConfigMapNameDriver() {
6362
SparkConf sparkConf = new SparkConf();
6463
sparkConf.set("foo", "bar");
6564
sparkConf.set("spark.executor.instances", "1");
66-
String appId = RandomStringUtils.randomAlphabetic(1000);
65+
String appId = "a".repeat(1000);
6766
SparkAppDriverConf sparkAppDriverConf =
6867
SparkAppDriverConf.create(
6968
sparkConf, appId, mock(JavaMainAppResource.class), "foo", null, Option.empty());

spark-submission-worker/src/test/java/org/apache/spark/k8s/operator/SparkAppSubmissionWorkerTest.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@
3636

3737
import io.fabric8.kubernetes.api.model.ObjectMeta;
3838
import io.fabric8.kubernetes.api.model.ObjectMetaBuilder;
39-
import org.apache.commons.lang3.RandomStringUtils;
4039
import org.junit.jupiter.api.Test;
4140
import org.mockito.MockedConstruction;
4241

@@ -209,8 +208,8 @@ void sparkAppIdShouldBeDeterministicPerAppPerAttempt() {
209208

210209
@Test
211210
void generatedSparkAppIdShouldComplyLengthLimit() {
212-
String namespaceName = RandomStringUtils.randomAlphabetic(253);
213-
String appName = RandomStringUtils.randomAlphabetic(253);
211+
String namespaceName = "n".repeat(253);
212+
String appName = "a".repeat(253);
214213

215214
SparkApplication mockApp = mock(SparkApplication.class);
216215
ObjectMeta appMeta =

0 commit comments

Comments
 (0)