question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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

See original GitHub issue

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

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
e5lcommented, Aug 19, 2020

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

1reaction
Hakky54commented, Aug 18, 2020

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?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Null connection in Ktor causing java.lang.IllegalStateException
I am trying to read data from an API-endpoint using Ktor and getting an IllegalStateException often regarding supposedly null connection.
Read more >
Response validation - Ktor
If required, you can use the following validation strategies: Use the expectSuccess property to throw exceptions for non-2xx responses.
Read more >
Ktor Http Client: Receive null on a not nullable field ... - YouTrack
Assume you want to query data from an API that responds with the following payload if everything works well, while the data field...
Read more >
Using Ktor Client MockEngine for Integration and UI Tests
The project used in this article is a sample Android app which ... null get() = field ?: throw IllegalStateException("Mock has not beet ......
Read more >
How to Build a Simple REST API With Ktor + Android App
Building a REST API in Kotlin made easy. Learn it in this video.Find my Ktor courses here (15% off with discount code ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found