Ktor: Support JDK9

Created on 10 Feb 2018  路  20Comments  路  Source: ktorio/ktor

package 'sun.security.x509' is not available in JDK9

e: /Users/jonnyzzz/Work/ktor/ktor-server/ktor-server-core/src/io/ktor/util/SSL.kt: (62, 10): Symbol is declared in module 'java.base' which does not export package 'sun.security.x509'

enhancement

Most helpful comment

Following this Ktor doc: https://ktor.io/quickstart/quickstart/intellij-idea/gradle.html

I'm getting this error when running io.ktor.server.netty.DevelopmentEngine from the intellij IDE

Error occurred during initialization of boot layer
java.lang.module.ResolutionException: Modules ktor.http.jvm and ktor.server.core export package io.ktor.http to module io.netty.transport

All 20 comments

It seems to be just used to create a self-signed certificate.
There is a similar issue in Netty: https://github.com/netty/netty/issues/6679

Maybe that functionality could be distributed in a separate module, since this is going to be used on development purposes mainly. And then Ktor could include bouncycastle libraries just for that module so the core doesn't depend on it.

sun.security.x509 dependency issue is fixed in master

JDK10 has just released. Will it break anything else ?

Java 10 is a pretty minor release in comparison with Java 9. You can try it by yourself, but I guess it should yield similar results to Java 9.
I have tried running some samples of Ktor and couldn't find major issues myself. The only warning I have noticed after switching from Java8 to Java10 is:

WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by io.netty.util.internal.ReflectionUtil (file:/Users/user/.m2/repository/io/netty/netty-common/4.1.19.Final/netty-common-4.1.19.Final.jar) to constructor java.nio.DirectByteBuffer(long,int)
WARNING: Please consider reporting this to the maintainers of io.netty.util.internal.ReflectionUtil
WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
WARNING: All illegal access operations will be denied in a future release

Building Ktor using JDK 10 (and probably JDK 9) produces this error (seems related to Dokka):

gradle install
...

> Task :ktor-http:dokka 
ERROR: Exception while analyzing expression at (50,5) in /Users/user/projects/ktor/ktor-http/src/io/ktor/http/FileContentType.kt:
CaseInsensitiveMap<List<ContentType>>(records.size).apply { putAll(records) }

java.lang.reflect.InaccessibleObjectException: Unable to make field private static final jdk.internal.misc.Unsafe jdk.internal.misc.Unsafe.theUnsafe accessible: module java.base does not "opens jdk.internal.misc" to unnamed module @291c57f
        at java.base/java.lang.reflect.AccessibleObject.checkCanSetAccessible(AccessibleObject.java:337)
        at java.base/java.lang.reflect.AccessibleObject.checkCanSetAccessible(AccessibleObject.java:281)
        at java.base/java.lang.reflect.Field.checkCanSetAccessible(Field.java:176)

Have you tried to build without dokka?
./gradle assemble -x dokka -x dokkaJavadoc

It seems that there is still a reference to sun here:

java -version
java version "10" 2018-03-20

./gradlew assemble -x dokka -x dokkaJavadoc

> Configure project :
The Task.leftShift(Closure) method has been deprecated and is scheduled to be removed in Gradle 5.0. Please use Task.doLast(Action) instead.
        at build_7q1su2ti4wt2dlh3kyd7ld443.run(/Users/user/projects/ktor/build.gradle:31)
        (Run with --stacktrace to get the full stack trace of this deprecation warning.)

e: /Users/user/projects/ktor/ktor-network-tls/src/io/ktor/network/tls/Parser.kt: (125, 20): Symbol is declared in module 'java.base' which does not export package 'sun.security.x509'

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':ktor-network-tls:compileKotlin'.
> Compilation error. See log for more details

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

* Get more help at https://help.gradle.org

BUILD FAILED in 2s
27 actionable tasks: 1 executed, 26 up-to-date

The reflection error with Netty was fixed on their side in 4.1.21Final and above. I think the version ktor uses needs updating to use it.

Now ktor compilation is passing under JDK9. Let's see what actually doesn't work in runtime

OK, now we have all tests running on CI, 4 tests failed (3 of them are identified, and the remaining one has unknown cause yet)

I'm getting

Error occurred during initialization of boot layer
java.lang.module.ResolutionException: Modules ktor.http and ktor.server.core export package io.ktor.http to module alpn.api

on running my server, is that related to this issue or should I open a new one for that?

Running Ktor 0.9.3 with Kotlin 1.2.51 on OpenJDK 1.11.0

Following this Ktor doc: https://ktor.io/quickstart/quickstart/intellij-idea/gradle.html

I'm getting this error when running io.ktor.server.netty.DevelopmentEngine from the intellij IDE

Error occurred during initialization of boot layer
java.lang.module.ResolutionException: Modules ktor.http.jvm and ktor.server.core export package io.ktor.http to module io.netty.transport

Following this Ktor doc: https://ktor.io/quickstart/quickstart/intellij-idea/gradle.html

I'm getting this error when running io.ktor.server.netty.DevelopmentEngine from the intellij IDE

Error occurred during initialization of boot layer
java.lang.module.ResolutionException: Modules ktor.http.jvm and ktor.server.core export package io.ktor.http to module io.netty.transport

Is there a workaround? I'm stuck on this too.

same problem
Error occurred during initialization of boot layer
java.lang.module.ResolutionException: Modules ktor.server.core and ktor.http.jvm export package io.ktor.http to module ktor.network

I have a lot of compile-time errors like:

error: module kotlinx.io.jvm reads package io.ktor.http from both ktor.server.core and ktor.http.jvm
error: module kotlinx.io.jvm reads package io.ktor.http.content from both ktor.server.core and ktor.http.jvm
error: module kotlinx.io.jvm reads package io.ktor.util from both ktor.server.core and ktor.utils.jvm
error: module kotlinx.coroutines.jdk8 reads package io.ktor.http from both ktor.server.core and ktor.http.jvm
error: module kotlinx.coroutines.jdk8 reads package io.ktor.http.content from both ktor.server.core and ktor.http.jvm
error: module kotlinx.coroutines.jdk8 reads package io.ktor.util from both ktor.server.core and ktor.utils.jvm
error: module kotlinx.coroutines.core reads package io.ktor.http from both ktor.server.core and ktor.http.jvm
error: module kotlinx.coroutines.core reads package io.ktor.http.content from both ktor.server.core and ktor.http.jvm
error: module kotlinx.coroutines.core reads package io.ktor.util from both ktor.server.core and ktor.utils.jvm
error: module logback.core reads package io.ktor.http from both ktor.server.core and ktor.http.jvm
error: module logback.core reads package io.ktor.http.content from both ktor.server.core and ktor.http.jvm
error: module logback.core reads package io.ktor.util from both ktor.server.core and ktor.utils.jvm
error: module slf4j.api reads package io.ktor.http from both ktor.server.core and ktor.http.jvm
error: module slf4j.api reads package io.ktor.http.content from both ktor.server.core and ktor.http.jvm
error: module slf4j.api reads package io.ktor.util from both ktor.server.core and ktor.utils.jvm
error: module atomicfu reads package io.ktor.http from both ktor.server.core and ktor.http.jvm
error: module atomicfu reads package io.ktor.http.content from both ktor.server.core and ktor.http.jvm
error: module atomicfu reads package io.ktor.util from both ktor.server.core and ktor.utils.jvm
error: module config reads package io.ktor.http from both ktor.server.core and ktor.http.jvm
error: module config reads package io.ktor.http.content from both ktor.server.core and ktor.http.jvm
error: module config reads package io.ktor.util from both ktor.server.core and ktor.utils.jvm
error: module kotlin.css reads package io.ktor.http from both ktor.server.core and ktor.http.jvm
error: module kotlin.css reads package io.ktor.http.content from both ktor.server.core and ktor.http.jvm
error: module kotlin.css reads package io.ktor.util from both ktor.server.core and ktor.utils.jvm
error: module kotlinx.coroutines.io reads package io.ktor.http from both ktor.server.core and ktor.http.jvm
error: module kotlinx.coroutines.io reads package io.ktor.http.content from both ktor.server.core and ktor.http.jvm
error: module kotlinx.coroutines.io reads package io.ktor.util from both ktor.server.core and ktor.utils.jvm
error: module kotlinx.io reads package io.ktor.http from both ktor.server.core and ktor.http.jvm
error: module kotlinx.io reads package io.ktor.http.content from both ktor.server.core and ktor.http.jvm
error: module kotlinx.io reads package io.ktor.util from both ktor.server.core and ktor.utils.jvm
error: module kotlinx.coroutines.core.common reads package io.ktor.http from both ktor.server.core and ktor.http.jvm
error: module kotlinx.coroutines.core.common reads package io.ktor.http.content from both ktor.server.core and ktor.http.jvm
error: module kotlinx.coroutines.core.common reads package io.ktor.util from both ktor.server.core and ktor.utils.jvm
error: module kotlin.stdlib.common reads package io.ktor.http from both ktor.server.core and ktor.http.jvm

Compile worked but got following error following code while running with JDK 12:

import io.ktor.application.call
import io.ktor.html.respondHtml
import io.ktor.routing.get
import io.ktor.routing.routing
import io.ktor.server.engine.embeddedServer
import io.ktor.server.netty.Netty
import kotlinx.html.a
import kotlinx.html.body

fun main() {
    embeddedServer(Netty, 8080) {
        routing {
            get("/") {
                call.respondHtml { body { a(href = "/", target = "Home") } }
            }
        }
    }
}

Error:

23:01:50.274 [main] DEBUG io.netty.util.internal.PlatformDependent0 - jdk.internal.misc.Unsafe.allocateUninitializedArray(int): unavailable
java.lang.IllegalAccessException: class io.netty.util.internal.PlatformDependent0$6 cannot access class jdk.internal.misc.Unsafe (in module java.base) because module java.base does not export jdk.internal.misc to unnamed module @2af616d3
    at java.base/jdk.internal.reflect.Reflection.newIllegalAccessException(Reflection.java:355)
    at java.base/java.lang.reflect.AccessibleObject.checkAccess(AccessibleObject.java:639)
    at java.base/java.lang.reflect.Method.invoke(Method.java:559)
    at io.netty.util.internal.PlatformDependent0$6.run(PlatformDependent0.java:334)
    at java.base/java.security.AccessController.doPrivileged(AccessController.java:310)
    at io.netty.util.internal.PlatformDependent0.<clinit>(PlatformDependent0.java:325)
    at io.netty.util.internal.PlatformDependent.isAndroid(PlatformDependent.java:212)
    at io.netty.util.internal.PlatformDependent.<clinit>(PlatformDependent.java:80)
    at io.netty.channel.nio.NioEventLoop.newTaskQueue(NioEventLoop.java:268)
    at io.netty.util.concurrent.SingleThreadEventExecutor.<init>(SingleThreadEventExecutor.java:165)
    at io.netty.channel.SingleThreadEventLoop.<init>(SingleThreadEventLoop.java:58)
    at io.netty.channel.nio.NioEventLoop.<init>(NioEventLoop.java:134)
    at io.netty.channel.nio.NioEventLoopGroup.newChild(NioEventLoopGroup.java:127)
    at io.netty.channel.nio.NioEventLoopGroup.newChild(NioEventLoopGroup.java:36)
    at io.netty.util.concurrent.MultithreadEventExecutorGroup.<init>(MultithreadEventExecutorGroup.java:84)
    at io.netty.util.concurrent.MultithreadEventExecutorGroup.<init>(MultithreadEventExecutorGroup.java:58)
    at io.netty.channel.MultithreadEventLoopGroup.<init>(MultithreadEventLoopGroup.java:52)
    at io.netty.channel.nio.NioEventLoopGroup.<init>(NioEventLoopGroup.java:87)
    at io.netty.channel.nio.NioEventLoopGroup.<init>(NioEventLoopGroup.java:82)
    at io.netty.channel.nio.NioEventLoopGroup.<init>(NioEventLoopGroup.java:63)
    at io.netty.channel.nio.NioEventLoopGroup.<init>(NioEventLoopGroup.java:51)
    at io.ktor.server.netty.EventLoopGroupProxy$Companion.create(NettyApplicationEngine.kt:187)
    at io.ktor.server.netty.NettyApplicationEngine.<init>(NettyApplicationEngine.kt:74)
    at io.ktor.server.netty.Netty.create(Embedded.kt:14)
    at io.ktor.server.netty.Netty.create(Embedded.kt:12)
    at io.ktor.server.engine.EmbeddedServerKt.embeddedServer(EmbeddedServer.kt:79)
    at io.ktor.server.engine.EmbeddedServerKt.embeddedServer(EmbeddedServer.kt:67)
    at io.ktor.server.engine.EmbeddedServerKt.embeddedServer(EmbeddedServer.kt:36)
    at io.ktor.server.engine.EmbeddedServerKt.embeddedServer$default(EmbeddedServer.kt:34)

Should be obsolete after the Netty update.

@e5l Sorry, but how does this Netty update fix split-package issue in Ktor itself (see my comment above on 17 May 2019)?

It's the separate problem and the origin was fixed. Could you file new ticket for that? I'll take a look

Please check the following ticket on YouTrack for follow-ups to this issue. GitHub issues will be closed in the coming weeks.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

PPACI picture PPACI  路  4Comments

diaodou picture diaodou  路  3Comments

baruchn picture baruchn  路  3Comments

seanf picture seanf  路  3Comments

ManifoldFR picture ManifoldFR  路  4Comments