lihaoyi / test

0 stars 0 forks source link

Cannot use HTTP PATCH on JRE version >= 9 #652

Open lihaoyi opened 1 month ago

lihaoyi commented 1 month ago

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

ID: 123 Original Author: dotoole

lihaoyi commented 1 month ago

as a workaround, maybe you could call .post instead of .patch but also supply headers = Map("X-HTTP-Method-Override" -> "PATCH")? Original Author:SethTisue