Skip to content
Commit b9bb52ff authored by Baptiste Mathus's avatar Baptiste Mathus
Browse files

Switch Jenkins.getInstance() to @Nonnull (#2297)

As detailed by @stephenc:

> So there is `getInstanceOrNull()` which is for use in Jenkins core or
> in code that plugins add that may escape the Jenkins singleton
> lifecycle.
>
> In regular plugins `getInstance()` will never return null as the
> lifecycle does not instantiate them until after there is a Jenkins
> singleton and the plugins will be stopped before there is no
> singleton.
>
> The `getActiveInstance()` is therefore equivalent to `getInstance()`
> and should never have been born.
>
> The only way a plugin can get a `null` from `Jenkins.getInstance()` is
> if you install an `atExit()` handler, use a `PhantomReference` type
> thing, or directly manipulate the servlet container in some way or
> other. A correctly written plugin should unwind any of those things
> when it is stopped or a method bound to the termination lifecycle. If
> there are some cases (for which I cannot anticipate a good coder being
> able to write a correct termination lifecycle method to fix) where the
> code cannot be unhooked... then in those cases the plugin should use
> `getInstanceOrNull()` and know how to respond to the `null` that could
> not be avoided.
parent 8f436799
Loading
Loading
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment