From 03e680ffaa0a4b3af2c1ba8b3b81546401121eb5 Mon Sep 17 00:00:00 2001 From: Anas Khan <83116240+anxkhn@users.noreply.github.com> Date: Sat, 4 Jul 2026 23:14:45 +0530 Subject: [PATCH] Core: Fix OAuthTokenResponse.addScope error to show the invalid scope Builder.addScope validated the scope with Preconditions.checkArgument(..., "Invalid scope: %s") but did not pass the scope argument for the %s placeholder. Guava leaves the unmatched %s in place, so an invalid scope raised IllegalArgumentException with the literal message "Invalid scope: %s", hiding the value that was actually rejected. Pass the scope as the format argument so the message reports the offending value, and add a regression test asserting the message contains the scope rather than the literal placeholder. Generated-by: opencode Signed-off-by: Anas Khan <83116240+anxkhn@users.noreply.github.com> --- .../apache/iceberg/rest/responses/OAuthTokenResponse.java | 2 +- .../iceberg/rest/responses/TestOAuthTokenResponse.java | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/core/src/main/java/org/apache/iceberg/rest/responses/OAuthTokenResponse.java b/core/src/main/java/org/apache/iceberg/rest/responses/OAuthTokenResponse.java index 56c35f3cc6c6..270fe50e824e 100644 --- a/core/src/main/java/org/apache/iceberg/rest/responses/OAuthTokenResponse.java +++ b/core/src/main/java/org/apache/iceberg/rest/responses/OAuthTokenResponse.java @@ -108,7 +108,7 @@ public Builder setExpirationInSeconds(int durationInSeconds) { } public Builder addScope(String scope) { - Preconditions.checkArgument(OAuth2Util.isValidScopeToken(scope), "Invalid scope: %s"); + Preconditions.checkArgument(OAuth2Util.isValidScopeToken(scope), "Invalid scope: %s", scope); this.scopes.add(scope); return this; } diff --git a/core/src/test/java/org/apache/iceberg/rest/responses/TestOAuthTokenResponse.java b/core/src/test/java/org/apache/iceberg/rest/responses/TestOAuthTokenResponse.java index aec052de9aa6..8961991cd345 100644 --- a/core/src/test/java/org/apache/iceberg/rest/responses/TestOAuthTokenResponse.java +++ b/core/src/test/java/org/apache/iceberg/rest/responses/TestOAuthTokenResponse.java @@ -130,4 +130,11 @@ public void testFailures() { .isInstanceOf(IllegalArgumentException.class) .hasMessageContaining("Cannot parse to a string value: token_type: 34"); } + + @Test + void invalidScopeReportsScopeValue() { + assertThatThrownBy(() -> OAuthTokenResponse.builder().addScope("bad scope")) + .isInstanceOf(IllegalArgumentException.class) + .hasMessage("Invalid scope: bad scope"); + } }