ktorio / ktorio/ktor-init-tools

Exception when using "logging feature": "java.lang.IllegalStateException: Failed to find HttpClientEngineContainer in classpath via ServiceLoader"

Open
#5 2 comments 0 reactions 0 assignees View on GitHub
Dominant language
Kotlin
Stars
40
Forks
22
PR merge metrics
No merged PRs in 30d

Description

As erroneously opened in [ktorio/ktor:867](https://github.com/ktorio/ktor/issues/867)

### Ktor Version
1.1.1

### Ktor Engine Used(client or server and name)
io.ktor.server.netty.EngineMain

### JVM Version, Operating System and Relevant Context
```
openjdk version "1.8.0_192"
OpenJDK Runtime Environment (build 1.8.0_192-b26)
OpenJDK 64-Bit Server VM (build 25.192-b26, mixed mode)
```

OS: `Linux 4.14.90-1-MANJARO`

### Feedback

I have created a completely fresh project using the IntelliJ Ktor-plugin's starter, only choosing "Logging feature" as additional features.

Starting the server without doing any changes gives me the following stack trace:

```
2019-01-13 16:51:11.390 [main] INFO Application - No ktor.deployment.watch patterns specified, automatic reload is not active
Exception in thread "main" java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at kotlin.reflect.jvm.internal.calls.CallerImpl$Method.callMethod(CallerImpl.kt:71)
at kotlin.reflect.jvm.internal.calls.CallerImpl$Method$Static.call(CallerImpl.kt:80)
at kotlin.reflect.jvm.internal.KCallableImpl.callDefaultMethod$kotlin_reflect_api(KCallableImpl.kt:166)
at kotlin.reflect.jvm.internal.KCallableImpl.callBy(KCallableImpl.kt:110)
at io.ktor.server.engine.ApplicationEngineEnvironmentReloading.callFunctionWithInjection(ApplicationEngineEnvironmentReloading.kt:347)
at io.ktor.server.engine.ApplicationEngineEnvironmentReloading.executeModuleFunction(ApplicationEngineEnvironmentReloading.kt:297)
at io.ktor.server.engine.ApplicationEngineEnvironmentReloading.instantiateAndConfigureApplication(ApplicationEngineEnvironmentReloading.kt:273)
at io.ktor.server.engine.ApplicationEngineEnvironmentReloading.createApplication(ApplicationEngineEnvironmentReloading.kt:126)
at io.ktor.server.engine.ApplicationEngineEnvironmentReloading.start(ApplicationEngineEnvironmentReloading.kt:245)
at io.ktor.server.netty.NettyApplicationEngine.start(NettyApplicationEngine.kt:106)
at io.ktor.server.netty.NettyApplicationEngine.start(NettyApplicationEngine.kt:18)
at io.ktor.server.engine.ApplicationEngine$DefaultImpls.start$default(ApplicationEngine.kt:46)
at io.ktor.server.netty.EngineMain.main(EngineMain.kt:17)
at com.example.ApplicationKt.main(Application.kt:12)
Caused by: java.lang.ExceptionInInitializerError
at com.example.ApplicationKt.module(Application.kt:27)
at com.example.ApplicationKt.module$default(Application.kt:16)
... 18 more
Caused by: java.lang.IllegalStateException: Failed to find HttpClientEngineContainer in classpath via ServiceLoader
at io.ktor.client.HttpClientJvmKt.(HttpClientJvm.kt:28)
... 20 more
```

Removing this section in `Application.kt`:

```kotlin
val client = HttpClient() {
install(Logging) {
level = LogLevel.HEADERS
}
}
```

Allows me to start the server successfully.

Contributor guide

No contributing guide indexed for this repository

Research direction

Start with the generated Application.kt and the HttpClient() logging setup shown in the report, then follow the startup stack trace through HttpClientJvm.kt and the ServiceLoader lookup. Reproduce the fresh Ktor project failure with Logging enabled; done means the generated server starts successfully without removing that configuration.

Written by the indexing model from the issue text.

Assessment

Tech stack
kotlin
Domain
tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.