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
This commit is contained in:
Stephen Connolly committed 2016-03-08 10:26:19 +00:00
1 parent 2f70b2fe8b
commit b0bd44e8e9
1 file changed
+11 -13
@@ -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);