Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
dotoole opened this issue Jan 9, 2023 · 2 comments
Closed

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

dotoole opened this issue Jan 9, 2023 · 2 comments

Comments

@dotoole
Copy link

dotoole commented Jan 9, 2023

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

// HttpURLConnection enforces a list of official http METHODs, but not everyone abides by the spec

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

@SethTisue
Copy link

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

@lihaoyi
Copy link
Member

lihaoyi commented Jun 16, 2024

Should be fixed by #158 I think

@lihaoyi lihaoyi closed this as completed Jun 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants