{"record":{"id":"45635e238b8db8bd","repo":"jd-opensource/joyagent-jdgenie","slug":"nl2sql","errorCode":null,"errorMessage":"nl2sql返回对象为空","messagePattern":"nl2sql返回对象为空","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"genie-backend/src/main/java/com/jd/genie/service/Nl2SqlService.java","lineNumber":78,"sourceCode":"        Nl2SqlSseListener sqlSseListener = new Nl2SqlSseListener(emitter, request.getRequestId(), request.getTraceId());\n        OkHttpUtil.requestSse(dataAgentConfig.getAgentUrl() + NL2SQL_URL, null, JSONObject.toJSONString(request), sqlSseListener);\n        sqlSseListener.getCountDownLatch().await();\n        int eventCount = sqlSseListener.getEventCount();\n        log.info(\"{} sse event count:{}\", request.getRequestId(), eventCount);\n        if (!sqlSseListener.isSuccess()) {\n            throw new RuntimeException(\"sse listener failed \" + sqlSseListener.getErrorMessage());\n        }\n        NL2SQLResult nl2SQLResult = sqlSseListener.getNl2SQLResult();\n        if (err.get() != null) {\n            throw new RuntimeException(\"sse nl2sql failed:\" + err.get().getMessage());\n        }\n        return nl2sqlQueryData(request, nl2SQLResult);\n    }\n\n\n    public String replaceFirstMatchedOrThrow(String input, List<String> codeList) {\n        if (input == null || codeList == null || codeList.isEmpty()) {\n            throw new IllegalArgumentException(\"nl2sql返回对象为空\");\n        }\n\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 {","sourceCodeStart":60,"sourceCodeEnd":96,"githubUrl":"https://github.com/jd-opensource/joyagent-jdgenie/blob/2417e0b8b636d941ad5fb14c59b20dddfef5375d/genie-backend/src/main/java/com/jd/genie/service/Nl2SqlService.java#L60-L96","documentation":"replaceFirstMatchedOrThrow decorates model code identifiers in the nl2sql-generated SQL with backticks. It throws IllegalArgumentException('nl2sql返回对象为空') when the input SQL or the code list is null/empty — i.e. the nl2sql result object lacked the data needed to post-process.","triggerScenarios":"prettySql() calls replaceFirstMatchedOrThrow with nl2SQLData.getNl2sql()==null or request.getModelCodeList() empty/null.","commonSituations":"Agent returned a data item with no nl2sql field; frontend request omitted modelCodeList; older agent versions returning a different field name.","solutions":["Ensure request.modelCodeList is populated with the model codes before calling NL2SQL","Check the agent response item has a non-null nl2sql field","If null input is legitimate, relax the guard to return input unchanged instead of throwing"],"exampleFix":"// before\nif (input == null || codeList == null || codeList.isEmpty()) {\n    throw new IllegalArgumentException(\"nl2sql返回对象为空\");\n}\n// after\nif (input == null) {\n    return null;\n}\nif (codeList == null || codeList.isEmpty()) {\n    return input;\n}","handlingStrategy":"validation","validationCode":"if (request.getModelCodeList() == null || request.getModelCodeList().isEmpty()) {\n    throw new IllegalArgumentException(\"modelCodeList is required\");\n}\n// and ensure nl2SQLData.getNl2sql() != null before prettySql","typeGuard":"boolean isDecoratable(String sql, List<String> codes) {\n    return sql != null && codes != null && !codes.isEmpty();\n}","tryCatchPattern":"try {\n    pretty = prettySql(data, request);\n} catch (IllegalArgumentException e) {\n    log.warn(\"cannot decorate sql: {}\", e.getMessage());\n    pretty = data.getNl2sql(); // fall back to raw sql\n}","preventionTips":["Always populate modelCodeList in NL2SQLReq","Null-check agent nl2sql output before post-processing","Add unit tests for empty codeList paths"],"tags":["validation","nl2sql","null-value"],"backgroundTag":"null-argument","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"}