khttp icon indicating copy to clipboard operation
khttp copied to clipboard

Illegal reflective access on khttp.requests.GenericRequest

Open caoimhebyrne opened this issue 3 years ago • 1 comments

Description The class khttp.requests.GenericRequest uses reflection to access the setter for URL#host and URL#authority image

On JDK 11+, this causes a warning to be printed to the console, which will turn into an exception in the future. image

This can be fixed by changing the method to something like:

private fun URL.toIDN(): URL {
    val newHost = IDN.toASCII(this.host)
    // Not sure how to fix this one
    // 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) {
        null
    } else {
        URLDecoder.decode(this.query, "UTF-8")
    }
    return URL(URI(this.protocol, this.userInfo, newHost, this.port, this.path, query, this.ref).toASCIIString())
}

I am unsure how to change authority from using reflection. If anyone has any ideas please let me know.

caoimhebyrne avatar Apr 04 '21 16:04 caoimhebyrne

@cbyrneee Is this project abandonware? I'm thinking I should move my code to something more well supported. What did you end up doing?

mjaggard avatar Mar 03 '22 17:03 mjaggard