From 8e5fab5ce61937ca22ff30712db32e55d9e19cba Mon Sep 17 00:00:00 2001 From: Alexander Dinauer Date: Fri, 7 Nov 2025 12:08:25 +0100 Subject: [PATCH 1/3] Trim whitespace on properties file path --- .../io/sentry/config/FilesystemPropertiesLoader.java | 4 ++-- .../io/sentry/config/FilesystemPropertiesLoaderTest.kt | 10 ++++++++++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/sentry/src/main/java/io/sentry/config/FilesystemPropertiesLoader.java b/sentry/src/main/java/io/sentry/config/FilesystemPropertiesLoader.java index b3bf0526486..9ae225f45d1 100644 --- a/sentry/src/main/java/io/sentry/config/FilesystemPropertiesLoader.java +++ b/sentry/src/main/java/io/sentry/config/FilesystemPropertiesLoader.java @@ -24,7 +24,7 @@ public FilesystemPropertiesLoader(@NotNull String filePath, @NotNull ILogger log @Override public @Nullable Properties load() { try { - final File f = new File(filePath); + final File f = new File(filePath.trim()); if (f.isFile() && f.canRead()) { try (InputStream is = new BufferedInputStream(new FileInputStream(f))) { final Properties properties = new Properties(); @@ -38,7 +38,7 @@ public FilesystemPropertiesLoader(@NotNull String filePath, @NotNull ILogger log logger.log( SentryLevel.ERROR, "Failed to load Sentry configuration since it is not readable: %s", filePath); } - } catch (IOException e) { + } catch (Throwable e) { logger.log( SentryLevel.ERROR, e, "Failed to load Sentry configuration from file: %s", filePath); return null; diff --git a/sentry/src/test/java/io/sentry/config/FilesystemPropertiesLoaderTest.kt b/sentry/src/test/java/io/sentry/config/FilesystemPropertiesLoaderTest.kt index 11e3a3a3fbc..237b728ab7b 100644 --- a/sentry/src/test/java/io/sentry/config/FilesystemPropertiesLoaderTest.kt +++ b/sentry/src/test/java/io/sentry/config/FilesystemPropertiesLoaderTest.kt @@ -22,6 +22,16 @@ class FilesystemPropertiesLoaderTest { assertEquals("some-dsn", properties["dsn"]) } + @Test + fun `returns properties when file has whitespace`() { + val file = folder.newFile("sentry.properties") + file.writeText("dsn=some-dsn", Charset.defaultCharset()) + val loader = FilesystemPropertiesLoader(" " + file.absolutePath + " ", NoOpLogger.getInstance()) + val properties = loader.load() + assertNotNull(properties) + assertEquals("some-dsn", properties["dsn"]) + } + @Test fun `returns null when property file not found`() { val loader = From 4b4db829803516782406fddd9ac340c5457c21d4 Mon Sep 17 00:00:00 2001 From: Alexander Dinauer Date: Fri, 7 Nov 2025 12:20:48 +0100 Subject: [PATCH 2/3] format --- .../io/sentry/config/FilesystemPropertiesLoader.java | 9 ++++++--- .../io/sentry/config/FilesystemPropertiesLoaderTest.kt | 3 ++- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/sentry/src/main/java/io/sentry/config/FilesystemPropertiesLoader.java b/sentry/src/main/java/io/sentry/config/FilesystemPropertiesLoader.java index 9ae225f45d1..dcb1ea91009 100644 --- a/sentry/src/main/java/io/sentry/config/FilesystemPropertiesLoader.java +++ b/sentry/src/main/java/io/sentry/config/FilesystemPropertiesLoader.java @@ -5,7 +5,6 @@ import java.io.BufferedInputStream; import java.io.File; import java.io.FileInputStream; -import java.io.IOException; import java.io.InputStream; import java.util.Properties; import org.jetbrains.annotations.NotNull; @@ -33,10 +32,14 @@ public FilesystemPropertiesLoader(@NotNull String filePath, @NotNull ILogger log } } else if (!f.isFile()) { logger.log( - SentryLevel.ERROR, "Failed to load Sentry configuration since it is not a file or does not exist: %s", filePath); + SentryLevel.ERROR, + "Failed to load Sentry configuration since it is not a file or does not exist: %s", + filePath); } else if (!f.canRead()) { logger.log( - SentryLevel.ERROR, "Failed to load Sentry configuration since it is not readable: %s", filePath); + SentryLevel.ERROR, + "Failed to load Sentry configuration since it is not readable: %s", + filePath); } } catch (Throwable e) { logger.log( diff --git a/sentry/src/test/java/io/sentry/config/FilesystemPropertiesLoaderTest.kt b/sentry/src/test/java/io/sentry/config/FilesystemPropertiesLoaderTest.kt index 237b728ab7b..1addfb449bc 100644 --- a/sentry/src/test/java/io/sentry/config/FilesystemPropertiesLoaderTest.kt +++ b/sentry/src/test/java/io/sentry/config/FilesystemPropertiesLoaderTest.kt @@ -26,7 +26,8 @@ class FilesystemPropertiesLoaderTest { fun `returns properties when file has whitespace`() { val file = folder.newFile("sentry.properties") file.writeText("dsn=some-dsn", Charset.defaultCharset()) - val loader = FilesystemPropertiesLoader(" " + file.absolutePath + " ", NoOpLogger.getInstance()) + val loader = + FilesystemPropertiesLoader(" " + file.absolutePath + " ", NoOpLogger.getInstance()) val properties = loader.load() assertNotNull(properties) assertEquals("some-dsn", properties["dsn"]) From 2fe170d22f839f6b29aeb82b3264775b79af8707 Mon Sep 17 00:00:00 2001 From: Alexander Dinauer Date: Fri, 7 Nov 2025 12:33:26 +0100 Subject: [PATCH 3/3] changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6c55dcc5d73..6f1fcc48690 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,7 @@ - Removed SentryExecutorService limit for delayed scheduled tasks ([#4846](https://github.com/getsentry/sentry-java/pull/4846)) - Fix visual artifacts for the Canvas strategy on some devices ([#4861](https://github.com/getsentry/sentry-java/pull/4861)) +- [Config] Trim whitespace on properties path ([#4880](https://github.com/getsentry/sentry-java/pull/4880)) ### Improvements