You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@polaris.apache.org by di...@apache.org on 2026/09/15 22:30:05 UTC
(polaris) branch main updated: Deduplicate leading-slash trimming into StorageLocation.trimLeadingSlash (#5524)
This is an automated email from the ASF dual-hosted git repository.
dimas-b pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/polaris.git
The following commit(s) were added to refs/heads/main by this push:
new e4a4513840 Deduplicate leading-slash trimming into StorageLocation.trimLeadingSlash (#5524)
e4a4513840 is described below
commit e4a45138409facf684dd296d4b671f63e92bec0c
Author: Prithvi S <pr...@gmail.com>
AuthorDate: Wed Sep 16 04:00:00 2026 +0530
Deduplicate leading-slash trimming into StorageLocation.trimLeadingSlash (#5524)
---
.../org/apache/polaris/core/storage/StorageLocation.java | 12 ++++++++++++
.../core/storage/aws/AwsCredentialsStorageIntegration.java | 8 +-------
.../apache/polaris/core/storage/azure/AzureLocation.java | 2 +-
.../core/storage/gcp/GcpCredentialsStorageIntegration.java | 13 +------------
4 files changed, 15 insertions(+), 20 deletions(-)
diff --git a/polaris-core/src/main/java/org/apache/polaris/core/storage/StorageLocation.java b/polaris-core/src/main/java/org/apache/polaris/core/storage/StorageLocation.java
index 6fe12b9585..5c1ff85eaf 100644
--- a/polaris-core/src/main/java/org/apache/polaris/core/storage/StorageLocation.java
+++ b/polaris-core/src/main/java/org/apache/polaris/core/storage/StorageLocation.java
@@ -73,6 +73,18 @@ public class StorageLocation {
}
}
+ /**
+ * Strips a single leading slash from a path. A {@code null} path is treated as empty. Tolerating
+ * an empty/absent path matters for bucket-root locations such as {@code gs://bucket}, whose raw
+ * path is empty and would otherwise break an unguarded {@code substring(1)}.
+ */
+ public static String trimLeadingSlash(String path) {
+ if (path == null) {
+ return "";
+ }
+ return path.startsWith("/") ? path.substring(1) : path;
+ }
+
/** If a path doesn't start with `/`, this will add one */
protected static @NonNull String ensureLeadingSlash(@NonNull String location) {
if (location.startsWith("/")) {
diff --git a/polaris-core/src/main/java/org/apache/polaris/core/storage/aws/AwsCredentialsStorageIntegration.java b/polaris-core/src/main/java/org/apache/polaris/core/storage/aws/AwsCredentialsStorageIntegration.java
index 5b81bec09a..e16b9d7041 100644
--- a/polaris-core/src/main/java/org/apache/polaris/core/storage/aws/AwsCredentialsStorageIntegration.java
+++ b/polaris-core/src/main/java/org/apache/polaris/core/storage/aws/AwsCredentialsStorageIntegration.java
@@ -19,6 +19,7 @@
package org.apache.polaris.core.storage.aws;
import static org.apache.polaris.core.config.FeatureConfiguration.STORAGE_CREDENTIAL_DURATION_SECONDS;
+import static org.apache.polaris.core.storage.StorageLocation.trimLeadingSlash;
import static org.apache.polaris.core.storage.aws.AwsSessionNameBuilder.buildSessionName;
import static org.apache.polaris.core.storage.aws.AwsSessionTagsBuilder.buildSessionTags;
@@ -558,11 +559,4 @@ public class AwsCredentialsStorageIntegration
}
return escaped.toString();
}
-
- private static @NonNull String trimLeadingSlash(String path) {
- if (path.startsWith("/")) {
- path = path.substring(1);
- }
- return path;
- }
}
diff --git a/polaris-core/src/main/java/org/apache/polaris/core/storage/azure/AzureLocation.java b/polaris-core/src/main/java/org/apache/polaris/core/storage/azure/AzureLocation.java
index af771649cc..711c27deea 100644
--- a/polaris-core/src/main/java/org/apache/polaris/core/storage/azure/AzureLocation.java
+++ b/polaris-core/src/main/java/org/apache/polaris/core/storage/azure/AzureLocation.java
@@ -70,7 +70,7 @@ public class AzureLocation extends StorageLocation {
this.storageAccount = hostParts[0];
this.endpoint = hostParts[1];
String path = matcher.group(3);
- filePath = path == null ? "" : path.startsWith("/") ? path.substring(1) : path;
+ filePath = StorageLocation.trimLeadingSlash(path);
}
/** Get the storage account */
diff --git a/polaris-core/src/main/java/org/apache/polaris/core/storage/gcp/GcpCredentialsStorageIntegration.java b/polaris-core/src/main/java/org/apache/polaris/core/storage/gcp/GcpCredentialsStorageIntegration.java
index c7c5e9c370..b91f490b95 100644
--- a/polaris-core/src/main/java/org/apache/polaris/core/storage/gcp/GcpCredentialsStorageIntegration.java
+++ b/polaris-core/src/main/java/org/apache/polaris/core/storage/gcp/GcpCredentialsStorageIntegration.java
@@ -19,6 +19,7 @@
package org.apache.polaris.core.storage.gcp;
import static org.apache.polaris.core.storage.StorageLocation.ensureTrailingSlash;
+import static org.apache.polaris.core.storage.StorageLocation.trimLeadingSlash;
import com.google.auth.http.HttpTransportFactory;
import com.google.auth.oauth2.AccessToken;
@@ -581,16 +582,4 @@ public class GcpCredentialsStorageIntegration
private static String bucketResource(String bucket) {
return "//storage.googleapis.com/projects/_/buckets/" + bucket;
}
-
- /**
- * Strips a single leading slash from a raw path, tolerating an empty raw path. A bucket-root
- * location such as {@code gs://bucket} parses to an empty raw path, so an unguarded {@code
- * substring(1)} would throw. This mirrors the AWS integration's handling.
- */
- private static String trimLeadingSlash(String path) {
- if (path.startsWith("/")) {
- path = path.substring(1);
- }
- return path;
- }
}