From 496befd20bb4eb43dd0503f7829742d27b188815 Mon Sep 17 00:00:00 2001 From: Vincent Latombe Date: Wed, 26 Oct 2022 18:02:43 +0200 Subject: [PATCH 1/2] Some exception handling that was forgotten as part of JEP-227 --- core/src/main/java/org/kohsuke/stapler/Stapler.java | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/core/src/main/java/org/kohsuke/stapler/Stapler.java b/core/src/main/java/org/kohsuke/stapler/Stapler.java index 9b36115088..55eaf90224 100644 --- a/core/src/main/java/org/kohsuke/stapler/Stapler.java +++ b/core/src/main/java/org/kohsuke/stapler/Stapler.java @@ -96,6 +96,15 @@ */ public class Stapler extends HttpServlet { + /** + * Exceptions we don't want to print a stacktrace for because they are normal behaviour. + * [HUDSON-4834] A stack trace is too noisy for this; could just need to log in. + * (Could consider doing this for all AcegiSecurityException's.) + */ + private static final List EXCEPTIONS_DO_NOT_PRINT_STACKTRACE = Arrays.asList( + "org.acegisecurity.AccessDeniedException", + "org.springframework.security.access.AccessDeniedException" + ); private /*final*/ ServletContext context; @SuppressFBWarnings(value = "SE_BAD_FIELD", justification = "The Stapler class is not expected to be serialized.") @@ -802,9 +811,7 @@ boolean tryInvoke(RequestImpl req, ResponseImpl rsp, Object node ) throws IOExce if (!isSocketException(e)) { getServletContext().log("Error while serving " + url, e); } - } else if (c.getName().equals("org.acegisecurity.AccessDeniedException")) { - // [HUDSON-4834] A stack trace is too noisy for this; could just need to log in. - // (Could consider doing this for all AcegiSecurityException's.) + } else if (EXCEPTIONS_DO_NOT_PRINT_STACKTRACE.contains(c.getName())) { getServletContext().log("While serving " + url + ": " + cause); break; } From 448166d2d73e42c43ce015a86fa905069ad33ff4 Mon Sep 17 00:00:00 2001 From: Vincent Latombe Date: Thu, 27 Oct 2022 09:40:19 +0200 Subject: [PATCH 2/2] Fix reviews --- core/src/main/java/org/kohsuke/stapler/Stapler.java | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/core/src/main/java/org/kohsuke/stapler/Stapler.java b/core/src/main/java/org/kohsuke/stapler/Stapler.java index 55eaf90224..4bceff3d64 100644 --- a/core/src/main/java/org/kohsuke/stapler/Stapler.java +++ b/core/src/main/java/org/kohsuke/stapler/Stapler.java @@ -98,10 +98,9 @@ public class Stapler extends HttpServlet { /** * Exceptions we don't want to print a stacktrace for because they are normal behaviour. - * [HUDSON-4834] A stack trace is too noisy for this; could just need to log in. - * (Could consider doing this for all AcegiSecurityException's.) + * [JENKINS-4834] A stack trace is too noisy for this; could just need to log in. */ - private static final List EXCEPTIONS_DO_NOT_PRINT_STACKTRACE = Arrays.asList( + private static final Set EXCEPTIONS_DO_NOT_PRINT_STACKTRACE = Set.of( "org.acegisecurity.AccessDeniedException", "org.springframework.security.access.AccessDeniedException" );