diff --git a/proj-android/PowerAuthLibrary/src/main/java/io/getlime/security/powerauth/networking/client/HttpClientTask.java b/proj-android/PowerAuthLibrary/src/main/java/io/getlime/security/powerauth/networking/client/HttpClientTask.java index 4d277469..c05da204 100644 --- a/proj-android/PowerAuthLibrary/src/main/java/io/getlime/security/powerauth/networking/client/HttpClientTask.java +++ b/proj-android/PowerAuthLibrary/src/main/java/io/getlime/security/powerauth/networking/client/HttpClientTask.java @@ -269,14 +269,15 @@ private void setThreadStatsTag() { * @param connection prepared connection object. * @param requestData (optional) byte array with request data. */ - private void logRequest(HttpURLConnection connection, byte[] requestData) { + private void logRequest(@Nullable HttpURLConnection connection, @Nullable byte[] requestData) { if (!PowerAuthLog.isEnabled()) { return; } // Endpoint final IEndpointDefinition endpoint = httpRequestHelper.getEndpoint(); // URL, method - final String url = connection.getURL().toString(); + final boolean hasConnection = connection != null; + final String url = hasConnection ? connection.getURL().toString() : "null"; final String method = endpoint.getHttpMethod(); // Flags final boolean signature = endpoint.getAuthorizationUriId() != null; @@ -287,7 +288,7 @@ private void logRequest(HttpURLConnection connection, byte[] requestData) { PowerAuthLog.d("HTTP %s request%s: -> %s", method, signedEncrypted, url); } else { // Verbose, put headers and body (if not encrypted) into the log. - final Map> prop = connection.getRequestProperties(); + final Map> prop = hasConnection ? connection.getRequestProperties() : null; final String propStr = prop == null ? "" : prop.toString(); if (encrypted) { PowerAuthLog.d("HTTP %s request%s: %s\n- Headers: %s- Body: ", method, signedEncrypted, url, propStr); @@ -305,14 +306,15 @@ private void logRequest(HttpURLConnection connection, byte[] requestData) { * @param responseData (optional) data returned in HTTP request. * @param error (optional) error produced during the request. */ - private void logResponse(HttpURLConnection connection, byte[] responseData, Throwable error) { + private void logResponse(@Nullable HttpURLConnection connection, @Nullable byte[] responseData, @Nullable Throwable error) { if (!PowerAuthLog.isEnabled()) { return; } // Endpoint final IEndpointDefinition endpoint = httpRequestHelper.getEndpoint(); // URL, method - final String url = connection.getURL().toString(); + final boolean hasConnection = connection != null; + final String url = hasConnection ? connection.getURL().toString() : "null"; final String method = endpoint.getHttpMethod(); final String errorMessage; if (error != null) { @@ -329,7 +331,7 @@ private void logResponse(HttpURLConnection connection, byte[] responseData, Thro // Response code int responseCode; try { - responseCode = connection.getResponseCode(); + responseCode = hasConnection ? connection.getResponseCode() : 0; } catch (IOException e) { responseCode = 0; } @@ -343,7 +345,7 @@ private void logResponse(HttpURLConnection connection, byte[] responseData, Thro } else { final boolean encrypted = endpoint.getEncryptorId() != EciesEncryptorId.NONE; // Response headers - final String responseHeaders = connection.getHeaderFields().toString(); + final String responseHeaders = hasConnection ? connection.getHeaderFields().toString() : "{}"; // Response body final String responseBodyTmp = responseData == null ? "" : new String(responseData, Charset.defaultCharset()); final String responseBody;