diff --git a/common/network-shuffle/src/main/java/org/apache/spark/network/shuffle/RemoteBlockPushResolver.java b/common/network-shuffle/src/main/java/org/apache/spark/network/shuffle/RemoteBlockPushResolver.java index 4a02a0f326368..ceafb6f755641 100644 --- a/common/network-shuffle/src/main/java/org/apache/spark/network/shuffle/RemoteBlockPushResolver.java +++ b/common/network-shuffle/src/main/java/org/apache/spark/network/shuffle/RemoteBlockPushResolver.java @@ -214,7 +214,7 @@ protected AppShuffleInfo validateAndGetAppShuffleInfo(String appId) { // TODO: [SPARK-33236] Change the message when this service is able to handle NM restart AppShuffleInfo appShuffleInfo = appsShuffleInfo.get(appId); JavaUtils.checkArgument(appShuffleInfo != null, - "application " + appId + " is not registered or NM was restarted."); + "application %s is not registered or NM was restarted.", appId); return appShuffleInfo; } diff --git a/common/utils-java/src/main/java/org/apache/spark/network/util/JavaUtils.java b/common/utils-java/src/main/java/org/apache/spark/network/util/JavaUtils.java index 2cf4570488ee0..48c765365a574 100644 --- a/common/utils-java/src/main/java/org/apache/spark/network/util/JavaUtils.java +++ b/common/utils-java/src/main/java/org/apache/spark/network/util/JavaUtils.java @@ -751,8 +751,40 @@ public static boolean isTesting() { .anyMatch(prefix -> osName.regionMatches(true, 0, prefix, 0, prefix.length())); /** - * Throws IllegalArgumentException with the given message if the check is false. - * Keep this clone of CommandBuilderUtils.checkArgument synced with the original. + * Throws an {@link IllegalArgumentException} with a formatted message if {@code check} is + * {@code false}. + * + *
The failure message is produced with {@link String#format(String, Object...)}: {@code msg} + * is the format string and every runtime value must be supplied through {@code args} using a + * conversion such as {@code %s}. Do not concatenate values into {@code msg}. Passing an + * already-interpolated message, for example + *
{@code checkArgument(cond, "bad key: " + key)}
+ * is a mistake for two reasons:
+ * Keep this clone of {@code CommandBuilderUtils.checkArgument} synced with the original. + * + * @param check the condition that must hold; an exception is thrown when it is {@code false} + * @param msg a {@link String#format(String, Object...)} format string for the failure message; + * do not interpolate runtime values into it, pass them through {@code args} + * @param args the arguments referenced by the format specifiers in {@code msg} + * @throws IllegalArgumentException if {@code check} is {@code false} */ public static void checkArgument(boolean check, String msg, Object... args) { if (!check) { @@ -761,8 +793,20 @@ public static void checkArgument(boolean check, String msg, Object... args) { } /** - * Throws IllegalStateException with the given message if the check is false. - * Keep this clone of CommandBuilderUtils.checkState synced with the original. + * Throws an {@link IllegalStateException} with a formatted message if {@code check} is + * {@code false}. + * + *
{@code msg} is a {@link String#format(String, Object...)} format string; the same + * format-argument contract and caveats described on {@link #checkArgument(boolean, String, + * Object...)} apply here. + * + *
Keep this clone of {@code CommandBuilderUtils.checkState} synced with the original. + * + * @param check the condition that must hold; an exception is thrown when it is {@code false} + * @param msg a {@link String#format(String, Object...)} format string for the failure message; + * do not interpolate runtime values into it, pass them through {@code args} + * @param args the arguments referenced by the format specifiers in {@code msg} + * @throws IllegalStateException if {@code check} is {@code false} */ public static void checkState(boolean check, String msg, Object... args) { if (!check) {