ExportXMLWordPrintable

    • Type: Bug
    • Resolution: Fixed
    • Priority: Major
    • None
    • Environment:
      Jenkins 2.543.3, aliyun-oss-uploader 1.4

      Description

      When aliyunOSSUpload runs in a Pipeline, Jenkins logs a WARNING "Cannot create control version of class org.jenkinsci.plugins.workflow.steps.CoreStep" with a ClassCastException for maxRetries.

      The upload itself succeeds. The warning comes from the step-argument round trip (DescribableModel.uninstantiate2) that Jenkins performs when it renders the step in the UI.

      Cause

      In OSSPublisher.java the constructor and the getter use different types for the same property:

      @DataBoundConstructor
      public OSSPublisher(String endpoint, String accessKeyId, String accessKeySecret,
              String bucketName, String localPath, String remotePath, String maxRetries)
      
      public int getMaxRetries() {
          return StringUtils.isEmpty(maxRetries) ? 3 : Integer.parseInt(maxRetries);
      }
      

      structs reads the property through the getter (int 3) and then tries to pass it back to the String constructor parameter, which fails. This happens even when maxRetries is not set, because the getter returns the default 3.

      Steps to reproduce

      pipeline {
        agent any
        stages {
          stage('upload') {
            steps {
              writeFile file: 'test.txt', text: 'hello'
              aliyunOSSUpload(
                endpoint: 'oss-example.aliyuncs.com',
                accessKeyId: 'xxx',
                accessKeySecret: 'xxx',
                bucketName: 'example-bucket',
                localPath: '/test.txt',
                remotePath: '/test.txt'
              )
            }
          }
        }
      }
      

      Then check the Jenkins system log.

      Log

      WARNING: Cannot create control version of class org.jenkinsci.plugins.workflow.steps.CoreStep using {delegate=@aliyunOSSUpload$OSSPublisher(...,maxRetries=3,...)}
      java.lang.IllegalArgumentException: Could not instantiate {...} for org.inurl.jenkins.plugin.OSSPublisher: java.lang.ClassCastException: org.inurl.jenkins.plugin.OSSPublisher.maxRetries expects class java.lang.String but received class java.lang.Integer
          at org.jenkinsci.plugins.structs.describable.DescribableModel.instantiate(DescribableModel.java:338)
          at org.jenkinsci.plugins.structs.describable.DescribableModel.uninstantiate2(DescribableModel.java:676)
          at org.jenkinsci.plugins.workflow.actions.ArgumentsAction.resolve(ArgumentsAction.java:306)
          ...
      Caused by: java.lang.ClassCastException: org.inurl.jenkins.plugin.OSSPublisher.maxRetries expects class java.lang.String but received class java.lang.Integer
          at org.jenkinsci.plugins.structs.describable.DescribableModel.coerce(DescribableModel.java:495)
      

      Suggested fix

      Make the getter return the stored String and parse it where the value is used:

      public String getMaxRetries() {
          return maxRetries;
      }
      
      private int maxRetriesAsInt() {
          return StringUtils.isEmpty(maxRetries) ? 3 : Integer.parseInt(maxRetries);
      }
      

            Assignee:
            Tzach Solomon
            Reporter:
            Tzach Solomon
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: