Skip to content

Commit d394cef

Browse files
committed
core: Avoid wrapping Errors in RuntimeException
1 parent f25f55a commit d394cef

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
@@ -364,10 +364,10 @@ public void runInContext() {
364364
stream.close(Status.fromThrowable(e), new Metadata());
365365
context.cancel(null);
366366
throw e;
367-
} catch (Throwable t) {
368-
stream.close(Status.fromThrowable(t), new Metadata());
367+
} catch (Error e) {
368+
stream.close(Status.fromThrowable(e), new Metadata());
369369
context.cancel(null);
370-
throw new RuntimeException(t);
370+
throw e;
371371
} finally {
372372
jumpListener.setListener(listener);
373373
}
@@ -487,9 +487,9 @@ public void runInContext() {
487487
} catch (RuntimeException e) {
488488
internalClose(Status.fromThrowable(e), new Metadata());
489489
throw e;
490-
} catch (Throwable t) {
491-
internalClose(Status.fromThrowable(t), new Metadata());
492-
throw new RuntimeException(t);
490+
} catch (Error e) {
491+
internalClose(Status.fromThrowable(e), new Metadata());
492+
throw e;
493493
}
494494
}
495495
});
@@ -505,9 +505,9 @@ public void runInContext() {
505505
} catch (RuntimeException e) {
506506
internalClose(Status.fromThrowable(e), new Metadata());
507507
throw e;
508-
} catch (Throwable t) {
509-
internalClose(Status.fromThrowable(t), new Metadata());
510-
throw new RuntimeException(t);
508+
} catch (Error e) {
509+
internalClose(Status.fromThrowable(e), new Metadata());
510+
throw e;
511511
}
512512
}
513513
});

0 commit comments

Comments
 (0)