Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

## Unreleased

### Internal

- Reduce JSON serialization overhead by allocating reflection cycle-tracking state only when reflection serialization is used. ([#5600](https://github.com/getsentry/sentry-java/pull/5600))

## 8.45.0

### Features
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
@ApiStatus.Internal
public final class JsonReflectionObjectSerializer {

private final Set<Object> visiting = new HashSet<>();
private @Nullable Set<Object> visiting;
private final int maxDepth;

JsonReflectionObjectSerializer(int maxDepth) {
Expand Down Expand Up @@ -69,6 +69,7 @@ public final class JsonReflectionObjectSerializer {
} else if (object.getClass().isEnum()) {
return object.toString();
} else {
final Set<Object> visiting = getVisiting();
if (visiting.contains(object)) {
logger.log(SentryLevel.INFO, "Cyclic reference detected. Calling toString() on object.");
return object.toString();
Expand Down Expand Up @@ -135,6 +136,13 @@ public final class JsonReflectionObjectSerializer {

// Helper

private @NotNull Set<Object> getVisiting() {
if (visiting == null) {
visiting = new HashSet<>();
}
return visiting;
}

private @NotNull List<Object> list(@NotNull Object[] objectArray, @NotNull ILogger logger)
throws Exception {
List<Object> list = new ArrayList<>();
Expand Down
Loading