Skip to content

Commit

Permalink
Defensively call isShutdown method for executor description
Browse files Browse the repository at this point in the history
Closes gh-34514
  • Loading branch information
jhoeller committed Feb 28, 2025
1 parent 34315fc commit 559ea6c
Showing 1 changed file with 8 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2023 the original author or authors.
* Copyright 2002-2025 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -69,7 +69,13 @@ public TaskRejectedException(Executor executor, Object task, RejectedExecutionEx

private static String executorDescription(Executor executor) {
if (executor instanceof ExecutorService executorService) {
return "ExecutorService in " + (executorService.isShutdown() ? "shutdown" : "active") + " state";
try {
return "ExecutorService in " + (executorService.isShutdown() ? "shutdown" : "active") + " state";
}
catch (Exception ex) {
// UnsupportedOperationException/IllegalStateException from ManagedExecutorService.isShutdown()
// Falling back to toString() below.
}
}
return executor.toString();
}
Expand Down

0 comments on commit 559ea6c

Please sign in to comment.