Skip to content

Commit

Permalink
Do not cache stacktrace elements
Browse files Browse the repository at this point in the history
  • Loading branch information
schlosna committed Nov 22, 2024
1 parent 222238e commit 239b100
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion dialogue-core/src/main/java/com/palantir/dialogue/core/Uris.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import com.github.benmanes.caffeine.cache.Caffeine;
import com.github.benmanes.caffeine.cache.LoadingCache;
import com.palantir.dialogue.DialogueImmutablesStyle;
import com.palantir.logsafe.Arg;
import com.palantir.logsafe.Preconditions;
import com.palantir.logsafe.Unsafe;
import com.palantir.logsafe.UnsafeArg;
Expand All @@ -41,6 +42,9 @@ public final class Uris {
*/
private static final String MESH_PREFIX = "mesh-";

private static final Arg<?>[] EMPTY_ARGS = new Arg[0];
private static final StackTraceElement[] EMPTY_STACKTRACE = new StackTraceElement[0];

/**
* Shared cache of string to parsed URI. This avoids excessive allocation overhead when parsing repeated targets.
*/
Expand Down Expand Up @@ -110,7 +114,10 @@ default boolean isMeshMode() {
default URI uriOrThrow() {
SafeIllegalArgumentException exception = exception();
if (exception != null) {
throw exception;
throw new SafeIllegalArgumentException(
exception.getLogMessage(),
exception,
exception.getArgs().toArray(EMPTY_ARGS));
}
return Preconditions.checkNotNull(uri(), "uri");
}
Expand All @@ -125,6 +132,8 @@ default void check() {
}

static @Unsafe MaybeUri failure(SafeIllegalArgumentException exception) {
// do not cache stacktrace elements
exception.setStackTrace(EMPTY_STACKTRACE);
return ImmutableMaybeUri.of(null, exception);
}
}
Expand Down

0 comments on commit 239b100

Please sign in to comment.