{"record":{"id":"aa88932350966e54","repo":"NationalSecurityAgency/ghidra","slug":"invalid-element-part-must-be-non-negative","errorCode":null,"errorMessage":"Invalid element {part} - must be non-negative","messagePattern":"Invalid element (.+?) - must be non-negative","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"warning","filePath":"Ghidra/Extensions/MachineLearning/src/main/java/ghidra/machinelearning/functionfinding/FunctionStartRFParams.java","lineNumber":227,"sourceCode":"\t * Parses a CSV into a sorted list of distinct integer values (duplicates are ignored).  Returns\n\t * an empty list of a parse error is encountered.\n\t * @param csv csv string to parse\n\t * @return sorted list  \n\t */\n\tpublic static List<Integer> parseIntegerCSV(String csv) {\n\t\tif (StringUtils.isBlank(csv)) {\n\t\t\tthrow new IllegalArgumentException(\"Entry cannot be blank\");\n\t\t}\n\t\tString trimmed = csv.trim();\n\t\tif (trimmed.startsWith(\",\") || trimmed.endsWith(\",\")) {\n\t\t\tthrow new IllegalArgumentException(\"String must not begin or end with a comma\");\n\t\t}\n\t\tSet<Integer> results = new HashSet<>();\n\t\tString[] parts = trimmed.split(\",\");\n\t\tfor (String part : parts) {\n\t\t\tInteger i = Integer.decode(part.trim());\n\t\t\tif (i < 0) {\n\t\t\t\tthrow new IllegalArgumentException(\n\t\t\t\t\t\"Invalid element \" + part + \" - must be non-negative\");\n\t\t\t}\n\t\t\tresults.add(i);\n\t\t}\n\t\treturn results.stream().sorted().collect(Collectors.toList());\n\t}\n\n\t/**\n\t * Returns the {@link AddressSet} of function entries in the source program.\n\t * <P>\n\t * NB: Invoke {@link FunctionStartRFParams#computeFuncEntriesAndInteriors} before\n\t * invoking this method.\n\t * @return set of entries\n\t */\n\tpublic AddressSet getFuncEntries() {\n\t\treturn funcEntries;\n\t}\n","sourceCodeStart":209,"sourceCodeEnd":245,"githubUrl":"https://github.com/NationalSecurityAgency/ghidra/blob/d5f144c24d6bc53c9cbf4448c6d11143e7696206/Ghidra/Extensions/MachineLearning/src/main/java/ghidra/machinelearning/functionfinding/FunctionStartRFParams.java#L209-L245","documentation":"Thrown by parseIntegerCSV(csv) when an element parses to an Integer (via Integer.decode, so 0x.. / 0.. / decimal) but the value is negative. The method only accepts non-negative integers because they represent byte counts/offsets for feature extraction. Note: a non-numeric element throws NumberFormatException from Integer.decode, not this message.","triggerScenarios":"parseIntegerCSV(\"1,-2,4\"); parseIntegerCSV(\"-1\"); any element that is a valid but negative integer.","commonSituations":"User entering a negative byte offset/count; a config derived from a signed field that went negative; hex like '0xFFFFFFFF' decoded to a negative int.","solutions":["Use only non-negative values (0 and positive integers).","Sanitize/abs the values before parsing if a sign was unintended, or reject negative input in the UI.","Avoid out-of-range hex that Integer.decode maps to negative (use values < 0x80000000)."],"exampleFix":"// before\nparseIntegerCSV(\"1,-2,4\"); // throws\n\n// after\nparseIntegerCSV(\"1,2,4\");","handlingStrategy":"validation","validationCode":"public static boolean allNonNegative(String csv) {\n    for (String part : csv.split(\",\")) {\n        try {\n            if (Integer.decode(part.trim()) < 0) return false;\n        } catch (NumberFormatException e) { return false; }\n    }\n    return true;\n}","typeGuard":"null","tryCatchPattern":"try {\n    List<Integer> r = FunctionStartRFParams.parseIntegerCSV(csv);\n} catch (IllegalArgumentException e) {\n    if (e.getMessage().contains(\"must be non-negative\")) {\n        // reject/abs the offending element and re-prompt\n    } else throw e;\n}","preventionTips":["Constrain numeric input fields to unsigned values in the UI.","Avoid hex values >= 0x80000000 that Integer.decode maps to negative.","Validate each token is a non-negative integer before parsing."],"tags":["machine-learning","validation","config-parsing","function-finder"],"backgroundTag":null,"analyzedSha":"d5f144c24d6bc53c9cbf4448c6d11143e7696206","analyzedAt":"2026-08-14T01:00:57.564Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}