{"record":{"id":"3b515f1ea4badc82","repo":"jd-opensource/joyagent-jdgenie","slug":"error-3b515f","errorCode":null,"errorMessage":"返回结果为空！","messagePattern":"返回结果为空！","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"genie-backend/src/main/java/com/jd/genie/util/HttpUtils.java","lineNumber":130,"sourceCode":"        httpReq.setConfig(requestConfig);\n        // 传入header信息\n        if (headers != null && !headers.isEmpty()) {\n            for (Map.Entry<String, String> entry : headers.entrySet()) {\n                httpReq.setHeader(entry.getKey(), String.valueOf(entry.getValue()));\n            }\n        }\n        // 传入body信息\n        if (StringUtils.isNotEmpty(body)) {\n            ((HttpEntityEnclosingRequestBase) httpReq).setEntity(new StringEntity(body, ContentType.create(\"application/json\", \"utf-8\")));\n        }\n        CloseableHttpResponse response = null;\n        try {\n            response = HttpClient.INS.getHttpClient().execute(httpReq);\n            String responseEntityStr = EntityUtils.toString(response.getEntity());\n            return Objects.requireNonNull(responseEntityStr);\n        } catch (NullPointerException e) {\n            log.error(\"httpReq请求失败：url:{}\", url, e);\n            throw new RuntimeException(\"返回结果为空！\", e);\n        } catch (Exception e) {\n            log.error(\"httpReq请求失败：url:{}\", url, e);\n            throw new RuntimeException(e);\n        } finally {\n            close(response);\n        }\n    }\n\n    private static HttpRequestBase getHttpRequest(String type, String url) {\n        HttpRequestBase httpReq = null;\n        switch (type) {\n            case \"post\":\n                httpReq = new HttpPost(url);\n                break;\n            case \"put\":\n                httpReq = new HttpPut(url);\n                break;\n            case \"delete\":","sourceCodeStart":112,"sourceCodeEnd":148,"githubUrl":"https://github.com/jd-opensource/joyagent-jdgenie/blob/2417e0b8b636d941ad5fb14c59b20dddfef5375d/genie-backend/src/main/java/com/jd/genie/util/HttpUtils.java#L112-L148","documentation":"httpReqThrowException executes an HTTP request and requires a non-empty response body via Objects.requireNonNull. When the entity string is null (no response body, or response/response.getEntity() is null) an NPE is caught and rethrown as RuntimeException(\"返回结果为空！\", i.e. 'response is empty').","triggerScenarios":"The remote server returns 204 No Content, an empty body, or a null entity; connection failures producing a response without an entity; HttpClient returning a response whose entity was already consumed.","commonSituations":"Calling endpoints that legitimately return empty bodies; proxies/gateways stripping the body; server errors returning no payload; timeout or reset mid-response.","solutions":["Check the HTTP status code and response entity for null before parsing","Only call httpReqThrowException for endpoints that guarantee a body; use a tolerant variant otherwise","Inspect the wrapped NPE cause (logged with the URL) to determine why the body was missing","Fix the server/proxy to return a proper body or a non-2xx error instead of an empty 200","Add retry logic for transient network failures"],"exampleFix":"// before\nString body = httpUtils.httpReqThrowException(request);\n// after\nHttpResponse response = httpClient.execute(request);\nif (response.getStatusLine().getStatusCode() == 204 || response.getEntity() == null) {\n    return null; // or default value\n}\nString body = EntityUtils.toString(response.getEntity());","handlingStrategy":"try-catch","validationCode":"HttpUriRequest req = ...;\n// pre-check: only call httpReqThrowException on endpoints documented to return a body\nHttpResponse probe = HttpClient.INS.getHttpClient().execute((HttpUriRequest) req);\nint status = probe.getStatusLine().getStatusCode();\nif (status == 204 || probe.getEntity() == null) { /* handle empty */ }","typeGuard":null,"tryCatchPattern":"try {\n    String body = httpUtils.httpReqThrowException(request);\n} catch (RuntimeException e) {\n    Throwable cause = e.getCause();\n    if (cause instanceof NullPointerException) {\n        // empty response body — use default/fallback\n    } else {\n        throw e;\n    }\n}","preventionTips":["Check response status codes before consuming the entity","Avoid calling this helper for 204/empty-body endpoints","Retry transient network failures with backoff","Monitor the logged url:{} entries to spot services returning empty bodies"],"tags":["java","http","network","empty-response"],"backgroundTag":"empty-response-body","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"}