{"record":{"id":"1119cf8c32c1a4a5","repo":"dianping/cat","slug":"invalid-level-1119cf","errorCode":null,"errorMessage":"Invalid level.","messagePattern":"Invalid level\\.","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"cat-core/src/main/java/com/dianping/cat/config/LogLevel.java","lineNumber":43,"sourceCode":"\tERROR(2, \"error\");\n\n\tprivate int m_id;\n\n\tprivate String m_level;\n\n\tprivate LogLevel(int id, String level) {\n\t\tm_id = id;\n\t\tm_level = level;\n\t}\n\n\tpublic static String getName(int id) {\n\t\tfor (LogLevel logLevel : LogLevel.values()) {\n\t\t\tif (logLevel.getId() == id) {\n\t\t\t\treturn logLevel.getLevel();\n\t\t\t}\n\t\t}\n\n\t\tthrow new RuntimeException(\"Invalid level.\");\n\t}\n\n\tpublic static int getId(String level) {\n\t\tfor (LogLevel logLevel : LogLevel.values()) {\n\t\t\tif (logLevel.getLevel().equalsIgnoreCase(level)) {\n\t\t\t\treturn logLevel.getId();\n\t\t\t}\n\t\t}\n\n\t\tthrow new RuntimeException(\"Invalid level.\");\n\t}\n\n\tpublic int getId() {\n\t\treturn m_id;\n\t}\n\n\tpublic String getLevel() {\n\t\treturn m_level;","sourceCodeStart":25,"sourceCodeEnd":61,"githubUrl":"https://github.com/dianping/cat/blob/e815e74d4c2dd74edac831241f1253fcc7d25381/cat-core/src/main/java/com/dianping/cat/config/LogLevel.java#L25-L61","documentation":"LogLevel.getName(int) throws RuntimeException(\"Invalid level.\") when the id matches no LogLevel enum constant. LogLevel maps log-level ids to names for CAT's log-viewing features. Note it uses ids, not the character codes some other CAT enums use — passing a wrong identifier type is a classic cause.","triggerScenarios":"LogLevel.getName(id) with an id outside the enum's defined ids — e.g. a char value accidentally passed as an int ('E' = 69), -1 from a lookup failure upstream, or an id from a newer/older schema.","commonSituations":"Version skew between the CAT server and stored/forwarded log data, passing an ASCII char code where a numeric enum id was expected, or default int values (0/-1) from unparsed fields reaching this call.","solutions":["Log the id at the call site; compare with the id values declared in the LogLevel enum.","Validate the id range before calling, or scan LogLevel.values() for a match and fall back to a default name.","If ids come from remote data, pin client and server to matching versions or send names instead of ids.","Fix upstream parsing so uninitialized ids never reach this mapping."],"exampleFix":"// before\nString level = LogLevel.getName(event.getLevelId()); // id 99 -> throws\n\n// after\nint id = event.getLevelId();\nString level = null;\nfor (LogLevel l : LogLevel.values()) { if (l.getId() == id) { level = l.getLevel(); break; } }\nif (level == null) level = \"UNKNOWN\";","handlingStrategy":"validation","validationCode":"boolean ok = false;\nfor (LogLevel l : LogLevel.values()) if (l.getId() == id) { ok = true; break; }\nif (!ok) id = defaultId;","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Do not confuse char level codes with numeric enum ids.","Pin client/server versions that share the id scheme."],"tags":["enum","validation","versioning"],"backgroundTag":null,"analyzedSha":"e815e74d4c2dd74edac831241f1253fcc7d25381","analyzedAt":"2026-08-14T14:22:34.512Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}