Uploaded image for project: 'Jenkins'
  1. Jenkins
  2. JENKINS-57342

Java Array .length is incorrectly determined as a call on the array type

    Details

    • Similar Issues:

      Description

      When .length is called on, an array (say, [Ljava.lang.String; ), it is treated as a call on String itself and caused the below error:

      No such field found: field java.lang.String length. Administrators can decide whether to approve or reject this signature. 

       

      The workaround is to convert the array to list and use .size(), but this becomes an ugly workaround if it needs to be converted only for this purpose (i.e., the working type needs to be an array for some reason).

      Here is a sample pipeline code to show this issue in action:

      pipeline {
          agent "any"    stages {
              stage('Init') {
                  steps {
                      script {
                          echo "a b\nb\nc d\n".split("\n").collect {it.split()}.findAll {it.length == 2}
                      }
                  }
              }
          }
      } 

      If you simply make the below change, it will start working:

        echo "a b\nb\nc d\n".split("\n").collect {it.split() as List}.findAll {it.size() == 2} 

      As a side note, if you go the scriptApproval page, you will not see any signature for String.length that needs be approved.

        Attachments

          Activity

          There are no comments yet on this issue.

            People

            • Assignee:
              Unassigned
              Reporter:
              haridsv Hari Dara
            • Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

              • Created:
                Updated: