{"record":{"id":"7a3c35744f4de031","repo":"jd-opensource/joyagent-jdgenie","slug":"nl2sql-result-is-null","errorCode":null,"errorMessage":"nl2sql result is null","messagePattern":"nl2sql result is null","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"genie-backend/src/main/java/com/jd/genie/service/Nl2SqlService.java","lineNumber":98,"sourceCode":"\n        List<Pattern> patterns = codeList.stream()\n                .distinct()\n                .map(code -> Pattern.compile(\"(?i)(?<!`)\\\\b\" + Pattern.quote(code) + \"\\\\b(?!`)\"))\n                .toList();\n\n        Matcher matcher;\n        for (Pattern pattern : patterns) {\n            matcher = pattern.matcher(input);\n            if (matcher.find()) {\n                return matcher.replaceFirst(\"`$0`\");\n            }\n        }\n        return input;\n    }\n\n    private List<ChatQueryData> nl2sqlQueryData(NL2SQLReq request, NL2SQLResult nl2SQLResult) throws Exception {\n        if (nl2SQLResult == null || nl2SQLResult.getCode() == null) {\n            throw new RuntimeException(\"nl2sql result is null\");\n        }\n        if (nl2SQLResult.getCode() != 200) {\n            throw new RuntimeException(\"nl2sql server return error:\" + nl2SQLResult.getErr_msg());\n        }\n        if (CollectionUtils.isEmpty(nl2SQLResult.getData())) {\n            throw new RuntimeException(\"nl2sql返回为空\");\n        }\n        nl2SQLResult.setRootQuery(request.getQuery());\n        for (NL2SQLResult.NL2SQLData nl2SQLData : nl2SQLResult.getData()) {\n            String prettySql = replaceFirstMatchedOrThrow(nl2SQLData.getNl2sql(), request.getModelCodeList());\n            nl2SQLData.setNl2sql(prettySql);\n        }\n        return queryData(request, nl2SQLResult);\n    }\n\n    public String getTableName(ChatModelInfoDto modelInfo) {\n        if (\"table\".equalsIgnoreCase(modelInfo.getType())) {\n            return modelInfo.getContent();","sourceCodeStart":80,"sourceCodeEnd":116,"githubUrl":"https://github.com/jd-opensource/joyagent-jdgenie/blob/2417e0b8b636d941ad5fb14c59b20dddfef5375d/genie-backend/src/main/java/com/jd/genie/service/Nl2SqlService.java#L80-L116","documentation":"nl2sqlQueryData validates the NL2SQLResult envelope before extracting data. If the parsed result is null or its code field is null, this RuntimeException is thrown — meaning the agent response could not be parsed into a valid NL2SQLResult (bad JSON shape or empty body).","triggerScenarios":"runNL2SQLSync/runNL2SQLSse call nl2sqlQueryData with nl2SQLResult==null (JSON parse of empty/garbage body) or with code==null (response JSON missing 'code').","commonSituations":"Agent returned an HTML error page or empty 200 body; version skew between agent response schema and NL2SQLResult fields; fastjson parse silently yielding null fields.","solutions":["Log the raw jsonResult and verify it parses to {code:200,...}","Check that the agent endpoint is the NL2SQL API and not a generic error page","Align NL2SQLResult field names with the agent's current response schema"],"exampleFix":"// before\nif (nl2SQLResult == null || nl2SQLResult.getCode() == null) {\n    throw new RuntimeException(\"nl2sql result is null\");\n}\n// after\nif (nl2SQLResult == null || nl2SQLResult.getCode() == null) {\n    throw new RuntimeException(\"nl2sql result is null, traceId=\" + request.getTraceId());\n}","handlingStrategy":"type-guard","validationCode":"NL2SQLResult r = JSONObject.parseObject(jsonResult, NL2SQLResult.class);\nif (r == null || r.getCode() == null) {\n    log.error(\"bad nl2sql response: {}\", jsonResult);\n    return;\n}","typeGuard":"boolean isValidResult(NL2SQLResult r) {\n    return r != null && r.getCode() != null;\n}","tryCatchPattern":"try {\n    List<ChatQueryData> data = nl2sqlQueryData(request, result);\n} catch (RuntimeException e) {\n    if (\"nl2sql result is null\".equals(e.getMessage())) {\n        // inspect raw response / agent health\n    }\n    throw e;\n}","preventionTips":["Log raw agent responses for schema drift detection","Validate agent response contract with integration tests","Reject non-JSON (HTML) bodies early"],"tags":["nl2sql","response-shape","null-value"],"backgroundTag":"unexpected-api-response-shape","analyzedSha":"2417e0b8b636d941ad5fb14c59b20dddfef5375d","analyzedAt":"2026-09-08T11:28:19.414Z","contentChangedAt":"2026-09-08T11:28:19.414Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}