Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert "StatusException/StatusRuntimeException hide stack trace in a simpler way" #11066

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
16 changes: 14 additions & 2 deletions api/src/main/java/io/grpc/StatusException.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public class StatusException extends Exception {
private static final long serialVersionUID = -660954903976144640L;
private final Status status;
private final Metadata trailers;
private final boolean fillInStackTrace;

/**
* Constructs an exception with both a status. See also {@link Status#asException()}.
Expand All @@ -48,10 +49,21 @@ public StatusException(Status status, @Nullable Metadata trailers) {
}

StatusException(Status status, @Nullable Metadata trailers, boolean fillInStackTrace) {
super(Status.formatThrowableMessage(status), status.getCause(),
/* enableSuppression */ true, /* writableStackTrace */fillInStackTrace);
super(Status.formatThrowableMessage(status), status.getCause());
this.status = status;
this.trailers = trailers;
this.fillInStackTrace = fillInStackTrace;
fillInStackTrace();
}

@Override
public synchronized Throwable fillInStackTrace() {
// Let's observe final variables in two states! This works because Throwable will invoke this
// method before fillInStackTrace is set, thus doing nothing. After the constructor has set
// fillInStackTrace, this method will properly fill it in. Additionally, sub classes may call
// this normally, because fillInStackTrace will either be set, or this method will be
// overriden.
return fillInStackTrace ? super.fillInStackTrace() : this;
}

/**
Expand Down
17 changes: 15 additions & 2 deletions api/src/main/java/io/grpc/StatusRuntimeException.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ public class StatusRuntimeException extends RuntimeException {
private final Status status;
private final Metadata trailers;

private final boolean fillInStackTrace;

/**
* Constructs the exception with both a status. See also {@link Status#asRuntimeException()}.
*
Expand All @@ -49,10 +51,21 @@ public StatusRuntimeException(Status status, @Nullable Metadata trailers) {
}

StatusRuntimeException(Status status, @Nullable Metadata trailers, boolean fillInStackTrace) {
super(Status.formatThrowableMessage(status), status.getCause(),
/* enable suppressions */ true, /* writableStackTrace */ fillInStackTrace);
super(Status.formatThrowableMessage(status), status.getCause());
this.status = status;
this.trailers = trailers;
this.fillInStackTrace = fillInStackTrace;
fillInStackTrace();
}

@Override
public synchronized Throwable fillInStackTrace() {
// Let's observe final variables in two states! This works because Throwable will invoke this
// method before fillInStackTrace is set, thus doing nothing. After the constructor has set
// fillInStackTrace, this method will properly fill it in. Additionally, sub classes may call
// this normally, because fillInStackTrace will either be set, or this method will be
// overriden.
return fillInStackTrace ? super.fillInStackTrace() : this;
}

/**
Expand Down