From ac21650da731667a8d86fbf591253eace3344f5e Mon Sep 17 00:00:00 2001 From: agarcia Date: Mon, 25 May 2020 11:51:13 +0200 Subject: [PATCH] Manage responses with no avatar --- .../resources/users/GetRemoteUserAvatarOperation.kt | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/users/GetRemoteUserAvatarOperation.kt b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/users/GetRemoteUserAvatarOperation.kt index 18191218..44769622 100644 --- a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/users/GetRemoteUserAvatarOperation.kt +++ b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/users/GetRemoteUserAvatarOperation.kt @@ -38,7 +38,7 @@ import java.net.URL class GetRemoteUserAvatarOperation(private val avatarDimension: Int) : RemoteOperation() { override fun run(client: OwnCloudClient): RemoteOperationResult { - lateinit var inputStream: InputStream + var inputStream: InputStream? = null lateinit var getMethod: GetMethod lateinit var result: RemoteOperationResult @@ -71,7 +71,7 @@ class GetRemoteUserAvatarOperation(private val avatarDimension: Int) : Timber.d("Avatar size: Bytes received ${bytesArray.size} of $contentLength") // find out etag - val etag = WebdavUtils.getEtagFromResponse(getMethod); + val etag = WebdavUtils.getEtagFromResponse(getMethod) if (etag.isEmpty()) { Timber.w("Could not read Etag from avatar") } @@ -87,14 +87,14 @@ class GetRemoteUserAvatarOperation(private val avatarDimension: Int) : } catch (e: Exception) { result = RemoteOperationResult(e) - Timber.e(e, "Exception while getting OC user avatar"); + Timber.e(e, "Exception while getting OC user avatar") } finally { try { - client.exhaustResponse(inputStream); - inputStream.close() + client.exhaustResponse(inputStream) + inputStream?.close() } catch (i: IOException) { - Timber.e(i, "Unexpected exception closing input stream"); + Timber.e(i, "Unexpected exception closing input stream") } }