{"record":{"id":"25ed088af7de65a8","repo":"NationalSecurityAgency/ghidra","slug":"bad-category-tag","errorCode":null,"errorMessage":"Bad category tag","messagePattern":"Bad category tag","errorType":"exception","errorClass":"LSHException","httpStatus":null,"severity":"error","filePath":"Ghidra/Features/BSim/src/main/java/ghidra/features/bsim/query/description/CategoryRecord.java","lineNumber":84,"sourceCode":"\t\tif (arg0.category==null)\n\t\t\treturn 1;\t\t// this comes after null\n\t\treturn category.compareTo(arg0.category);\n\t}\n\n\tpublic void saveXml(Writer fwrite) throws IOException {\n\t\tfwrite.append(\"  <category type=\\\"\");\n\t\tfwrite.append(type);\n\t\tfwrite.append(\"\\\">\");\n\t\tSpecXmlUtils.xmlEscapeWriter(fwrite, category);\n\t\tfwrite.append(\"</category>\\n\");\t\t\n\t}\n\t\n\tpublic static CategoryRecord restoreXml(XmlPullParser parser) throws LSHException {\n\t\tXmlElement el = parser.start(\"category\");\n\t\tString type = el.getAttribute(\"type\");\n\t\tString category = parser.end().getText();\n\t\tif (type==null || category==null)\n\t\t\tthrow new LSHException(\"Bad category tag\");\n\t\treturn new CategoryRecord(type,category);\n\t}\n\t\n\tpublic static boolean enforceTypeCharacters(String val) {\n\t\tif (val==null) return false;\n\t\tif (val.length()==0) return false;\n\t\tfor(int i=0;i<val.length();++i) {\n\t\t\tchar c = val.charAt(i);\n\t\t\tif (!Character.isLetterOrDigit(c)&&(c!=' ')&&(c!='.')&&(c!='_')&&(c!=':')&&(c!='/')&&(c!='(')&&(c!=')'))\n\t\t\t\treturn false;\n\t\t}\n\t\treturn true;\n\t}\n}\n","sourceCodeStart":66,"sourceCodeEnd":99,"githubUrl":"https://github.com/NationalSecurityAgency/ghidra/blob/d5f144c24d6bc53c9cbf4448c6d11143e7696206/Ghidra/Features/BSim/src/main/java/ghidra/features/bsim/query/description/CategoryRecord.java#L66-L99","documentation":"Thrown by CategoryRecord.restoreXml when parsing a <category> XML element whose type attribute or text content is null. The BSim category record XML format requires both a type attribute and a category value; a missing one means malformed XML, typically from a hand-edited or corrupted BSim metadata export.","triggerScenarios":"Calling CategoryRecord.restoreXml(parser) on an XML stream where a <category> element lacks the type attribute (el.getAttribute(\"type\") returns null) or has no text content (parser.end().getText() returns null). Occurs when importing/restoring a BSim category XML file that is malformed.","commonSituations":"Importing a BSim metadata XML file that was hand-edited and broke the schema. Corrupted XML export. A different tool/version producing category XML without the type attribute. Empty <category></category> elements.","solutions":["Validate the category XML against the expected BSim schema before importing (each <category> must have a non-empty type attribute and text).","Fix the malformed element in the source XML: add the missing type attribute or category text.","Pre-scan the XML and skip/repair elements missing required fields.","Regenerate the XML export from the original source if it is corrupted."],"exampleFix":"// before (malformed XML):\n// <category>somecategory</category>   <!-- missing type attribute -->\n\n// after (well-formed):\n// <category type=\"genre\">somecategory</category>","handlingStrategy":"validation","validationCode":"// Validate each <category> element has type and text before restore.\nXmlElement el = parser.peek();\nString type = el.getAttribute(\"type\");\nif (type == null || type.isEmpty()) {\n    throw new IllegalArgumentException(\"<category> missing type attribute\");\n}","typeGuard":null,"tryCatchPattern":"try {\n    return CategoryRecord.restoreXml(parser);\n} catch (LSHException e) {\n    if (e.getMessage().contains(\"Bad category tag\")) {\n        parser.end(); // skip the malformed element\n        return null; // or a default record\n    }\n    throw e;\n}","preventionTips":["Validate BSim metadata XML against the expected schema before import.","Regenerate corrupted XML exports from the source.","Pre-scan and repair category elements missing required fields."],"tags":["bsim","xml","parsing","category","validation","lsh-exception"],"backgroundTag":null,"analyzedSha":"d5f144c24d6bc53c9cbf4448c6d11143e7696206","analyzedAt":"2026-08-14T01:00:57.564Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}