OpenAPITools / OpenAPITools/openapi-generator
[BUG][JAVA][JERSEY3] Generated Jersey3 Clients throw java.lang.reflect.InaccessibleObjectException when Calling Endpoint using PATCH
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 26.8k
- Forks
- 7.7k
- PR merge metrics
- PR metrics pending
Description
Bug Report Checklist
- Have you provided a full/minimal spec to reproduce the issue?
- Have you validated the input using an OpenAPI validator (example)?
- Have you tested with the latest master to confirm the issue still exists?
- Have you searched for related issues/PRs?
- What's the actual output vs expected output?
- [Optional] Sponsorship to speed up the bug fix or feature request (example)
Description
Calling a Rest Endpoint using PATCH yields an InaccessibleObjectException:
jakarta.ws.rs.ProcessingException: java.lang.reflect.InaccessibleObjectException: Unable to make field protected java.lang.String java.net.HttpURLConnection.method accessible: module java.base does not "opens java.net" to unnamed module @2de8284b
at org.glassfish.jersey.client.ClientRuntime.invoke(ClientRuntime.java:309)
at org.glassfish.jersey.client.JerseyInvocation.lambda$invoke$0(JerseyInvocation.java:662)
at org.glassfish.jersey.client.JerseyInvocation.call(JerseyInvocation.java:697)
at org.glassfish.jersey.client.JerseyInvocation.lambda$runInScope$3(JerseyInvocation.java:691)
at org.glassfish.jersey.internal.Errors.process(Errors.java:292)
at org.glassfish.jersey.internal.Errors.process(Errors.java:274)
at org.glassfish.jersey.internal.Errors.process(Errors.java:205)
at org.glassfish.jersey.process.internal.RequestScope.runInScope(RequestScope.java:390)
at org.glassfish.jersey.client.JerseyInvocation.runInScope(JerseyInvocation.java:691)
at org.glassfish.jersey.client.JerseyInvocation.invoke(JerseyInvocation.java:661)
at org.glassfish.jersey.client.JerseyInvocation$Builder.method(JerseyInvocation.java:439)
at de.db.remote.integrationtests.generated.api.echo.api.invoker.ApiClient.sendRequest(ApiClient.java:1077)
at de.db.remote.integrationtests.generated.api.echo.api.invoker.ApiClient.invokeAPI(ApiClient.java:1031)
at de.db.remote.integrationtests.generated.api.echo.api.EchoApi.echoSomethingWithHttpInfo(EchoApi.java:184)
at de.db.remote.integrationtests.generated.api.echo.api.EchoApi.echoSomething(EchoApi.java:127)
at de.db.remote.integrationtests.steps.fk.EchoSteps.iSendTheMessageUsingTheCreatedEchoId(EchoSteps.java:44)
at ?.I Send the message "Hell on earth" using the created echoId(classpath:features/UC-1_Echo_a_Message.feature:20)
Caused by: java.lang.RuntimeException: java.lang.reflect.InaccessibleObjectException: Unable to make field protected java.lang.String java.net.HttpURLConnection.method accessible: module java.base does not "opens java.net" to unnamed module @2de8284b
at org.glassfish.jersey.client.internal.HttpUrlConnector$3.run(HttpUrlConnector.java:520)
at java.base/java.security.AccessController.doPrivileged(AccessController.java:569)
at org.glassfish.jersey.client.internal.HttpUrlConnector.setRequestMethodViaJreBugWorkaround(HttpUrlConnector.java:481)
at org.glassfish.jersey.client.internal.HttpUrlConnector._apply(HttpUrlConnector.java:325)
at org.glassfish.jersey.client.internal.HttpUrlConnector.apply(HttpUrlConnector.java:267)
at org.glassfish.jersey.client.ClientRuntime.invoke(ClientRuntime.java:297)
at org.glassfish.jersey.client.JerseyInvocation.lambda$invoke$0(JerseyInvocation.java:662)
at org.glassfish.jersey.client.JerseyInvocation.call(JerseyInvocation.java:697)
at org.glassfish.jersey.client.JerseyInvocation.lambda$runInScope$3(JerseyInvocation.java:691)
at org.glassfish.jersey.internal.Errors.process(Errors.java:292)
at org.glassfish.jersey.internal.Errors.process(Errors.java:274)
at org.glassfish.jersey.internal.Errors.process(Errors.java:205)
at org.glassfish.jersey.process.internal.RequestScope.runInScope(RequestScope.java:390)
at org.glassfish.jersey.client.JerseyInvocation.runInScope(JerseyInvocation.java:691)
at org.glassfish.jersey.client.JerseyInvocation.invoke(JerseyInvocation.java:661)
at org.glassfish.jersey.client.JerseyInvocation$Builder.method(JerseyInvocation.java:439)
at de.db.remote.integrationtests.generated.api.echo.api.invoker.ApiClient.sendRequest(ApiClient.java:1077)
at de.db.remote.integrationtests.generated.api.echo.api.invoker.ApiClient.invokeAPI(ApiClient.java:1031)
at de.db.remote.integrationtests.generated.api.echo.api.EchoApi.echoSomethingWithHttpInfo(EchoApi.java:184)
at de.db.remote.integrationtests.generated.api.echo.api.EchoApi.echoSomething(EchoApi.java:127)
at de.db.remote.integrationtests.steps.fk.EchoSteps.iSendTheMessageUsingTheCreatedEchoId(EchoSteps.java:44)
at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:104)
at java.base/java.lang.reflect.Method.invoke(Method.java:577)
at io.cucumber.java.Invoker.doInvoke(Invoker.java:66)
[...]
Caused by: java.lang.reflect.InaccessibleObjectException: Unable to make field protected java.lang.String java.net.HttpURLConnection.method accessible: module java.base does not "opens java.net" to unnamed module @2de8284b
at java.base/java.lang.reflect.AccessibleObject.checkCanSetAccessible(AccessibleObject.java:354)
at java.base/java.lang.reflect.AccessibleObject.checkCanSetAccessible(AccessibleObject.java:297)
at java.base/java.lang.reflect.Field.checkCanSetAccessible(Field.java:180)
at java.base/java.lang.reflect.Field.setAccessible(Field.java:174)
at org.glassfish.jersey.client.internal.HttpUrlConnector$3.run(HttpUrlConnector.java:515)
... 107 more
openapi-generator version
Generator Maven Plugin Version: 6.0.1
OpenAPI declaration file content or url
Json Snipped of example PATCH endpoint:
"/echos/{echoId}": {
"patch": {
"tags": [
"echo"
],
"summary": "echo a message",
"operationId": "echoSomething",
"parameters": [
{
"name": "echoId",
"in": "path",
"required": true,
"schema": {
"type": "string"
}
}
],
"requestBody": {
"content": {
"text/plain": {
"schema": {
"type": "string"
}
}
},
"required": true
},
"responses": {
"200": {
"description": "OK",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/EchoMessage"
}
}
}
}
}
}
}
Full Swagger Json:
https://gist.github.com/FlorianKaemmerer/e7e973d2c53aa4d96d1422c0b51697d9
Generation Details
Java Version: 17
Relevant Dependencies:
<dependency>
<groupId>com.fasterxml.jackson.datatype</groupId>
<artifactId>jackson-datatype-jdk8</artifactId>
<version>2.13.3</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.core</groupId>
<artifactId>jersey-client</artifactId>
<version>3.1.0-M3</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.media</groupId>
<artifactId>jersey-media-multipart</artifactId>
<version>3.1.0-M3</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.media</groupId>
<artifactId>jersey-media-json-jackson</artifactId>
<version>3.1.0-M3</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.inject</groupId>
<artifactId>jersey-hk2</artifactId>
<version>3.1.0-M3</version>
</dependency>
<dependency>
<groupId>jakarta.annotation</groupId>
<artifactId>jakarta.annotation-api</artifactId>
<version>2.1.1</version>
</dependency>
Plugin configuration:
<plugin>
<groupId>org.openapitools</groupId>
<artifactId>openapi-generator-maven-plugin</artifactId>
<version>6.0.1</version>
<configuration>
<inputSpec>${project.basedir}/echo.json</inputSpec>
<generatorName>java</generatorName>
<generateModelTests>false</generateModelTests>
<generateApiTests>false</generateApiTests>
<generateModelTests>false</generateModelTests>
<generateModelDocumentation>false</generateModelDocumentation>
<additionalProperties>failOnEmptyBeans=false</additionalProperties>
<configOptions>
<library>jersey3</library>
<hideGenerationTimestamp>true</hideGenerationTimestamp>
<delegatePattern>true</delegatePattern>
<java8>true</java8>
<dateLibrary>java8</dateLibrary>
<openApiNullable>false</openApiNullable>
<oas3>true</oas3>
</configOptions>
</configuration>
<executions>
<execution>
<id>echo-api</id>
<goals>
<goal>generate</goal>
</goals>
</execution>
</executions>
</plugin>
Steps to reproduce
Compile Client
Call "/echos/{echoid}" using PATCH
Related issues/PRs
No relevant Issues found
Suggest a fix
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the generated Jersey3 client on Java 17 by calling the PATCH endpoint, then inspect ApiClient.sendRequest and the Jersey HttpUrlConnector stack shown in the report. Done means the generated client can invoke PATCH without InaccessibleObjectException, with a regression test covering the reported endpoint and runtime combination.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- api, tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100