Reflection API - a weird test failure while bumping pom to next LTS

72 views
Skip to first unread message

Radek Antoniuk

unread,
Jun 13, 2025, 6:19:21 AMJun 13
to Jenkins Developers
I'm updating the jira-plugin to the next LTS and one test suddenly started failing with:

Found no instances of hudson.model.Job$BuildNumberAssigner registered
java.lang.IllegalStateException
 at hudson.ExtensionList.lookupFirst(ExtensionList.java:482)
 at hudson.model.Job.assignBuildNumber(Job.java:345)
 at hudson.model.Run.<init>(Run.java:324)
 at org.jenkinsci.plugins.workflow.job.WorkflowRun.<init>(WorkflowRun.java:250)
 at hudson.plugins.jira.UpdaterTest.getChangesUsingReflectionForWorkflowJob(UpdaterTest.java:313)
 at java.base/java.lang.reflect.Method.invoke(Method.java:569)
 at java.base/java.util.ArrayList.forEach(ArrayList.java:1511)
 at java.base/java.util.ArrayList.forEach(ArrayList.java:1511)

Test:

I tried to find any changes around Reflection API but I don't see anything and just wanted to make sure this a test/mock problem or an issue somewhere else.

Thanks,
Radek

Vincent Latombe

unread,
Jun 13, 2025, 6:28:14 AMJun 13
to jenkin...@googlegroups.com
You need a valid Jenkins context to use this class. Simply removing @WithoutJenkins annotation from the test method should fix it.

Vincent


--
You received this message because you are subscribed to the Google Groups "Jenkins Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jenkinsci-de...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/jenkinsci-dev/9420553c-aaa6-45b6-b493-54e473b9e3ffn%40googlegroups.com.

Jesse Glick

unread,
Jun 16, 2025, 5:47:04 PMJun 16
to jenkin...@googlegroups.com
In general, if you use Mockito in Jenkins tests, you should expect to be forced to edit existing test suites after even compatible changes to core or plugin dependencies. It is safer to divide test code into true unit tests (no mocking framework) plus proper integration tests with `JenkinsRule` or one of its variants.

Radek Antoniuk

unread,
Jun 17, 2025, 10:57:31 AMJun 17
to jenkin...@googlegroups.com
In general, if you use Mockito in Jenkins tests, you should expect to be forced to edit existing test suites after even compatible changes to core or plugin dependencies. 
 
That's fine, I was just making sure in this specific case this isn't something that slipped through the core tests.
 
It is safer to divide test code into true unit tests (no mocking framework) plus proper integration tests with `JenkinsRule` or one of its variants.
 
By the variants you mean @WithJenkins @WithoutJenkins, right? I'm guessing this is purely logistical/logical suggestion to quickly catch issues like that - but indeed, that's a good one.
 
You need a valid Jenkins context to use this class. Simply removing @WithoutJenkins annotation from the test method should fix it.
 
That's exactly what I was curious and sent that email - why did it work before (so didn't need the instance) and suddenly it's needed after bumping the LTS.
 
Thinking about it, if I would set up an alternate branch that would automatically bump BOM and Jenkins parent version continuously, then it could catch and pinpoint it to a specific change.
 
Anyway, thanks guys!

Radek
On 16 Jun 2025 at 23:47 +0200, 'Jesse Glick' via Jenkins Developers <jenkin...@googlegroups.com>, wrote:
In general, if you use Mockito in Jenkins tests, you should expect to be forced to edit existing test suites after even compatible changes to core or plugin dependencies. It is safer to divide test code into true unit tests (no mocking framework) plus proper integration tests with `JenkinsRule` or one of its variants.

--
You received this message because you are subscribed to a topic in the Google Groups "Jenkins Developers" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/jenkinsci-dev/nE3hFK8WV34/unsubscribe.
To unsubscribe from this group and all its topics, send an email to jenkinsci-de...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/jenkinsci-dev/CANfRfr1%2B9FKeeaP1LmyaFt%3DL%2BijdNOEjS0Yp3SdMMyUujXLM6w%40mail.gmail.com.

Jesse Glick

unread,
Jun 17, 2025, 1:30:02 PMJun 17
to jenkin...@googlegroups.com
On Tue, Jun 17, 2025 at 10:57 AM Radek Antoniuk <radek.a...@gmail.com> wrote:
proper integration tests with `JenkinsRule` or one of its variants.
 
By the variants you mean @WithJenkins @WithoutJenkins, right?

I actually meant `JenkinsSessionRule` and `RealJenkinsRule`. `@WithJenkins` is I guess the JUnit 5 version of `JenkinsRule`. `@WithoutJenkins` just turns off `JenkinsRule` for one test method; arguably clearer to use `JenkinsSessionRule`, in which case some methods may simply decline to start Jenkins even once. 

Vincent Latombe

unread,
Jun 20, 2025, 4:36:28 AMJun 20
to jenkin...@googlegroups.com
> and suddenly it's needed after bumping the LTS.

The implementation changed and now it relies on having a valid Jenkins context as it relies on resolving implementation of an extension point (wasn't the case before).

Vincent


--
You received this message because you are subscribed to the Google Groups "Jenkins Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jenkinsci-de...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/jenkinsci-dev/CANfRfr2%3D%2BkSy1SZZP8kMOuuUNm5hubRT7CgPZFLZRfZ5PyfKog%40mail.gmail.com.

Radek Antoniuk

unread,
Jun 21, 2025, 10:04:25 AMJun 21
to jenkin...@googlegroups.com
Thanks Vincent, that was exactly the confirmation I wanted that this was intentional but I couldn’t find it in the release notes.  
 
Appreciate it! 
You received this message because you are subscribed to a topic in the Google Groups "Jenkins Developers" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/jenkinsci-dev/nE3hFK8WV34/unsubscribe.
To unsubscribe from this group and all its topics, send an email to jenkinsci-de...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/jenkinsci-dev/CAH-zGCi7sSrVhG0_j02OFQTgczMP6vwZeh8iTuGpJ5gELF4dNA%40mail.gmail.com.

Jesse Glick

unread,
Jun 23, 2025, 5:41:20 PMJun 23
to jenkin...@googlegroups.com
On Sat, Jun 21, 2025 at 10:04 AM Radek Antoniuk <radek.a...@gmail.com> wrote:
this was intentional but I couldn’t find it in the release notes

Because this was an internal change. If you are using Mockito in tests, you are in general going to need to be constantly adjusting your tests according to implementation changes in dependencies, and you will need to read diffs to do that, not release notes.
Reply all
Reply to author
Forward
0 new messages