Skip to content

Commit 22393f9

Browse files
ejona86zhangkun83
authored andcommitted
core: Avoid wrapping Errors in RuntimeException
1 parent c14edca commit 22393f9

File tree

2 files changed

+13
-10
lines changed

2 files changed

+13
-10
lines changed

core/src/main/java/io/grpc/internal/LogExceptionRunnable.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@
3333

3434
import static com.google.common.base.Preconditions.checkNotNull;
3535

36+
import com.google.common.base.Throwables;
37+
3638
import java.util.logging.Level;
3739
import java.util.logging.Logger;
3840

@@ -56,7 +58,8 @@ public void run() {
5658
task.run();
5759
} catch (Throwable t) {
5860
log.log(Level.SEVERE, "Exception while executing runnable " + task, t);
59-
throw t instanceof RuntimeException ? (RuntimeException) t : new RuntimeException(t);
61+
Throwables.propagateIfPossible(t);
62+
throw new AssertionError(t);
6063
}
6164
}
6265

core/src/main/java/io/grpc/internal/ServerImpl.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -363,10 +363,10 @@ public void runInContext() {
363363
stream.close(Status.fromThrowable(e), new Metadata());
364364
context.cancel(null);
365365
throw e;
366-
} catch (Throwable t) {
367-
stream.close(Status.fromThrowable(t), new Metadata());
366+
} catch (Error e) {
367+
stream.close(Status.fromThrowable(e), new Metadata());
368368
context.cancel(null);
369-
throw new RuntimeException(t);
369+
throw e;
370370
} finally {
371371
jumpListener.setListener(listener);
372372
}
@@ -486,9 +486,9 @@ public void runInContext() {
486486
} catch (RuntimeException e) {
487487
internalClose(Status.fromThrowable(e), new Metadata());
488488
throw e;
489-
} catch (Throwable t) {
490-
internalClose(Status.fromThrowable(t), new Metadata());
491-
throw new RuntimeException(t);
489+
} catch (Error e) {
490+
internalClose(Status.fromThrowable(e), new Metadata());
491+
throw e;
492492
}
493493
}
494494
});
@@ -504,9 +504,9 @@ public void runInContext() {
504504
} catch (RuntimeException e) {
505505
internalClose(Status.fromThrowable(e), new Metadata());
506506
throw e;
507-
} catch (Throwable t) {
508-
internalClose(Status.fromThrowable(t), new Metadata());
509-
throw new RuntimeException(t);
507+
} catch (Error e) {
508+
internalClose(Status.fromThrowable(e), new Metadata());
509+
throw e;
510510
}
511511
}
512512
});

0 commit comments

Comments
 (0)