From 559ea6c4809376e14a8365c8b66c229070703d16 Mon Sep 17 00:00:00 2001 From: Juergen Hoeller Date: Fri, 28 Feb 2025 14:11:57 +0100 Subject: [PATCH] Defensively call isShutdown method for executor description Closes gh-34514 --- .../core/task/TaskRejectedException.java | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/spring-core/src/main/java/org/springframework/core/task/TaskRejectedException.java b/spring-core/src/main/java/org/springframework/core/task/TaskRejectedException.java index 6d70d26f4bef..68b31633304c 100644 --- a/spring-core/src/main/java/org/springframework/core/task/TaskRejectedException.java +++ b/spring-core/src/main/java/org/springframework/core/task/TaskRejectedException.java @@ -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. @@ -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(); }