requests-scala icon indicating copy to clipboard operation
requests-scala copied to clipboard

Cannot use HTTP PATCH on JRE version >= 9

Open dotoole opened this issue 2 years ago • 1 comments

When using requests.patch(), the following error is thrown running on JRE 17

Unable to make field private final sun.net.www.protocol.https.DelegateHttpsURLConnection sun.net.www.protocol.https.HttpsURLConnectionImpl.delegate accessible: module java.base does not "opens sun.net.www.protocol.https" to unnamed module @4f9e5d6a
--
Exception: | java.lang.reflect.InaccessibleObjectException
java.base/java.lang.reflect.AccessibleObject.checkCanSetAccessible(AccessibleObject.java:354)
java.base/java.lang.reflect.AccessibleObject.checkCanSetAccessible(AccessibleObject.java:297)
java.base/java.lang.reflect.Field.checkCanSetAccessible(Field.java:178)
java.base/java.lang.reflect.Field.setAccessible(Field.java:172)
requests.Requester$$anon$1.$anonfun$readBytesThrough$2(Requester.scala:214)
requests.Requester$$anon$1.$anonfun$readBytesThrough$2$adapted(Requester.scala:213)
scala.Option.foreach(Option.scala:437)
requests.Requester$$anon$1.readBytesThrough(Requester.scala:213)
geny.Readable.writeBytesTo(Writable.scala:93)
geny.Readable.writeBytesTo$(Writable.scala:93)
requests.Requester$$anon$1.writeBytesTo(Requester.scala:164)
requests.Requester.apply(Requester.scala:113)

This is due to the workaround here https://github.com/com-lihaoyi/requests-scala/blob/ac506a50267ede978061e62c2a4a3e41ad7f1264/requests/src/requests/Requester.scala#L209 trying to access the underlying implementation of HttpURLConnection, which in this case is sun.net.www.protocol.https.DelegateHttpsURLConnection. The sun.net classes have been not exported for external use since Java 9.

The correct approach seems to be to switch to the HttpClient API as it does not restrict HTTP methods https://bugs.openjdk.org/browse/JDK-7016595

dotoole avatar Jan 09 '23 15:01 dotoole