From f9fef613ce1e096a930f2b8d1c143d9764c5f3e7 Mon Sep 17 00:00:00 2001 From: Vincent Latombe Date: Thu, 19 Sep 2024 10:47:42 +0200 Subject: [PATCH] Clean up a few plain `e.printStackTrace()` calls (#9742) Co-authored-by: Jesse Glick --- .../hudson/lifecycle/WindowsInstallerLink.java | 4 ++-- core/src/main/java/hudson/model/AbstractItem.java | 2 +- core/src/main/java/hudson/model/ViewJob.java | 15 ++++++++++++--- core/src/main/java/jenkins/model/Jenkins.java | 2 +- 4 files changed, 16 insertions(+), 7 deletions(-) diff --git a/core/src/main/java/hudson/lifecycle/WindowsInstallerLink.java b/core/src/main/java/hudson/lifecycle/WindowsInstallerLink.java index c54a90d1c5..af0ddf9a6e 100644 --- a/core/src/main/java/hudson/lifecycle/WindowsInstallerLink.java +++ b/core/src/main/java/hudson/lifecycle/WindowsInstallerLink.java @@ -226,7 +226,7 @@ public class WindowsInstallerLink extends ManagementLink { new File(installationDir, "jenkins.exe"), "start", task, installationDir); task.getLogger().println(r == 0 ? "Successfully started" : "start service failed. Exit code=" + r); } catch (IOException | InterruptedException e) { - e.printStackTrace(); + LOGGER.log(Level.WARNING, null, e); } } @@ -241,7 +241,7 @@ public class WindowsInstallerLink extends ManagementLink { Jenkins.get().cleanUp(); System.exit(0); } catch (InterruptedException e) { - e.printStackTrace(); + LOGGER.log(Level.SEVERE, null, e); } } }.start(); diff --git a/core/src/main/java/hudson/model/AbstractItem.java b/core/src/main/java/hudson/model/AbstractItem.java index 0e712d8a2e..8ba7aafe15 100644 --- a/core/src/main/java/hudson/model/AbstractItem.java +++ b/core/src/main/java/hudson/model/AbstractItem.java @@ -434,7 +434,7 @@ public abstract class AbstractItem extends Actionable implements Loadable, Item, Util.deleteRecursive(oldRoot); } catch (IOException e) { // but ignore the error, since we expect that - e.printStackTrace(); + LOGGER.log(Level.WARNING, "Ignoring IOException while deleting", e); } } diff --git a/core/src/main/java/hudson/model/ViewJob.java b/core/src/main/java/hudson/model/ViewJob.java index 055b98cafd..c030fea012 100644 --- a/core/src/main/java/hudson/model/ViewJob.java +++ b/core/src/main/java/hudson/model/ViewJob.java @@ -236,14 +236,23 @@ public abstract class ViewJob, RunT extends Run @Override public void run() { while (!terminating()) { + String jobName = null; try { - getNext()._reload(); + var next = getNext(); + jobName = next.getFullName(); + next._reload(); + jobName = null; } catch (InterruptedException e) { // treat this as a death signal return; - } catch (Throwable t) { + } catch (Exception e) { // otherwise ignore any error - t.printStackTrace(); + if (jobName != null) { + var finalJobName = jobName; + LOGGER.log(Level.WARNING, e, () -> "Failed to reload job " + finalJobName); + } else { + LOGGER.log(Level.WARNING, e, () -> "Failed to obtain next job in the reload queue"); + } } } } diff --git a/core/src/main/java/jenkins/model/Jenkins.java b/core/src/main/java/jenkins/model/Jenkins.java index 9af524b6b1..705044cd8f 100644 --- a/core/src/main/java/jenkins/model/Jenkins.java +++ b/core/src/main/java/jenkins/model/Jenkins.java @@ -5631,7 +5631,7 @@ public class Jenkins extends AbstractCIBase implements DirectlyModifiableTopLeve if (is != null) props.load(is); } catch (IOException e) { - e.printStackTrace(); // if the version properties is missing, that's OK. + LOGGER.log(Level.WARNING, e, () -> "Failed to load jenkins-version.properties"); } String ver = props.getProperty("version"); if (ver == null) ver = UNCOMPUTED_VERSION;