Unable to resolve class org.apache.commons.fileupload.disk.DiskFileItemFactory

Hi everyone,

after upgrading to 2.462.2 we are experiencing issues with Jenkins Plain Credentials Plugin. I read in the upgrade guide that the Apache Commons FileUpload library was upgraded from 1.5 to 2.0 which means that some of the classes used by FileCredentialsImpl in the credentials plugin like org.apache.commons.fileupload.FileItem or org.apache.commons.fileupload.disk.DiskFileItemFactory cannot be found anymore because they are moved to an other package. FileCredentialsImpl uses org.apache.commons.fileupload.FileItem in it’s constructor.

Are you planning to upgrade the credentials plugin?

As far as all the reports and experience with ci.jenkins.io, the most recent releases of the credentials plugin work very well with Jenkins 2.462.2. You’ll need to provide more details of the failure you’re seeing and the configuration that is showing the failure.

Have you upgraded your plugins? If not, do that and check if the issue is resolved.

Plain credentials plugin 182.v468b_97b_9dcb_8 was released in May 2024 with specific improvements for compatibility with FileUpload 2.

I have the latest version of the plain credentials plugin.

My issue is that the constructor of FileCredentialsImpl expects org.apache.commons.fileupload.disk.DiskFileItem but jenkins is unable to resolve any of the classes from the old package e.g org.apache.commons.fileupload.disk.DiskFileItem.

I can’t duplicate the problem that you’re describing. Steps that I took while trying to duplicate the problem included:

  1. Create a plugins.txt file that defines the plugins being used (contents are below)
  2. Create a run-jenkins.sh file that downloads Jenkins and the requested plugins and runs
  3. Run the run-jenkins.sh file and complete the setup wizard by creating a user and choosing to install no addfitional plugins (since the plugins.txt file provides them all)
  4. Define a new credential that uses a secret file and save it, confirm no errors are reported
  5. Update the secret file credential, save it, and confirm no errors are reported
Contents of plugins.txt file
apache-httpcomponents-client-4-api:4.5.14-208.v438351942757
asm-api:9.7-33.v4d23ef79fcc8
bouncycastle-api:2.30.1.78.1-248.ve27176eb_46cb_
branch-api:2.1178.v969d9eb_c728e
caffeine-api:3.1.8-133.v17b_1ff2e0599
cloudbees-folder:6.951.v5f91d88d76b_b_
credentials:1378.v81ef4269d764
credentials-binding:681.vf91669a_32e45
display-url-api:2.204.vf6fddd8a_8b_e9
durable-task:577.v2a_8a_4b_7c0247
git:5.4.1
git-client:6.0.0
gson-api:2.11.0-41.v019fcf6125dc
instance-identity:185.v303dc7c645f9
ionicons-api:74.v93d5eb_813d5f
jackson2-api:2.17.0-379.v02de8ec9f64c
jakarta-activation-api:2.1.3-1
jakarta-mail-api:2.1.3-1
javax-activation-api:1.2.0-7
jaxb:2.3.9-1
joda-time-api:2.13.0-85.vb_64d1c2921f1
json-api:20240303-41.v94e11e6de726
mailer:472.vf7c289a_4b_420
mina-sshd-api-common:2.13.2-125.v200281b_61d59
mina-sshd-api-core:2.13.2-125.v200281b_61d59
pipeline-build-step:540.vb_e8849e1a_b_d8
pipeline-groovy-lib:730.ve57b_34648c63
pipeline-input-step:495.ve9c153f6067b_
pipeline-milestone-step:119.vdfdc43fc3b_9a_
pipeline-model-api:2.2214.vb_b_34b_2ea_9b_83
pipeline-model-definition:2.2214.vb_b_34b_2ea_9b_83
pipeline-model-extensions:2.2214.vb_b_34b_2ea_9b_83
pipeline-stage-step:312.v8cd10304c27a_
pipeline-stage-tags-metadata:2.2214.vb_b_34b_2ea_9b_83
plain-credentials:183.va_de8f1dd5a_2b_
scm-api:696.v778d637b_a_762
script-security:1362.v67dc1f0e1b_b_3
snakeyaml-api:2.3-123.v13484c65210a_
ssh-credentials:343.v884f71d78167
structs:338.v848422169819
variant:60.v7290fc0eb_b_cd
workflow-aggregator:600.vb_57cdd26fdd7
workflow-api:1336.vee415d95c521
workflow-basic-steps:1058.vcb_fc1e3a_21a_9
workflow-cps:3961.ve48ee2c44a_b_3
workflow-durable-task-step:1371.vb_7cec8f3b_95e
workflow-job:1436.vfa_244484591f
workflow-multibranch:795.ve0cb_1f45ca_9a_
workflow-scm-step:427.v4ca_6512e7df1
workflow-step-api:678.v3ee58b_469476
workflow-support:920.v59f71ce16f04
Contents of run-jenkins.sh
#!/bin/bash

JENKINS_WAR_VERSION=2.477
JENKINS_WAR=jenkins-{JENKINS_WAR_VERSION}.war PLUGIN_MANAGER_VERSION=2.13.0 PLUGIN_MANAGER_JAR=jenkins-plugin-manager-{PLUGIN_MANAGER_VERSION}.jar

if [ ! -f …/PLUGIN_MANAGER_JAR ]; then wget https://github.com/jenkinsci/plugin-installation-manager-tool/releases/download/{PLUGIN_MANAGER_VERSION}/$PLUGIN_MANAGER_JAR
mv $PLUGIN_MANAGER_JAR …
fi
if [ ! -d plugins ]; then
mkdir plugins
fi
java -jar …/$PLUGIN_MANAGER_JAR --jenkins-version $JENKINS_WAR_VERSION --latest false --plugin-download-directory plugins --plugin-file plugins.txt

if [ ! -f …/JENKINS_WAR ]; then wget https://get.jenkins.io/war/{JENKINS_WAR_VERSION}/jenkins.war
mv jenkins*.war …/$JENKINS_WAR
fi

JENKINS_HOME=. java -jar …/$JENKINS_WAR

Sorry, I forgot to mention that I’m executing a system groovy script where I’m importing the classes from the libraries and adding the credentials programmatically. So I’m not using the UI to add the credentials.

I’m using FileCredentialsImpl class where the 4th parameter in the constructor has the type org.apache.commons.fileupload.FileItem but this class cannot be resolved by Jenkins anymore. So I was wondering if you will also update FileCredentialsImpl to use org.apache.commons.fileupload2.core.FileItem instead.

def credential = new FileCredentialsImpl(CredentialsScope.GLOBAL, id, description, fileItem, filename, data)

I have no issues when I use the UI to add credentials.

It looks like you’re using the constructor from the plain credentials plugin that is intended for use by Stapler. I think that you’ll need to use the constructor that is intended for use by all the other cases.

Refer to the plugin Javadoc for more detail.

Thank you for your help! You are absolutely right. Our implementation is using the wrong constructor. I have changed it now and it works.