I am getting java.lang.ArrayIndexOutOfBoundsException
error in groovy while running below code.
stage('Calculate Opatch size') {
def files = findFiles(glob: '${BuildPathPublishRoot}\\30293915.*.zip')
echo """${files[0].length}"""
}
Below is the log:
java.lang.ArrayIndexOutOfBoundsException: Index 0 out of bounds for length 0
at org.codehaus.groovy.runtime.dgmimpl.arrays.ObjectArrayGetAtMetaMethod.invoke(ObjectArrayGetAtMetaMethod.java:41)
at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:325)
at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1225)
Can someone help me to understand the error and fix it.
CodePudding user response:
The only array index access you do is in files[0]
. As the Exception tells you, your array has the length 0, hence you get the error. Maybe add an empty check before accessing it?
CodePudding user response:
Your findFiles does not return an array, so there is no files[0]!