(Lio/sentry/util/LazyEvaluator$Evaluator;)V
public fun getValue ()Ljava/lang/Object;
+ public fun setValue (Ljava/lang/Object;)V
}
public abstract interface class io/sentry/util/LazyEvaluator$Evaluator {
diff --git a/sentry/src/main/java/io/sentry/ExperimentalOptions.java b/sentry/src/main/java/io/sentry/ExperimentalOptions.java
index f587996bd8..4a0e7de78d 100644
--- a/sentry/src/main/java/io/sentry/ExperimentalOptions.java
+++ b/sentry/src/main/java/io/sentry/ExperimentalOptions.java
@@ -9,7 +9,11 @@
* Beware that experimental options can change at any time.
*/
public final class ExperimentalOptions {
- private @NotNull SentryReplayOptions sessionReplay = new SentryReplayOptions();
+ private @NotNull SentryReplayOptions sessionReplay;
+
+ public ExperimentalOptions(final boolean empty) {
+ this.sessionReplay = new SentryReplayOptions(empty);
+ }
@NotNull
public SentryReplayOptions getSessionReplay() {
diff --git a/sentry/src/main/java/io/sentry/SentryOptions.java b/sentry/src/main/java/io/sentry/SentryOptions.java
index 3ff84c48de..61c721847c 100644
--- a/sentry/src/main/java/io/sentry/SentryOptions.java
+++ b/sentry/src/main/java/io/sentry/SentryOptions.java
@@ -19,13 +19,13 @@
import io.sentry.transport.ITransportGate;
import io.sentry.transport.NoOpEnvelopeCache;
import io.sentry.transport.NoOpTransportGate;
+import io.sentry.util.LazyEvaluator;
import io.sentry.util.Platform;
import io.sentry.util.SampleRateUtils;
import io.sentry.util.StringUtils;
import io.sentry.util.thread.IMainThreadChecker;
import io.sentry.util.thread.NoOpMainThreadChecker;
import java.io.File;
-import java.net.Proxy;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
@@ -118,11 +118,13 @@ public class SentryOptions {
/** minimum LogLevel to be used if debug is enabled */
private @NotNull SentryLevel diagnosticLevel = DEFAULT_DIAGNOSTIC_LEVEL;
- /** Envelope reader interface */
- private @NotNull IEnvelopeReader envelopeReader = new EnvelopeReader(new JsonSerializer(this));
-
/** Serializer interface to serialize/deserialize json events */
- private @NotNull ISerializer serializer = new JsonSerializer(this);
+ private final @NotNull LazyEvaluator serializer =
+ new LazyEvaluator<>(() -> new JsonSerializer(this));
+
+ /** Envelope reader interface */
+ private final @NotNull LazyEvaluator envelopeReader =
+ new LazyEvaluator<>(() -> new EnvelopeReader(serializer.getValue()));
/** Max depth when serializing object graphs with reflection. * */
private int maxDepth = 100;
@@ -416,7 +418,8 @@ public class SentryOptions {
/** Date provider to retrieve the current date from. */
@ApiStatus.Internal
- private @NotNull SentryDateProvider dateProvider = new SentryAutoDateProvider();
+ private final @NotNull LazyEvaluator dateProvider =
+ new LazyEvaluator<>(() -> new SentryAutoDateProvider());
private final @NotNull List performanceCollectors = new ArrayList<>();
@@ -479,7 +482,7 @@ public class SentryOptions {
@ApiStatus.Experimental private @Nullable Cron cron = null;
- private final @NotNull ExperimentalOptions experimental = new ExperimentalOptions();
+ private final @NotNull ExperimentalOptions experimental;
private @NotNull ReplayController replayController = NoOpReplayController.getInstance();
@@ -605,7 +608,7 @@ public void setDiagnosticLevel(@Nullable final SentryLevel diagnosticLevel) {
* @return the serializer
*/
public @NotNull ISerializer getSerializer() {
- return serializer;
+ return serializer.getValue();
}
/**
@@ -614,7 +617,7 @@ public void setDiagnosticLevel(@Nullable final SentryLevel diagnosticLevel) {
* @param serializer the serializer
*/
public void setSerializer(@Nullable ISerializer serializer) {
- this.serializer = serializer != null ? serializer : NoOpSerializer.getInstance();
+ this.serializer.setValue(serializer != null ? serializer : NoOpSerializer.getInstance());
}
/**
@@ -636,12 +639,12 @@ public void setMaxDepth(int maxDepth) {
}
public @NotNull IEnvelopeReader getEnvelopeReader() {
- return envelopeReader;
+ return envelopeReader.getValue();
}
public void setEnvelopeReader(final @Nullable IEnvelopeReader envelopeReader) {
- this.envelopeReader =
- envelopeReader != null ? envelopeReader : NoOpEnvelopeReader.getInstance();
+ this.envelopeReader.setValue(
+ envelopeReader != null ? envelopeReader : NoOpEnvelopeReader.getInstance());
}
/**
@@ -2212,7 +2215,7 @@ public void setIgnoredCheckIns(final @Nullable List ignoredCheckIns) {
/** Returns the current {@link SentryDateProvider} that is used to retrieve the current date. */
@ApiStatus.Internal
public @NotNull SentryDateProvider getDateProvider() {
- return dateProvider;
+ return dateProvider.getValue();
}
/**
@@ -2223,7 +2226,7 @@ public void setIgnoredCheckIns(final @Nullable List ignoredCheckIns) {
*/
@ApiStatus.Internal
public void setDateProvider(final @NotNull SentryDateProvider dateProvider) {
- this.dateProvider = dateProvider;
+ this.dateProvider.setValue(dateProvider);
}
/**
@@ -2540,6 +2543,7 @@ public SentryOptions() {
* @param empty if options should be empty.
*/
private SentryOptions(final boolean empty) {
+ experimental = new ExperimentalOptions(empty);
if (!empty) {
// SentryExecutorService should be initialized before any
// SendCachedEventFireAndForgetIntegration
diff --git a/sentry/src/main/java/io/sentry/SentryReplayOptions.java b/sentry/src/main/java/io/sentry/SentryReplayOptions.java
index 7656b088a1..097f72c921 100644
--- a/sentry/src/main/java/io/sentry/SentryReplayOptions.java
+++ b/sentry/src/main/java/io/sentry/SentryReplayOptions.java
@@ -96,14 +96,16 @@ public enum SentryReplayQuality {
/** The maximum duration of a full session replay, defaults to 1h. */
private long sessionDuration = 60 * 60 * 1000L;
- public SentryReplayOptions() {
- setRedactAllText(true);
- setRedactAllImages(true);
+ public SentryReplayOptions(final boolean empty) {
+ if (!empty) {
+ setRedactAllText(true);
+ setRedactAllImages(true);
+ }
}
public SentryReplayOptions(
final @Nullable Double sessionSampleRate, final @Nullable Double onErrorSampleRate) {
- this();
+ this(false);
this.sessionSampleRate = sessionSampleRate;
this.onErrorSampleRate = onErrorSampleRate;
}
diff --git a/sentry/src/main/java/io/sentry/cache/CacheStrategy.java b/sentry/src/main/java/io/sentry/cache/CacheStrategy.java
index dbb6a49c19..d48cc3108d 100644
--- a/sentry/src/main/java/io/sentry/cache/CacheStrategy.java
+++ b/sentry/src/main/java/io/sentry/cache/CacheStrategy.java
@@ -10,6 +10,7 @@
import io.sentry.SentryOptions;
import io.sentry.Session;
import io.sentry.clientreport.DiscardReason;
+import io.sentry.util.LazyEvaluator;
import io.sentry.util.Objects;
import java.io.BufferedInputStream;
import java.io.BufferedReader;
@@ -36,8 +37,9 @@ abstract class CacheStrategy {
@SuppressWarnings("CharsetObjectCanBeUsed")
protected static final Charset UTF_8 = Charset.forName("UTF-8");
- protected final @NotNull SentryOptions options;
- protected final @NotNull ISerializer serializer;
+ protected @NotNull SentryOptions options;
+ protected final @NotNull LazyEvaluator serializer =
+ new LazyEvaluator<>(() -> options.getSerializer());
protected final @NotNull File directory;
private final int maxSize;
@@ -48,7 +50,6 @@ abstract class CacheStrategy {
Objects.requireNonNull(directoryPath, "Directory is required.");
this.options = Objects.requireNonNull(options, "SentryOptions is required.");
- this.serializer = options.getSerializer();
this.directory = new File(directoryPath);
this.maxSize = maxSize;
@@ -177,7 +178,7 @@ private void moveInitFlagIfNecessary(
&& currentSession.getSessionId().equals(session.getSessionId())) {
session.setInitAsTrue();
try {
- newSessionItem = SentryEnvelopeItem.fromSession(serializer, session);
+ newSessionItem = SentryEnvelopeItem.fromSession(serializer.getValue(), session);
// remove item from envelope items so we can replace with the new one that has the
// init flag true
itemsIterator.remove();
@@ -216,7 +217,7 @@ private void moveInitFlagIfNecessary(
private @Nullable SentryEnvelope readEnvelope(final @NotNull File file) {
try (final InputStream inputStream = new BufferedInputStream(new FileInputStream(file))) {
- return serializer.deserializeEnvelope(inputStream);
+ return serializer.getValue().deserializeEnvelope(inputStream);
} catch (IOException e) {
options.getLogger().log(ERROR, "Failed to deserialize the envelope.", e);
}
@@ -258,7 +259,7 @@ private boolean isSessionType(final @Nullable SentryEnvelopeItem item) {
try (final Reader reader =
new BufferedReader(
new InputStreamReader(new ByteArrayInputStream(item.getData()), UTF_8))) {
- return serializer.deserialize(reader, Session.class);
+ return serializer.getValue().deserialize(reader, Session.class);
} catch (Throwable e) {
options.getLogger().log(ERROR, "Failed to deserialize the session.", e);
}
@@ -268,7 +269,7 @@ private boolean isSessionType(final @Nullable SentryEnvelopeItem item) {
private void saveNewEnvelope(
final @NotNull SentryEnvelope envelope, final @NotNull File file, final long timestamp) {
try (final OutputStream outputStream = new FileOutputStream(file)) {
- serializer.serialize(envelope, outputStream);
+ serializer.getValue().serialize(envelope, outputStream);
// we need to set the same timestamp so the sorting from oldest to newest wont break.
file.setLastModified(timestamp);
} catch (Throwable e) {
diff --git a/sentry/src/main/java/io/sentry/cache/EnvelopeCache.java b/sentry/src/main/java/io/sentry/cache/EnvelopeCache.java
index 3be857a4b2..82636ac6c1 100644
--- a/sentry/src/main/java/io/sentry/cache/EnvelopeCache.java
+++ b/sentry/src/main/java/io/sentry/cache/EnvelopeCache.java
@@ -116,7 +116,7 @@ public void store(final @NotNull SentryEnvelope envelope, final @NotNull Hint hi
try (final Reader reader =
new BufferedReader(
new InputStreamReader(new FileInputStream(currentSessionFile), UTF_8))) {
- final Session session = serializer.deserialize(reader, Session.class);
+ final Session session = serializer.getValue().deserialize(reader, Session.class);
if (session != null) {
writeSessionToDisk(previousSessionFile, session);
}
@@ -204,7 +204,7 @@ private void tryEndPreviousSession(final @NotNull Hint hint) {
try (final Reader reader =
new BufferedReader(
new InputStreamReader(new FileInputStream(previousSessionFile), UTF_8))) {
- final Session session = serializer.deserialize(reader, Session.class);
+ final Session session = serializer.getValue().deserialize(reader, Session.class);
if (session != null) {
final AbnormalExit abnormalHint = (AbnormalExit) sdkHint;
final @Nullable Long abnormalExitTimestamp = abnormalHint.timestamp();
@@ -263,7 +263,7 @@ private void updateCurrentSession(
try (final Reader reader =
new BufferedReader(
new InputStreamReader(new ByteArrayInputStream(item.getData()), UTF_8))) {
- final Session session = serializer.deserialize(reader, Session.class);
+ final Session session = serializer.getValue().deserialize(reader, Session.class);
if (session == null) {
options
.getLogger()
@@ -304,7 +304,7 @@ private void writeEnvelopeToDisk(
}
try (final OutputStream outputStream = new FileOutputStream(file)) {
- serializer.serialize(envelope, outputStream);
+ serializer.getValue().serialize(envelope, outputStream);
} catch (Throwable e) {
options
.getLogger()
@@ -324,7 +324,7 @@ private void writeSessionToDisk(final @NotNull File file, final @NotNull Session
try (final OutputStream outputStream = new FileOutputStream(file);
final Writer writer = new BufferedWriter(new OutputStreamWriter(outputStream, UTF_8))) {
- serializer.serialize(session, writer);
+ serializer.getValue().serialize(session, writer);
} catch (Throwable e) {
options
.getLogger()
@@ -388,7 +388,7 @@ public void discard(final @NotNull SentryEnvelope envelope) {
for (final File file : allCachedEnvelopes) {
try (final InputStream is = new BufferedInputStream(new FileInputStream(file))) {
- ret.add(serializer.deserializeEnvelope(is));
+ ret.add(serializer.getValue().deserializeEnvelope(is));
} catch (FileNotFoundException e) {
options
.getLogger()
diff --git a/sentry/src/main/java/io/sentry/clientreport/AtomicClientReportStorage.java b/sentry/src/main/java/io/sentry/clientreport/AtomicClientReportStorage.java
index 2e7f0c27a7..fd1f9a9de9 100644
--- a/sentry/src/main/java/io/sentry/clientreport/AtomicClientReportStorage.java
+++ b/sentry/src/main/java/io/sentry/clientreport/AtomicClientReportStorage.java
@@ -1,10 +1,12 @@
package io.sentry.clientreport;
import io.sentry.DataCategory;
+import io.sentry.util.LazyEvaluator;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;
+import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.atomic.AtomicLong;
import org.jetbrains.annotations.ApiStatus;
@@ -14,25 +16,28 @@
@ApiStatus.Internal
final class AtomicClientReportStorage implements IClientReportStorage {
- private final @NotNull Map lostEventCounts;
+ private final @NotNull LazyEvaluator