Skip to content

Commit c8648dc

Browse files
committed
core: Remove usage of LogExceptionRunnable from Deadline
io.grpc should not be depending on anything from internal. Also, the convenience method of Deadline is part of our public API and shouldn't use LogExceptionRunnable because it would surprise our users. Swapped to lower-case 'log' since the logger is not immutable.
1 parent 5384f97 commit c8648dc

File tree

2 files changed

+9
-8
lines changed

2 files changed

+9
-8
lines changed

core/src/main/java/io/grpc/Context.java

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@
108108
*/
109109
public class Context {
110110

111-
private static final Logger LOG = Logger.getLogger(Context.class.getName());
111+
private static final Logger log = Logger.getLogger(Context.class.getName());
112112

113113
private static final Object[][] EMPTY_ENTRIES = new Object[0][2];
114114

@@ -354,7 +354,7 @@ public void detach(Context toAttach) {
354354
// Log a severe message instead of throwing an exception as the context to attach is assumed
355355
// to be the correct one and the unbalanced state represents a coding mistake in a lower
356356
// layer in the stack that cannot be recovered from here.
357-
LOG.log(Level.SEVERE, "Context was not attached when detaching",
357+
log.log(Level.SEVERE, "Context was not attached when detaching",
358358
new Throwable().fillInStackTrace());
359359
}
360360
}
@@ -657,7 +657,11 @@ private CancellableContext(Context parent, Deadline deadline,
657657
pendingDeadline = deadline.runOnExpiration(new Runnable() {
658658
@Override
659659
public void run() {
660-
cancel(cause);
660+
try {
661+
cancel(cause);
662+
} catch (Throwable t) {
663+
log.log(Level.SEVERE, "Cancel threw an exception, which should not happen", t);
664+
}
661665
}
662666
}, scheduler);
663667
} else {
@@ -817,7 +821,7 @@ private void deliver() {
817821
try {
818822
executor.execute(this);
819823
} catch (Throwable t) {
820-
LOG.log(Level.INFO, "Exception notifying context listener", t);
824+
log.log(Level.INFO, "Exception notifying context listener", t);
821825
}
822826
}
823827

core/src/main/java/io/grpc/Deadline.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,6 @@
3434
import com.google.common.annotations.VisibleForTesting;
3535
import com.google.common.base.Preconditions;
3636

37-
import io.grpc.internal.LogExceptionRunnable;
38-
3937
import java.util.concurrent.ScheduledExecutorService;
4038
import java.util.concurrent.ScheduledFuture;
4139
import java.util.concurrent.TimeUnit;
@@ -150,8 +148,7 @@ public long timeRemaining(TimeUnit unit) {
150148
public ScheduledFuture<?> runOnExpiration(Runnable task, ScheduledExecutorService scheduler) {
151149
Preconditions.checkNotNull(task, "task");
152150
Preconditions.checkNotNull(scheduler, "scheduler");
153-
return scheduler.schedule(new LogExceptionRunnable(task),
154-
deadlineNanos - ticker.read(), TimeUnit.NANOSECONDS);
151+
return scheduler.schedule(task, deadlineNanos - ticker.read(), TimeUnit.NANOSECONDS);
155152
}
156153

157154
@Override

0 commit comments

Comments
 (0)