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:
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:
If you simply make the below change, it will start working:
As a side note, if you go the scriptApproval page, you will not see any signature for String.length that needs be approved.