Skip to content

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

Closed
@dotoole

Description

@dotoole

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions