- Code that is running from a plugin and on the master's JVM is guaranteed to never get null from this method (any cases where you do get null are bugs in core)
- Code that is running from a plugin and on a remote JVM should never be allowed to load the Jenkins class in their classloader, so should never use Jenkins.getInstance()... we are annotating the method with @Nullable so that such code can have some evolution time
- Code that is running in core and on one of two special paths should use the Jenkins.getInstanceOrNull() method so that the UI can be presented to users before the singleton has been instantiated / after the singleton has been destroyed
- The remaining 95% of uses in core (and 100% of uses in plugins) can safely assume that the instance is never null
This reverts commit bb7c8fcedb.
Closes#2090, I'll redo this as a PR... though if that PR is subject to multiple rounds of review before being merged then I will take that of evidence of the exact problem that committing directly was supposed to resolve... namely exponentially multiplying the effort required to make actual improvements to the code base.
- Only ever called after extensions are on the classpath and before termination
- If it were somehow or other called after `Jenkins.theInstance == null` then at that point the queue has already been persisted so the trigger could have no effect anyway... much better to surface in the shutdown logs about the missed trigger than either return false or incorrectly report the job as triggered
- Only ever called after extensions are on the classpath and before termination
- Noting that the one valid check for null should actually be using a guard on extensions being available and not a check for null
- Plugins using these methods will be safe
- The code path I need to analyse is the `Jenkins.super()` constructor code path. As Jenkins extends AbstractCIBase if there is a call there that requires the queue lock during construction it may require these methods to be safe against being called before the singleton has been put in place
- But the type of tests here would be very restricted in what they could safely do anyway, so they would largely be restricted to verifying data migration during xml loading
- Only ever called after extensions are on the classpath while performing initialization and during termination before `Jenkins.theInstance` is set to `null`
- 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