Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,15 @@

- 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

- 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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -24,15 +23,25 @@ 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();
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);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: Whitespace Path Mismatch

The error messages log the original filePath which may contain whitespace, but the actual file check uses filePath.trim(). This creates confusing logs where the displayed path doesn't match the path that was actually checked, making debugging difficult when paths have leading or trailing whitespace.

Fix in Cursor Fix in Web

}
} catch (IOException e) {
} catch (Throwable e) {
logger.log(
SentryLevel.ERROR, e, "Failed to load Sentry configuration from file: %s", filePath);
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down
Loading