Without this, I saw:
FAILURE: initializationError(hudson.model.CauseTest)
[INFO] java.lang.Exception: Field j must implement MethodRule
[INFO] at org.junit.runners.BlockJUnit4ClassRunner.validateRuleField(BlockJUnit4ClassRunner.java:188)
[INFO] at org.junit.runners.BlockJUnit4ClassRunner.validateFields(BlockJUnit4ClassRunner.java:183)
[INFO] at org.junit.runners.BlockJUnit4ClassRunner.collectInitializationErrors(BlockJUnit4ClassRunner.java:123)
[INFO] at org.junit.runners.ParentRunner.validate(ParentRunner.java:269)
[INFO] at org.junit.runners.ParentRunner.<init>(ParentRunner.java:66)
[INFO] at org.junit.runners.BlockJUnit4ClassRunner.<init>(BlockJUnit4ClassRunner.java:58)
[INFO] at org.junit.internal.builders.JUnit4Builder.runnerForClass(JUnit4Builder.java:13)
[INFO] at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:57)
[INFO] at org.junit.internal.builders.AllDefaultPossibilitiesBuilder.runnerForClass(AllDefaultPossibilitiesBuilder.java:29)
[INFO] at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:57)
[INFO] at org.junit.internal.requests.ClassRequest.getRunner(ClassRequest.java:24)
[INFO] at junit.framework.JUnit4TestAdapter.<init>(JUnit4TestAdapter.java:31)
[INFO] at junit.framework.JUnit4TestAdapter.<init>(JUnit4TestAdapter.java:24)
[INFO] at com.sun.maven.junit.LocalTestCaseRunner.buildMethodTestCase(LocalTestCaseRunner.java:121)
[INFO] at com.sun.maven.junit.LocalTestCaseRunner.buildTestCase(LocalTestCaseRunner.java:83)
[INFO] at com.sun.maven.junit.LocalTestCaseRunner.runTestCase(LocalTestCaseRunner.java:62)
[INFO] at com.sun.maven.junit.LocalTestCaseRunner.runTestCase(LocalTestCaseRunner.java:58)
[INFO] at sun.reflect.GeneratedMethodAccessor334.invoke(Unknown Source)
[INFO] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
[INFO] at java.lang.reflect.Method.invoke(Method.java:597)
[INFO] at hudson.remoting.RemoteInvocationHandler$RPCRequest.perform(RemoteInvocationHandler.java:274)
[INFO] at hudson.remoting.RemoteInvocationHandler$RPCRequest.call(RemoteInvocationHandler.java:255)
[INFO] at hudson.remoting.RemoteInvocationHandler$RPCRequest.call(RemoteInvocationHandler.java:215)
[INFO] at hudson.remoting.UserRequest.perform(UserRequest.java:118)
[INFO] at hudson.remoting.UserRequest.perform(UserRequest.java:48)
[INFO] at hudson.remoting.Request$2.run(Request.java:270)
[INFO] at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:441)
[INFO] at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)
[INFO] at java.util.concurrent.FutureTask.run(FutureTask.java:138)
[INFO] at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
[INFO] at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
[INFO] at java.lang.Thread.run(Thread.java:662)
The motivation of this is to enable test code to inject components from Jenkins, which means we need a single Injector that can see all of those, including @TestExtension and regular @Extension. Then I realized that the current implementation is broken, as it creates two independent Injectors. This has other undesirable side effects like @TestExtension components not being able to inject @Extensions, etc.
I briefly experimented with hierarchical Injectors (where we first create Injector that loads @Extension then create another that loads @TestExtension as a child), but this was hard to get right as we have no control over which ExtensionFinder gets instantiated first --- we'd be at the mercy of SezPoz.
So the eventual approach is to allow a single GuiceFinder to recognize multiple annotations. This also works well with our using child injector for installing plugins without restart