jenkinsci / jenkinsci/gitlab-branch-source-plugin
Jersey3 class cast exception on checkout
- Dominant language
- Java
- Stars
- 134
- Forks
- 113
- PR merge metrics
- No merged PRs in 30d
Description
### Jenkins and plugins versions report
Environment
```text
Jenkins: 2.576
OS: Linux - 5.15.0-190-generic
Java: 21.0.11 - Ubuntu (OpenJDK 64-Bit Server VM)
---
ansicolor:542.v03d235fee02d
ant:520.vd082ecfb_16a_9
antisamy-markup-formatter:173.v680e3a_b_69ff3
apache-httpcomponents-client-4-api:4.5.14-269.vfa_2321039a_83
apache-httpcomponents-client-5-api:5.6.4-204.vfa_29df89ffcf
asm-api:9.10.1-216.va_9256d3b_844b_
audit-trail:456.v39d2fd1ed556
authentication-tokens:1.144.v5ff4a_5ec5c33
blueocean:1.27.26
blueocean-autofavorite:1.2.5
blueocean-bitbucket-pipeline:1.27.26
blueocean-commons:1.27.26
blueocean-config:1.27.26
blueocean-core-js:1.27.26
blueocean-dashboard:1.27.26
blueocean-display-url:2.4.4
blueocean-events:1.27.26
blueocean-git-pipeline:1.27.26
blueocean-github-pipeline:1.27.26
blueocean-i18n:1.27.26
blueocean-jira:1.27.26
blueocean-jwt:1.27.26
blueocean-personalization:1.27.26
blueocean-pipeline-api-impl:1.27.26
blueocean-pipeline-editor:1.27.26
blueocean-pipeline-scm-api:1.27.26
blueocean-rest:1.27.26
blueocean-rest-impl:1.27.26
blueocean-web:1.27.26
bootstrap5-api:5.3.8-1048.va_c299057e35c
bouncycastle-api:2.30.1.84-291.v9f17b_21896e2
branch-api:2.1280.v0d4e5b_b_460ef
build-pipeline-plugin:2.2.0
build-timeout:1.41
caffeine-api:3.2.4-208.v7e2da_a_7db_82b_
checks-api:415.vf022234a_931d
cloudbees-bitbucket-branch-source:937.3.9
cloudbees-disk-usage-simple:275.v56e74c9dd0d3
cloudbees-folder:6.1106.v3a_d9a_6d2465e
command-launcher:134.v025a_5fcf9dea_
commons-collections4-api:4.5.0-8.va_d5448ef9011
commons-compress-api:1.28.0-87.v48a_8104cb_b_25
commons-lang3-api:3.20.0-109.ve43756e2d2b_4
commons-text-api:1.15.0-218.va_61573470393
conditional-buildstep:1.5.0
copyartifact:795.ve8e151429b_27
credentials:1511.v2e3cb_0008ef0
credentials-binding:728.v902a_273b_8947
dashboard-view:2.558.v96b_901978e47
data-tables-api:2.3.8-1570.v1cb_1cd2a_0fb_c
display-url-api:2.217.va_6b_de84cc74b_
docker-commons:477.v289085a_b_6896
docker-workflow:653.v2f2c08eff0ec
dtkit-api:3.0.3
durable-task:686.v80ff80875b_82
echarts-api:6.1.0-1306.vcee1648c16a_4
eddsa-api:0.3.0.1-29.v67e9a_1c969b_b_
email-ext:2038.v7b_8817a_499d9
extended-read-permission:92.v1b_f0c20b_75db_
external-monitor-job:223.vb_fddcf42c9b_3
extra-columns:1.29
favorite:2.267.vb_90d08408081
font-awesome-api:7.3.1-1013.v0835a_879ec6d
generic-webhook-trigger:2.4.2
git:5.10.1
git-client:6.6.1
git-server:137.ve0060b_432302
github:1.47.0
github-api:1.330-492.v3941a_032db_2a_
github-branch-source:1983.vfa_27ed961853
gitlab-api:6.3.0-126.vd066b_d896159
gitlab-branch-source:743.ve0c8154a_8da_b_
gitlab-plugin:1.9.16
gradle:2.19.1252.v15196b_5a_6e10
gson-api:2.14.0-201.v8eefe5515533
handy-uri-templates-2-api:2.1.8-38.vcea_5d521d5f3
htmlpublisher:429
instance-identity:203.v15e81a_1b_7a_38
ionicons-api:94.vcc3065403257
jackson-annotations2-api:2.22-19.v10a_a_582ea_26e
jackson2-api:2.22.2-445.vdc613f1d8012
jackson3-api:3.2.2-96.v599957900a_1a_
jakarta-activation-api:2.1.4-1
jakarta-mail-api:2.1.5-1
jakarta-xml-bind-api:4.0.9-19.v2b_a_5b_44d9a_1c
javadoc:354.vee1a_660b_4990
javax-activation-api:1.2.0-8
javax-mail-api:1.6.2-11
jaxb:2.3.9-143.v5979df3304e6
jdk-tool:83.v417146707a_3d
jenkins-design-language:1.27.26
jersey2-api:2.48-180.ve47b_264f849b_
jersey3-api:3.1.11-4.v77818819c2e1
jira:3.22
jjwt-api:0.13.0-141.vd58b_a_9592b_6c
jnr-posix-api:3.2.2-218.vd6064f4fa_0a_d
jobConfigHistory:1367.vc8fa_b_15101dc
joda-time-api:2.14.3-200.v65623733c99f
jquery:1.12.4-3
jquery3-api:3.7.1-687.v68d468e40b_30
jsch:0.2.16-95.v3eecb_55fa_b_78
json-api:20260814-226.v20f9685d642c
json-path-api:3.0.0-218.vcd4dd1355de2
jsoup:1.23.1-103.v4fde9422cc6f
junit:1424.vc64a_edde7777
ldap:807.809.vd3a_4e5e4ec98
locale:641.v84f22d75fd8b_
lockable-resources:1539.v4db_b_fc1cc115
log-parser:3.0.5
mailer:534.v1b_36f5864073
mapdb-api:1.0.9-44.va_1e1310c9118
matrix-auth:3.3
matrix-project:917.v22eda_817646e
maven-plugin:3.27
mercurial:1323.ve69d2a_db_8a_b_d
metrics:4.2.37-494.v06f9a_939d33a_
mina-sshd-api-common:2.19.0-192.v2b_a_7b_2c1dc71
mina-sshd-api-core:2.19.0-192.v2b_a_7b_2c1dc71
monitoring:2.8.0
okhttp-api:5.3.2-200.vedb_720a_cf1f8
oss-symbols-api:465.v25d9fdc88c26
pam-auth:1.12
parameterized-trigger:893.va_383a_9b_a_4c11
pipeline-agent-build-history:155.va_000e6b_77c81
pipeline-build-step:599.v4b_67ea_11b_152
pipeline-github-lib:65.v203688e7727e
pipeline-graph-analysis:254.v0f63a_a_447dca_
pipeline-graph-view:998.vc30deece0e36
pipeline-groovy-lib:798.v5cc688825312
pipeline-input-step:560.v56198a_642157
pipeline-milestone-step:152.v6e22b_8cfc66c
pipeline-model-api:2.2293.v6e7193cec599
pipeline-model-definition:2.2293.v6e7193cec599
pipeline-model-extensions:2.2293.v6e7193cec599
pipeline-rest-api:2.41
pipeline-stage-step:345.va_96187909426
pipeline-stage-tags-metadata:2.2293.v6e7193cec599
pipeline-stage-view:2.41
pipeline-utility-steps:3.810.va_7672d206740
plain-credentials:199.v9f8e1f741799
plugin-util-api:7.1341.v039f146993d9
prism-api:1.30.0-741.v034eb_0b_0a_a_fa_
pubsub-light:1.19
resource-disposer:0.25
role-strategy:898.vc050ed2424ca_
run-condition:276.v97298f3a_cd51
scm-api:728.vc30dcf7a_0df5
script-security:1412.v7737b_3405f86
slave-setup:147.vcd1728908670
snakeyaml-api:2.5-149.v72471e9c6371
snakeyaml-engine-api:3.1.1-12.v4320c7d6f89c
sse-gateway:1.29
ssh-credentials:372.va_250881b_08cd
ssh-slaves:3.1097.v868116049892
ssh-steps:2.0.92.vb_a_0583935f9b_
sshd:3.384.vc89b_5e138cf9
structs:362.va_b_695ef4fdf9
subversion:1303.vcfd9679fb_c12
timestamper:1.30
token-macro:477.vd4f0dc3cb_cf1
trilead-api:2.284.v1974ea_324382
variant:70.va_d9f17f859e0
view-job-filters:408.vb_ca_5e798e5b_5
woodstox-core-api:7.2.2-10.vcb_629759b_2c2
workflow-aggregator:608.v67378e9d3db_1
workflow-api:1413.v2ff1a_5e720fa_
workflow-basic-steps:1098.v808b_fd7f8cf4
workflow-cps:4370.v49a_6937566b_6
workflow-durable-task-step:1479.v56e587f413a_7
workflow-job:1590.v49101d088542
workflow-multibranch:841.vec5b_9e1806ec
workflow-scm-step:466.va_d69e602552b_
workflow-step-api:724.v538c2362b_dfb_
workflow-support:1015.v785e5a_b_b_8b_22
ws-cleanup:0.49
xunit:3.1.7
```
### What Operating System are you using (both controller, and any agents involved in the problem)?
Linux controller, Windows agents
### Reproduction steps
1. Update to Jenkins 2.576 and gitlab-branch-source-plugin 743.ve0c8154a_8da_b_
2. Set up multibranch pipeline including scm checkout step
3. push to source GitLab project
4. Error appears on only some jenkins runs (even within same pipeline)
### Expected Results
Gitlab project is successfully checked out and pipeline continues
### Actual Results
Most of the time, the scm checkout works as expected. But several times a day, the following error message occurs and the pipeline fails:
```
Querying the current revision of branch main...
12:03:16 java.lang.ClassCastException: Cannot cast org.glassfish.jersey.inject.hk2.Hk2InjectionManagerFactory to org.glassfish.jersey.internal.inject.InjectionManagerFactory
12:03:16 at java.base/java.lang.Class.cast(Class.java:4069)
12:03:16 at PluginClassLoader for jersey3-api//org.glassfish.jersey.internal.ServiceFinder$LazyObjectIterator.hasNext(ServiceFinder.java:692)
12:03:16 at PluginClassLoader for jersey3-api//org.glassfish.jersey.internal.inject.Injections.lookupService(Injections.java:101)
12:03:16 at PluginClassLoader for jersey3-api//org.glassfish.jersey.internal.inject.Injections.lookupInjectionManagerFactory(Injections.java:85)
12:03:16 at PluginClassLoader for jersey3-api//org.glassfish.jersey.internal.inject.Injections.createInjectionManager(Injections.java:56)
12:03:16 at PluginClassLoader for jersey3-api//org.glassfish.jersey.client.ClientConfig$State.findInjectionManager(ClientConfig.java:482)
12:03:16 at PluginClassLoader for jersey3-api//org.glassfish.jersey.client.ClientConfig$State.initRuntime(ClientConfig.java:419)
12:03:16 at PluginClassLoader for jersey3-api//org.glassfish.jersey.internal.util.collection.Values$LazyValueImpl.get(Values.java:321)
12:03:16 at PluginClassLoader for jersey3-api//org.glassfish.jersey.client.ClientConfig.getRuntime(ClientConfig.java:834)
12:03:16 at PluginClassLoader for jersey3-api//org.glassfish.jersey.client.ClientRequest.getClientRuntime(ClientRequest.java:188)
12:03:16 at PluginClassLoader for jersey3-api//org.glassfish.jersey.client.JerseyWebTarget.onBuilder(JerseyWebTarget.java:371)
12:03:16 at PluginClassLoader for jersey3-api//org.glassfish.jersey.client.JerseyWebTarget.request(JerseyWebTarget.java:199)
12:03:16 at PluginClassLoader for jersey3-api//org.glassfish.jersey.client.JerseyWebTarget.request(JerseyWebTarget.java:38)
12:03:16 at PluginClassLoader for gitlab-api//org.gitlab4j.api.GitLabApiClient.invocation(GitLabApiClient.java:863)
12:03:16 at PluginClassLoader for gitlab-api//org.gitlab4j.api.GitLabApiClient.invocation(GitLabApiClient.java:827)
12:03:16 at PluginClassLoader for gitlab-api//org.gitlab4j.api.GitLabApiClient.get(GitLabApiClient.java:427)
12:03:16 at PluginClassLoader for gitlab-api//org.gitlab4j.api.GitLabApiClient.get(GitLabApiClient.java:415)
12:03:16 at PluginClassLoader for gitlab-api//org.gitlab4j.api.AbstractApi.get(AbstractApi.java:262)
12:03:16 Caused: org.gitlab4j.api.GitLabApiException: Cannot cast org.glassfish.jersey.inject.hk2.Hk2InjectionManagerFactory to org.glassfish.jersey.internal.inject.InjectionManagerFactory
12:03:16 at PluginClassLoader for gitlab-api//org.gitlab4j.api.AbstractApi.handle(AbstractApi.java:806)
12:03:16 at PluginClassLoader for gitlab-api//org.gitlab4j.api.AbstractApi.get(AbstractApi.java:264)
12:03:16 at PluginClassLoader for gitlab-api//org.gitlab4j.api.RepositoryApi.getBranch(RepositoryApi.java:115)
12:03:16 at PluginClassLoader for gitlab-branch-source//io.jenkins.plugins.gitlabbranchsource.GitLabSCMSource.retrieve(GitLabSCMSource.java:368)
12:03:16 Caused: java.io.IOException: Failed to retrieve the SCM revision for main
12:03:16 at PluginClassLoader for gitlab-branch-source//io.jenkins.plugins.gitlabbranchsource.GitLabSCMSource.retrieve(GitLabSCMSource.java:412)
12:03:16 at PluginClassLoader for scm-api//jenkins.scm.api.SCMSource.fetch(SCMSource.java:577)
12:03:16 at PluginClassLoader for workflow-multibranch//org.jenkinsci.plugins.workflow.multibranch.SCMBinder.create(SCMBinder.java:104)
12:03:16 at PluginClassLoader for workflow-job//org.jenkinsci.plugins.workflow.job.WorkflowRun.run(WorkflowRun.java:342)
12:03:16 at hudson.model.ResourceController.execute(ResourceController.java:97)
12:03:16 at hudson.model.Executor.run(Executor.java:456)
12:03:16 Finished: FAILURE
```
### Anything else?
Seems to be the same or similar issue to #195, #169, #151. However, this time the dependency is on jersey3 rather than jersey2. Additionally, the artifactory plugin is not installed.
The gitlab-plugin and gitlab-branch-source plugins appear to be the only plugins installed with a jersey3 dependency. The maven manifest lists the same jersey3 dependency.
The JIRA plugin has a jersey2 dependency, but is disabled.
This error did not occur before upgrading to Jenkins 2.576 and gitlab-branch-source-plugin 743.ve0c8154a_8da_b_
### Are you interested in contributing a fix?
_No response_
Contributor guide
Research direction
Start with io.jenkins.plugins.gitlabbranchsource.GitLabSCMSource.retrieve and the gitlab-api call to RepositoryApi.getBranch shown in the stack trace. Reproduce the intermittent checkout failure after the Jenkins and gitlab-branch-source upgrades, then inspect the jersey3 dependency and plugin class-loading setup. Done means multibranch SCM revision retrieval and checkout complete without the ClassCastException.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- api, backend
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Active
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100