{"record":{"id":"75b5ab7caea3a2fc","repo":"android-async-http/android-async-http","slug":"responsehandler-must-not-be-null","errorCode":null,"errorMessage":"ResponseHandler must not be null","messagePattern":"ResponseHandler must not be null","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"library/src/main/java/com/loopj/android/http/AsyncHttpClient.java","lineNumber":1540,"sourceCode":"    /**\n     * Puts a new request in queue as a new thread in pool to be executed\n     *\n     * @param client          HttpClient to be used for request, can differ in single requests\n     * @param contentType     MIME body type, for POST and PUT requests, may be null\n     * @param context         Context of Android application, to hold the reference of request\n     * @param httpContext     HttpContext in which the request will be executed\n     * @param responseHandler ResponseHandler or its subclass to put the response into\n     * @param uriRequest      instance of HttpUriRequest, which means it must be of HttpDelete,\n     *                        HttpPost, HttpGet, HttpPut, etc.\n     * @return RequestHandle of future request process\n     */\n    protected RequestHandle sendRequest(DefaultHttpClient client, HttpContext httpContext, HttpUriRequest uriRequest, String contentType, ResponseHandlerInterface responseHandler, Context context) {\n        if (uriRequest == null) {\n            throw new IllegalArgumentException(\"HttpUriRequest must not be null\");\n        }\n\n        if (responseHandler == null) {\n            throw new IllegalArgumentException(\"ResponseHandler must not be null\");\n        }\n\n        if (responseHandler.getUseSynchronousMode() && !responseHandler.getUsePoolThread()) {\n            throw new IllegalArgumentException(\"Synchronous ResponseHandler used in AsyncHttpClient. You should create your response handler in a looper thread or use SyncHttpClient instead.\");\n        }\n\n        if (contentType != null) {\n            if (uriRequest instanceof HttpEntityEnclosingRequestBase && ((HttpEntityEnclosingRequestBase) uriRequest).getEntity() != null && uriRequest.containsHeader(HEADER_CONTENT_TYPE)) {\n                log.w(LOG_TAG, \"Passed contentType will be ignored because HttpEntity sets content type\");\n            } else {\n                uriRequest.setHeader(HEADER_CONTENT_TYPE, contentType);\n            }\n        }\n\n        responseHandler.setRequestHeaders(uriRequest.getAllHeaders());\n        responseHandler.setRequestURI(uriRequest.getURI());\n\n        AsyncHttpRequest request = newAsyncHttpRequest(client, httpContext, uriRequest, contentType, responseHandler, context);","sourceCodeStart":1522,"sourceCodeEnd":1558,"githubUrl":"https://github.com/android-async-http/android-async-http/blob/018a0b8d96a0dd569de9f8128cfe5d030e0423ef/library/src/main/java/com/loopj/android/http/AsyncHttpClient.java#L1522-L1558","documentation":"sendRequest throws IllegalArgumentException when the ResponseHandler passed in is null. AsyncHttpClient relies on the handler to process the HTTP response on the caller's looper thread; without one it cannot deliver results. The guard fails fast instead of crashing when the response arrives.","triggerScenarios":"Calling get/post/delete/put with a null ResponseHandlerInterface; passing a handler variable that was never initialized; API misuse where the developer expected the client to work fire-and-forget without a handler.","commonSituations":"Forgetting to instantiate an AsyncHttpResponseHandler subclass; a factory method returning null on failure; code paths where the handler is only assigned in one branch.","solutions":["Pass a non-null AsyncHttpResponseHandler (e.g. new TextHttpResponseHandler(){...}) to the request method","If no result handling is needed, still supply an empty handler implementation","Verify any handler-producing helper cannot return null"],"exampleFix":"// before\nclient.get(url, (RequestParams) null, null);\n// after\nclient.get(url, (RequestParams) null, new AsyncHttpResponseHandler() {\n    @Override public void onSuccess(int statusCode, Header[] headers, byte[] responseBody) {}\n    @Override public void onFailure(int statusCode, Header[] headers, byte[] responseBody, Throwable error) {}\n});","handlingStrategy":"validation","validationCode":"if (handler == null) { handler = new AsyncHttpResponseHandler() {\n    @Override public void onSuccess(int s, Header[] h, byte[] b) {}\n    @Override public void onFailure(int s, Header[] h, byte[] b, Throwable t) {}\n}; }","typeGuard":"boolean hasHandler = (responseHandler instanceof ResponseHandlerInterface); // null check before request call\nif (!hasHandler) { /* create default handler */ }","tryCatchPattern":"try { client.get(url, params, handler); } catch (IllegalArgumentException e) { Log.e(TAG, \"handler missing\", e); }","preventionTips":["Always pass a handler, even a no-op one, to AsyncHttpClient request methods","Never return null from handler factories","Remember AsyncHttpClient has no fire-and-forget mode; a handler is mandatory"],"tags":["android","http","null-argument","async-http-client"],"backgroundTag":"null-argument","analyzedSha":"018a0b8d96a0dd569de9f8128cfe5d030e0423ef","analyzedAt":"2026-09-09T15:22:01.829Z","contentChangedAt":"2026-09-09T15:22:01.829Z","schemaVersion":2},"datasetVersion":"2026-09-17T15:17:12.973Z"}