mirror of https://github.com/grpc/grpc-java.git
StatusException/StatusRuntimeException hide stack trace in a simpler way (#11064)
This commit is contained in:
parent
0866e716d6
commit
e36f099be9
|
|
@ -27,7 +27,6 @@ public class StatusException extends Exception {
|
||||||
private static final long serialVersionUID = -660954903976144640L;
|
private static final long serialVersionUID = -660954903976144640L;
|
||||||
private final Status status;
|
private final Status status;
|
||||||
private final Metadata trailers;
|
private final Metadata trailers;
|
||||||
private final boolean fillInStackTrace;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructs an exception with both a status. See also {@link Status#asException()}.
|
* Constructs an exception with both a status. See also {@link Status#asException()}.
|
||||||
|
|
@ -49,21 +48,10 @@ public class StatusException extends Exception {
|
||||||
}
|
}
|
||||||
|
|
||||||
StatusException(Status status, @Nullable Metadata trailers, boolean fillInStackTrace) {
|
StatusException(Status status, @Nullable Metadata trailers, boolean fillInStackTrace) {
|
||||||
super(Status.formatThrowableMessage(status), status.getCause());
|
super(Status.formatThrowableMessage(status), status.getCause(),
|
||||||
|
/* enableSuppression */ true, /* writableStackTrace */fillInStackTrace);
|
||||||
this.status = status;
|
this.status = status;
|
||||||
this.trailers = trailers;
|
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -29,8 +29,6 @@ public class StatusRuntimeException extends RuntimeException {
|
||||||
private final Status status;
|
private final Status status;
|
||||||
private final Metadata trailers;
|
private final Metadata trailers;
|
||||||
|
|
||||||
private final boolean fillInStackTrace;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructs the exception with both a status. See also {@link Status#asRuntimeException()}.
|
* Constructs the exception with both a status. See also {@link Status#asRuntimeException()}.
|
||||||
*
|
*
|
||||||
|
|
@ -51,21 +49,10 @@ public class StatusRuntimeException extends RuntimeException {
|
||||||
}
|
}
|
||||||
|
|
||||||
StatusRuntimeException(Status status, @Nullable Metadata trailers, boolean fillInStackTrace) {
|
StatusRuntimeException(Status status, @Nullable Metadata trailers, boolean fillInStackTrace) {
|
||||||
super(Status.formatThrowableMessage(status), status.getCause());
|
super(Status.formatThrowableMessage(status), status.getCause(),
|
||||||
|
/* enable suppressions */ true, /* writableStackTrace */ fillInStackTrace);
|
||||||
this.status = status;
|
this.status = status;
|
||||||
this.trailers = trailers;
|
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue