khttp icon indicating copy to clipboard operation
khttp copied to clipboard

HTTP Put results in "Unable to make field private java.lang.String java.net.URL.host accessible: module java.base does not "opens java.net" to unnamed"

Open maheshreddy77 opened this issue 1 year ago • 4 comments

khttp version is 1.0.0

When calling HTTP PUT to a url, i keep getting below error

java.lang.reflect.InaccessibleObjectException: Unable to make field private java.lang.String java.net.URL.host accessible: module java.base does not "opens java.net" to unnamed module @5f5a92bb
        at java.base/java.lang.reflect.AccessibleObject.checkCanSetAccessible(AccessibleObject.java:354) ~[na:na]
        at java.base/java.lang.reflect.AccessibleObject.checkCanSetAccessible(AccessibleObject.java:297) ~[na:na]
        at java.base/java.lang.reflect.Field.checkCanSetAccessible(Field.java:178) ~[na:na]
        at java.base/java.lang.reflect.Field.setAccessible(Field.java:172) ~[na:na]
        at khttp.requests.GenericRequest.toIDN(GenericRequest.kt:198) ~[khttp-1.0.0.jar!/:na]
        at khttp.requests.GenericRequest.makeRoute(GenericRequest.kt:208) ~[khttp-1.0.0.jar!/:na]
        at khttp.requests.GenericRequest.<init>(GenericRequest.kt:132) ~[khttp-1.0.0.jar!/:na]
        at khttp.KHttp.request(KHttp.kt:60) ~[khttp-1.0.0.jar!/:na]
        at khttp.KHttp.put(KHttp.kt:55) ~[khttp-1.0.0.jar!/:na]
        at khttp.KHttp.put$default(KHttp.kt:54) ~[khttp-1.0.0.jar!/:na]
        at ai.paravision.mozart.orchestrator.worker.WorkerClient.search$suspendImpl(WorkerClient.kt:29) ~[classes!/:0.0.0]

maheshreddy77 avatar Jul 18 '22 18:07 maheshreddy77

I have the same issue

Georglider avatar Aug 23 '22 16:08 Georglider

Use JDK 1.8

Jetug avatar Aug 25 '22 07:08 Jetug

not work for me, any other solution?

HagiCohn avatar Sep 18 '22 08:09 HagiCohn

Hi @maheshreddy77, @Georglider, @Jetug and @HagiCohn, I had the same issue and could not find a soluton - but I was successful, eventually.

The root of the problem is the JDK version, from 16.0 or 17.0 on it consequently denies "illegal reflective access" - before, for instance with JDK 11.0, it was possible to ignore or allow those accesses via VM argument (--illegal-access={warn, deny, permit})

Now it is possible only via another VM argument or a list of those, you can just refer to the error message and adjust accordingly. For enabling khttp 1.0 with JDK 17.0 I use these VM arguments:

--add-opens java.base/java.net=ALL.UNNAMED --add-opens java.base/sun.net.www.protocol.https=ALL-UNNAMED

Hope, this was of little help.

PS: The author should make the code compatible with JDK 16.0+ or mention it in the install/setup notes, cc @ascclemens

repodiac avatar Sep 30 '22 08:09 repodiac

This is because of JDK 9's modularity (JigSaw).

As mentioned, the author should fix this, preferrably by not using internal JDK API (not intended to be used).

OndraZizka avatar Oct 24 '22 22:10 OndraZizka

    private fun URL.toIDN(): URL {
        val newHost = IDN.toASCII(this.host)
        //val url = URL(this.protocol, newHost, port, this.file)

        val query = this.query ?. let { URLDecoder.decode(it, "UTF-8") }
        return URL(URI(this.protocol, this.userInfo, newHost, this.port, this.path, query, this.ref).toASCIIString())
    }

OndraZizka avatar Oct 25 '22 00:10 OndraZizka

The PR should fix it. Pity that the project is likely dormant :)

OndraZizka avatar Oct 25 '22 00:10 OndraZizka

@ascclemens , Would you allow to publish this into Maven central under ch.zizka.khttp ?

OndraZizka avatar Oct 25 '22 00:10 OndraZizka