NationalSecurityAgency/ghidra · warning · IllegalArgumentException
String must not begin or end with a comma
Error message
String must not begin or end with a comma
What it means
Thrown by parseIntegerCSV(csv) after trimming, when the string starts or ends with a comma (e.g. ',1,2' or '1,2,'). split(",") on such input would yield an empty leading/trailing element and a confusing NumberFormatException later, so this is caught early with a clear message.
Source
Thrown at Ghidra/Extensions/MachineLearning/src/main/java/ghidra/machinelearning/functionfinding/FunctionStartRFParams.java:220
contextRegisterNames.add(regName);
BigInteger bigInt = new BigInteger(regValPair[1].trim());
contextRegisterVals.add(bigInt);
}
}
/**
* Parses a CSV into a sorted list of distinct integer values (duplicates are ignored). Returns
* an empty list of a parse error is encountered.
* @param csv csv string to parse
* @return sorted list
*/
public static List<Integer> parseIntegerCSV(String csv) {
if (StringUtils.isBlank(csv)) {
throw new IllegalArgumentException("Entry cannot be blank");
}
String trimmed = csv.trim();
if (trimmed.startsWith(",") || trimmed.endsWith(",")) {
throw new IllegalArgumentException("String must not begin or end with a comma");
}
Set<Integer> results = new HashSet<>();
String[] parts = trimmed.split(",");
for (String part : parts) {
Integer i = Integer.decode(part.trim());
if (i < 0) {
throw new IllegalArgumentException(
"Invalid element " + part + " - must be non-negative");
}
results.add(i);
}
return results.stream().sorted().collect(Collectors.toList());
}
/**
* Returns the {@link AddressSet} of function entries in the source program.
* <P>
* NB: Invoke {@link FunctionStartRFParams#computeFuncEntriesAndInteriors} beforeView on GitHub (pinned to d5f144c24d)
Solutions
- Remove leading/trailing commas before submitting: csv.replaceAll("^[,\\s]+|[,\\s]+$", "").
- Build the CSV from non-empty tokens only (filter blanks before joining).
- Validate in the UI that the field does not begin or end with ','.
Example fix
// before
parseIntegerCSV("1,2,"); // trailing comma -> throws
// after
parseIntegerCSV("1,2"); Defensive patterns
Strategy: validation
Validate before calling
String safe = csv == null ? "" : csv.trim().replaceAll("^[,\\s]+|[,\\s]+$", "");
if (!safe.isEmpty()) {
List<Integer> r = FunctionStartRFParams.parseIntegerCSV(safe);
} Type guard
null
Try / catch
try {
List<Integer> r = FunctionStartRFParams.parseIntegerCSV(csv);
} catch (IllegalArgumentException e) {
if (e.getMessage().contains("begin or end with a comma")) {
List<Integer> r = FunctionStartRFParams.parseIntegerCSV(csv.trim().replaceAll("^[,]+|[,]+$", ""));
} else throw e;
} Prevention
- Strip leading/trailing commas and whitespace before parsing.
- Build CSV with String.join(",", tokens) over a filtered (non-empty) list.
- Validate field boundaries in the UI on loss of focus.
When it happens
Trigger: parseIntegerCSV(",1,2,3"); parseIntegerCSV("1,2,"); a CSV built by joining a list that included an empty/null tail element.
Common situations: Trailing comma from manual entry or from String.join on a list containing an empty string; copy-paste artifacts; UI text field with a stray comma at the cursor.
Related errors
- Error parsing register=value string {part}
- Entry cannot be blank
- Invalid element {part} - must be non-negative
- Register {regName} not found for program {programName}
- Maximum size of test sets must be positive!
AI-assisted analysis of NationalSecurityAgency/ghidra@d5f144c24d (2026-08-14).
Data as JSON: /api/errors/a7438d69c2b8af65.
Report an issue: GitHub.