[MINOR][CORE] Add verbatim-message overloads for JavaUtils.checkArgument and checkState - #58743
Open
david-mollitor-db wants to merge 1 commit into
Open
Conversation
…ent and checkState `JavaUtils.checkArgument`/`checkState` build the failure message with `String.format(msg, args)`, so `msg` is a format string. When a caller has no values to interpolate and passes a plain or already-concatenated message, that message is still treated as a format template: a stray `%` in it (a percent-encoded token, a Windows path like `%TEMP%`, a `LIKE` pattern, a number such as "50%") makes `String.format` throw an `IllegalFormatException` that replaces the intended `IllegalArgumentException`/`IllegalStateException` and hides the real reason the check failed. Add `checkArgument(boolean, String)` and `checkState(boolean, String)` overloads that throw the message verbatim, without going through `String.format`. Existing two-argument call sites bind to these overloads automatically on recompile (a two-argument call is never ambiguous with the varargs form), so plain-message checks become format-safe and skip the empty varargs array. Callers that do have values to interpolate keep using the varargs overload and should pass the values as arguments (`"bad key: %s", key`) rather than concatenating them. The existing varargs methods are unchanged, so the "keep synced with CommandBuilderUtils" clones are untouched. Co-authored-by: Isaac <no-reply@databricks.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What changes were proposed in this pull request?
Add two overloads to
JavaUtilsthat throw the failure message verbatim:Unlike the existing
checkArgument/checkState(boolean, String, Object...)methods, these donot route the message through
String.format. The existing varargs methods (and their"keep synced with
CommandBuilderUtils" bodies) are left unchanged.Why are the changes needed?
checkArgument/checkStatebuild the message withString.format(msg, args), somsgis aformat string. When a caller has no values to interpolate and passes a plain or
already-concatenated message, that message is still treated as a format template: a stray
%init (a percent-encoded token, a Windows path such as
%TEMP%, a SQLLIKEpattern, a number like"50%") makesString.formatthrow anIllegalFormatExceptionthat replaces the intendedIllegalArgumentException/IllegalStateExceptionand hides the real reason the check failed.The new overloads make the no-argument case format-safe: the message is used exactly as given, and
no empty varargs array is allocated. Existing two-argument call sites bind to these overloads
automatically on recompile — a two-argument call is never ambiguous with the varargs form — so they
gain this safety with no source changes. Callers that do have values to interpolate keep using the
varargs overload and should pass the values as arguments (
"bad key: %s", key) rather thanconcatenating them.
Does this PR introduce any user-facing change?
No. For the plain messages used by existing callers (none of which contain a
%), the exceptiontype and message are unchanged; the overloads only change behavior for a message that contains a
%and no arguments, which previously threw a formatting error.How was this patch tested?
Added
testCheckArgumentUsesMessageVerbatim/testCheckStateUsesMessageVerbatimtoJavaUtilsSuite, asserting that a message containing%(which would otherwise makeString.formatthrow) is preserved verbatim in the thrown exception.JavaUtilsSuitepasses (4tests).
common-utils-java,network-common,network-shuffle, andkvstorecompile cleanly(confirming existing two-argument callers rebind without ambiguity), and checkstyle is clean.
Was this patch authored or co-authored using generative AI tooling?
Generated-by: Claude Opus 4.8
This pull request and its description were written by Isaac.