From b0bd44e8e9ec86c8655cd87f81ed62f3bd15cd7c Mon Sep 17 00:00:00 2001 From: Stephen Connolly Date: Tue, 8 Mar 2016 10:26:19 +0000 Subject: [PATCH] Jenkins.getInstance() is safe to assume non-null (x1) - This code path is only ever called after extensions are on the classpath and before termination - The other code path may just possibly be called when `Jenkins.theInstance == null`, for clarification I assert that this can never happen, but as all it does is log the errors in a claimed failed startup I will leave this with just a TODO marker for now --- .../java/hudson/diagnosis/OldDataMonitor.java | 24 +++++++++---------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/core/src/main/java/hudson/diagnosis/OldDataMonitor.java b/core/src/main/java/hudson/diagnosis/OldDataMonitor.java index 510da1aca4..9707822644 100644 --- a/core/src/main/java/hudson/diagnosis/OldDataMonitor.java +++ b/core/src/main/java/hudson/diagnosis/OldDataMonitor.java @@ -105,20 +105,18 @@ public class OldDataMonitor extends AdministrativeMonitor { } private static void remove(Saveable obj, boolean isDelete) { - Jenkins j = Jenkins.getInstanceOrNull(); - if (j != null) { - OldDataMonitor odm = get(j); - SecurityContext oldContext = ACL.impersonate(ACL.SYSTEM); - try { - odm.data.remove(referTo(obj)); - if (isDelete && obj instanceof Job) { - for (Run r : ((Job) obj).getBuilds()) { - odm.data.remove(referTo(r)); - } + Jenkins j = Jenkins.getInstance(); + OldDataMonitor odm = get(j); + SecurityContext oldContext = ACL.impersonate(ACL.SYSTEM); + try { + odm.data.remove(referTo(obj)); + if (isDelete && obj instanceof Job) { + for (Run r : ((Job) obj).getBuilds()) { + odm.data.remove(referTo(r)); } - } finally { - SecurityContextHolder.setContext(oldContext); } + } finally { + SecurityContextHolder.setContext(oldContext); } } @@ -207,7 +205,7 @@ public class OldDataMonitor extends AdministrativeMonitor { } if (buf.length() == 0) return; Jenkins j = Jenkins.getInstanceOrNull(); - if (j == null) { + if (j == null) { // TODO confirm this can never be true // Startup failed, something is very broken, so report what we can. for (Throwable t : errors) { LOGGER.log(Level.WARNING, "could not read " + obj + " (and Jenkins did not start up)", t);