khttp
khttp copied to clipboard
Illegal access with Java 9
When running with java 9 you get the following warning:
WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by khttp.requests.GenericRequest (file:/C:/Users/Torben/.m2/repository/khttp/khttp/0.1.0/khttp-0.1.0.jar) to field java.net.URL.host
WARNING: Please consider reporting this to the maintainers of khttp.requests.GenericRequest
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
I too am affected by this issue.
I found this warning too
WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by khttp.requests.GenericRequest (file:/home/sherlock/.gradle/caches/modules-2/files-2.1/khttp/khttp/0.1.0/810c5e89d44b032c2d079aa1c05230e5e7cfcc81/khttp-0.1.0.jar) to field java.net.URL.host
WARNING: Please consider reporting this to the maintainers of khttp.requests.GenericRequest
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
Any update on this?
This does not seem to happen with Java 8, but does with newer versions
This does not seem to happen with Java 8, but does with newer versions
Yes, as stated in the title of the issue. But the current LTS version of java is 11, so it'd be nice being able to use it.
Any update? still getting it using java 11
Still getting this with 1.0.0:
WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by khttp.requests.GenericRequest (file:/home/gradle/.gradle/caches/modules-2/files-2.1/khttp/khttp/1.0.0/91b746489c4e55d44847d978c66cfbea91d84a62/khttp-1.0.0.jar) to field java.net.URL.host
WARNING: Please consider reporting this to the maintainers of khttp.requests.GenericRequest
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
The issue is the reflection code in this function:
private fun URL.toIDN(): URL {
val newHost = IDN.toASCII(this.host)
this.javaClass.getDeclaredField("host").apply { this.isAccessible = true }.set(this, newHost)
this.javaClass.getDeclaredField("authority").apply { this.isAccessible = true }.set(this, if (this.port == -1) this.host else "${this.host}:${this.port}")
The code is taking a URL that already has been constructed in makeRoute
private fun makeRoute(route: String) = URL(route + if (this.params.isNotEmpty()) "?${Parameters(this.params)}" else "").toIDN().toString()
and making the host and authority fields accessible so it can replace the host passed in with an IDN version.
A fix should eliminate the reflection code and construct the URL with an already modified host instead.
I can't get the existing Maven build of this project to run successfully. There are breaking tests on a freshly checked out copy of the project. Any fix should be along these lines (code untested due to above build problems):
private fun makeRoute(route: String): String {
val tempURL = URL(route + if (this.params.isNotEmpty()) "?${Parameters(this.params)}" else "")
val newHost = IDN.toASCII(tempURL.host)
val query = if (tempURL.query == null) {
null
} else {
URLDecoder.decode(tempURL.query, "UTF-8")
}
with(tempURL) {
return URL(URI(protocol, userInfo, newHost, port, path, query, ref).toASCIIString()).toString()
}
}
The above as a patch:
Index: src/main/kotlin/khttp/requests/GenericRequest.kt
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
--- src/main/kotlin/khttp/requests/GenericRequest.kt (revision 130b89ca9007fb2a03af85d71ecfcde617d0c909)
+++ src/main/kotlin/khttp/requests/GenericRequest.kt (date 1578838350218)
@@ -193,18 +193,20 @@
return stringWriter.toString()
}
- private fun URL.toIDN(): URL {
- val newHost = IDN.toASCII(this.host)
- this.javaClass.getDeclaredField("host").apply { this.isAccessible = true }.set(this, newHost)
- this.javaClass.getDeclaredField("authority").apply { this.isAccessible = true }.set(this, if (this.port == -1) this.host else "${this.host}:${this.port}")
- val query = if (this.query == null) {
+
+
+ private fun makeRoute(route: String): String {
+
+ val tempURL = URL(route + if (this.params.isNotEmpty()) "?${Parameters(this.params)}" else "")
+ val newHost = IDN.toASCII(tempURL.host)
+ val query = if (tempURL.query == null) {
null
} else {
- URLDecoder.decode(this.query, "UTF-8")
+ URLDecoder.decode(tempURL.query, "UTF-8")
}
- return URL(URI(this.protocol, this.userInfo, this.host, this.port, this.path, query, this.ref).toASCIIString())
+ with(tempURL) {
+ return URL(URI(protocol, userInfo, newHost, port, path, query, ref).toASCIIString()).toString()
+ }
}
-
- private fun makeRoute(route: String) = URL(route + if (this.params.isNotEmpty()) "?${Parameters(this.params)}" else "").toIDN().toString()
}
Thanks @paulnuk!
Although I'm afraid we should consider this project discontinued. The build has been failing for eight months now.
Thanks @paulnuk!
Although I'm afraid we should consider this project discontinued. The build has been failing for eight months now.
Well either we can count this project as dead (what are the alternatives) or fix it.
I'm happy to look at trying to do the fix, and fix the build whilst I'm at it, though that may involve a migration to Gradle Kotlin DSL whilst I'm at it.
Are people still interested in the fix?
So, any chance this can be fixed? :(
Thanks @paulnuk! Although I'm afraid we should consider this project discontinued. The build has been failing for eight months now.
Well either we can count this project as dead (what are the alternatives) or fix it.
I'm happy to look at trying to do the fix, and fix the build whilst I'm at it, though that may involve a migration to Gradle Kotlin DSL whilst I'm at it.
Are people still interested in the fix?
yes
Yep, having recently upgraded to java 15, yes, I'd love this fixed. KHttp is an awesome addition to my development. Would be great to have this fixed.
yes it would be nice to fix this, khttp is great!
3 years after reported and the last comment is "it would be nice to fix this", this is no bueno
Has anybody forked this and made a fixed version yet?