Ktor: Ktor with Android client throws IllegalStateException - responseMessage must not be null

Created on 21 Apr 2020  Â·  7Comments  Â·  Source: ktorio/ktor

Ktor Version and Engine Used (client or server and name)
Version 1.3.1 of Ktor client with Android module

Describe the bug
When I do a get request I am getting Exception in thread "main" java.lang.IllegalStateException: connection.responseMessage must not be null

To Reproduce

  • Running with Java 11, with maven, kotlin stdlib and org.jetbrains.kotlin maven plugin.
import io.ktor.client.HttpClient
import io.ktor.client.engine.android.Android
import io.ktor.client.request.get
import io.ktor.client.statement.HttpResponse
import io.ktor.utils.io.readUTF8Line
import kotlinx.coroutines.runBlocking

fun main() {

    runBlocking {
        val response: HttpResponse = HttpClient(Android).get("http://api.chucknorris.io/jokes/random")

        print(response.status.value)
        print(response.content.readUTF8Line())
    }

}

Expected behavior
I would expect it should print the status code and response message, but it doesn't reach at that point.

Screenshots
Screenshot 2020-04-21 at 12 53 59

bug

All 7 comments

I discovered that the some servers don't always send the reasonPrase. I am using Tomcat and they mentioned it is disabled by default, but can be enabled. However this option is deprecated and the switch will be removed for the next release. I am not quite sure if other servers always do send the reasonPhrase.

I found the following rfc http specification for the reason phrase, https://tools.ietf.org/html/rfc7230#section-3.1.2

The reason-phrase element exists for the sole purpose of providing a
textual description associated with the numeric status code, mostly
out of deference to earlier Internet application protocols that were
more frequently used with interactive text clients. A client SHOULD
ignore the reason-phrase content.

AndroidClientEngine requires the reasonPhrase at line number 85 val statusCode = HttpStatusCode(connection.responseCode, connection.responseMessage) Would it be possible to make the reasonPhrease optional within the AndroidClientEngine?

This issue is fixed with the following pull request: https://github.com/ktorio/ktor/pull/1852

I'm on Version 1.3.2 of Ktor client and I am still having this issues. The API calls work when I am running in app but under MPP unit testing I get the same exception.

sourceSets["androidTest"].dependencies {
        implementation("io.ktor:ktor-client-android:1.3.2")
       ...
}
    @Test
    @Tag("IntegrationTest")
    fun `Failing`() = runBlocking  {

        val response: HttpResponse = HttpClient().get("http://api.chucknorris.io/jokes/random")

        print(response.status.value)
        print(response.content.readUTF8Line())

    }

Exception

Caused by: java.lang.IllegalStateException: connection.responseMessage must not be null
    at io.ktor.client.engine.android.AndroidClientEngine.execute(AndroidClientEngine.kt:85)
    at io.ktor.client.engine.HttpClientEngine$executeWithinCallContext$2.invokeSuspend(HttpClientEngine.kt:83)
    at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
    at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:56)
    at kotlinx.coroutines.scheduling.CoroutineScheduler.runSafely(CoroutineScheduler.kt:571)

Hi @rolfwessels

This bug has been fixed but not available yet. The latest release is from March 2020 while the bug has been fixed at May 2020. They still need to release a new version of the library including the bug fix.

Hi @e5l, any idea when the next release will be made?

Is there any work around for this?

On Tue, Aug 18, 2020, 3:39 PM Hakky54 notifications@github.com wrote:

Hi @rolfwessels https://github.com/rolfwessels

This bug has been fixed but not available yet. The latest release is from
March 2020 while the bug has been fixed at April 2020. They still need to
release a new version of the library including the bug fix.

Hi @e5l https://github.com/e5l, any idea when the next release will be
made?

—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
https://github.com/ktorio/ktor/issues/1812#issuecomment-675484491, or
unsubscribe
https://github.com/notifications/unsubscribe-auth/AAE5A2YXSCDDRXYXOEPDOC3SBKABNANCNFSM4MNGPRTQ
.

Just made one. Sorry for the delay, please check 1.4.0

@e5l Thanks, appreciate it.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

lamba92 picture lamba92  Â·  3Comments

r4zzz4k picture r4zzz4k  Â·  4Comments

KennethanCeyer picture KennethanCeyer  Â·  4Comments

evgfilim1 picture evgfilim1  Â·  4Comments

SimonSchubert picture SimonSchubert  Â·  4Comments