I have a calculated text field, using this code
This field displays only the first names of the assignees
@Formula:
StringBuilder sb = new StringBuilder();
sb.append("* ");
List people = issue.get("customfield_10427");
if (people == null) {
sb.append(" unassigned ");
return sb.toString();
}
//Count resolved items
for (Object item : people) {
com.atlassian.jira.user.ApplicationUser user = (com.atlassian.jira.user.ApplicationUser) item;
String[] fullName = user.getDisplayName().split(" ", 2);
String firstname = fullName[0];
String surname = fullName[1];
sb.append(firstname).append(" ").append(surname.charAt(0));
sb.append(", ");
}
The problem I have found is that if the assignee in customfield_10427 is departed or inactive, the "com.atlassian.jira.user.ApplicationUser user" returns nothing and this generates an error
Target exception: java.lang.ArrayIndexOutOfBoundsException
How can I test if the list fullName is empty? I have tried various but the script skips over (i.e. doesn't see the list empty) and continues to fail.
Ideally I am trying to achieve the following (but using a method that works)
// Check if details returned are null
if (fullName == null) {
sb.append(" Departed ");
return sb.toString();
}
I have drilled into this a bit more. the issue isn't that the user is deactivated (although the error happens on all deactivated users, this is unrelated) but that user name only has a single name (no forename, surname). As a result, this fails
String[] fullName = user.getDisplayName().split(" ", 2);
String firstname = fullName[0];
String surname = fullName[1];Because there is no second element in the list. I have tried using assert statements to test fullName[1] and I have tried counting the number of elements. Both don't seem to conform to groovy standards and generate syntax errors
Thoughts?