Commit e6986869 authored by Stefan Arentz's avatar Stefan Arentz
Browse files

Closes #5946: HttpIconLoad$toIconLoaderResult can throw an IOException

parent f753fe2c
......@@ -49,19 +49,18 @@ class HttpIconLoader(
redirect = Request.Redirect.FOLLOW,
useCaches = true)
val response = try {
httpClient.fetch(downloadRequest)
return try {
val response = httpClient.fetch(downloadRequest)
if (response.isSuccess) {
response.toIconLoaderResult()
} else {
failureCache.rememberFailure(resource.url)
IconLoader.Result.NoResult
}
} catch (e: IOException) {
logger.debug("IOException while trying to download icon resource", e)
return IconLoader.Result.NoResult
}
return if (response.isSuccess) {
response.toIconLoaderResult()
} else {
failureCache.rememberFailure(resource.url)
IconLoader.Result.NoResult
}
}
private fun shouldDownload(resource: IconRequest.Resource): Boolean {
......
......@@ -29,6 +29,7 @@ import org.mockito.Mockito.never
import org.mockito.Mockito.reset
import org.mockito.Mockito.verify
import org.mockito.Mockito.verifyNoMoreInteractions
import java.io.InputStream
import java.io.IOException
@RunWith(AndroidJUnit4::class)
......@@ -196,4 +197,31 @@ class HttpIconLoaderTest {
assertEquals(IconLoader.Result.NoResult, loader.load(testContext, mock(), resource))
}
@Test
fun `Loader will return NoResult for IOExceptions happening during toIconLoaderResult`() {
val client: Client = mock()
val failingStream: InputStream = object : InputStream() {
override fun read(): Int {
throw IOException("Kaboom")
}
}
val loader = HttpIconLoader(client)
doReturn(
Response(
url = "https://www.example.org",
headers = MutableHeaders(),
status = 200,
body = Response.Body(failingStream))
).`when`(client).fetch(any())
val resource = IconRequest.Resource(
url = "https://www.example.org",
type = IconRequest.Resource.Type.APPLE_TOUCH_ICON
)
assertEquals(IconLoader.Result.NoResult, loader.load(mock(), mock(), resource))
}
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment