From b4ed940f92749972f8c2c867bc0428d4bb2539e8 Mon Sep 17 00:00:00 2001 From: Alexander Dinauer Date: Fri, 7 Nov 2025 11:39:26 +0100 Subject: [PATCH 1/4] Log why a properties file was not loaded --- .../java/io/sentry/config/FilesystemPropertiesLoader.java | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/sentry/src/main/java/io/sentry/config/FilesystemPropertiesLoader.java b/sentry/src/main/java/io/sentry/config/FilesystemPropertiesLoader.java index de93d5bbad6..b3bf0526486 100644 --- a/sentry/src/main/java/io/sentry/config/FilesystemPropertiesLoader.java +++ b/sentry/src/main/java/io/sentry/config/FilesystemPropertiesLoader.java @@ -31,6 +31,12 @@ public FilesystemPropertiesLoader(@NotNull String filePath, @NotNull ILogger log properties.load(is); return properties; } + } 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); + } else if (!f.canRead()) { + logger.log( + SentryLevel.ERROR, "Failed to load Sentry configuration since it is not readable: %s", filePath); } } catch (IOException e) { logger.log( From 274b6df82ce6436d4e39474d5574178de0b741b2 Mon Sep 17 00:00:00 2001 From: Sentry Github Bot Date: Fri, 7 Nov 2025 10:43:58 +0000 Subject: [PATCH 2/4] Format code --- .../java/io/sentry/config/FilesystemPropertiesLoader.java | 8 ++++++-- 1 file changed, 6 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..25b1b267038 100644 --- a/sentry/src/main/java/io/sentry/config/FilesystemPropertiesLoader.java +++ b/sentry/src/main/java/io/sentry/config/FilesystemPropertiesLoader.java @@ -33,10 +33,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 (IOException e) { logger.log( From 8b95cbe6129b64e1ccbe8c0255822f0dd49702c6 Mon Sep 17 00:00:00 2001 From: Alexander Dinauer Date: Mon, 10 Nov 2025 14:48:50 +0100 Subject: [PATCH 3/4] fix(config): Trim whitespace on properties path (#4880) * Trim whitespace on properties file path * format * changelog --- CHANGELOG.md | 1 + .../io/sentry/config/FilesystemPropertiesLoader.java | 5 ++--- .../sentry/config/FilesystemPropertiesLoaderTest.kt | 11 +++++++++++ 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f342737d994..c161981e1e7 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)) - Only set `DefaultReplayBreadcrumbConverter` if replay is available ([#4888](https://github.com/getsentry/sentry-java/pull/4888)) ### Improvements diff --git a/sentry/src/main/java/io/sentry/config/FilesystemPropertiesLoader.java b/sentry/src/main/java/io/sentry/config/FilesystemPropertiesLoader.java index 25b1b267038..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; @@ -24,7 +23,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(); @@ -42,7 +41,7 @@ public FilesystemPropertiesLoader(@NotNull String filePath, @NotNull ILogger log "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..1addfb449bc 100644 --- a/sentry/src/test/java/io/sentry/config/FilesystemPropertiesLoaderTest.kt +++ b/sentry/src/test/java/io/sentry/config/FilesystemPropertiesLoaderTest.kt @@ -22,6 +22,17 @@ 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 0f3ff3c8d949ca7eea51200077260f3a18c51797 Mon Sep 17 00:00:00 2001 From: Alexander Dinauer Date: Mon, 10 Nov 2025 14:50:15 +0100 Subject: [PATCH 4/4] changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index c161981e1e7..ebb582c096c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,7 @@ - Fallback to distinct-id as user.id logging attribute when user is not set ([#4847](https://github.com/getsentry/sentry-java/pull/4847)) - Report Timber.tag() as `timber.tag` log attribute ([#4845](https://github.com/getsentry/sentry-java/pull/4845)) - Session Replay: Add screenshot strategy serialization to RRWeb events ([#4851](https://github.com/getsentry/sentry-java/pull/4851)) +- Log why a properties file was not loaded ([#4879](https://github.com/getsentry/sentry-java/pull/4879)) ### Dependencies