khttp
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"
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]
I have the same issue
Use JDK 1.8
not work for me, any other solution?
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
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).
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())
}
The PR should fix it. Pity that the project is likely dormant :)
@ascclemens , Would you allow to publish this into Maven central under ch.zizka.khttp ?