Skip to content

Commit df3d8e4

Browse files
committed
[SPARK-53256][CORE] Promote check(Argument|State) to JavaUtils
### What changes were proposed in this pull request? This PR aims to promote the following `checkArgument`, and `checkState` methods to `JavaUtils` by copying. https://github.com/apache/spark/blob/1ae3d681983be9b7b46ec33282020e7d35b11903/launcher/src/main/java/org/apache/spark/launcher/CommandBuilderUtils.java#L220-L232 ### Why are the changes needed? - To reuse these Apache Spark utility methods widely in the whole Spark project. - Note that we need to clone because `launcher` module cannot have the other dependency and the existing methods are not `public`. I added the following style note to ensure them in sync in the future. > Keep this clone of CommandBuilderUtils.... synced with the original. ### Does this PR introduce _any_ user-facing change? No. ### How was this patch tested? Manual review. ### Was this patch authored or co-authored using generative AI tooling? No. Closes #51986 from dongjoon-hyun/SPARK-53256. Authored-by: Dongjoon Hyun <dongjoon@apache.org> Signed-off-by: Dongjoon Hyun <dongjoon@apache.org>
1 parent b248ba5 commit df3d8e4

1 file changed

Lines changed: 20 additions & 0 deletions

File tree

  • common/utils-java/src/main/java/org/apache/spark/network/util

common/utils-java/src/main/java/org/apache/spark/network/util/JavaUtils.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -737,4 +737,24 @@ public static boolean isTesting() {
737737
public static boolean isUnix = Stream.of("AIX", "HP-UX", "Irix", "Linux", "Mac OS X", "Solaris",
738738
"SunOS", "FreeBSD", "OpenBSD", "NetBSD")
739739
.anyMatch(prefix -> osName.regionMatches(true, 0, prefix, 0, prefix.length()));
740+
741+
/**
742+
* Throws IllegalArgumentException with the given message if the check is false.
743+
* Keep this clone of CommandBuilderUtils.checkArgument synced with the original.
744+
*/
745+
public static void checkArgument(boolean check, String msg, Object... args) {
746+
if (!check) {
747+
throw new IllegalArgumentException(String.format(msg, args));
748+
}
749+
}
750+
751+
/**
752+
* Throws IllegalStateException with the given message if the check is false.
753+
* Keep this clone of CommandBuilderUtils.checkState synced with the original.
754+
*/
755+
public static void checkState(boolean check, String msg, Object... args) {
756+
if (!check) {
757+
throw new IllegalStateException(String.format(msg, args));
758+
}
759+
}
740760
}

0 commit comments

Comments
 (0)