-
-
Notifications
You must be signed in to change notification settings - Fork 6.6k
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
[BUG] [Client] [Java] [Vertx] Current context may return NPE when creating new WebClient #8492
Comments
@ricardozanini thanks for reporting the issue. Please submit a PR to address these issues and we'll review accordingly. Let me know if you need help with the PR. |
@wing328 I've opened the PR (#8492), but it seems that we are lacking reviewers. Do you mind taking a look? Many thanks! 🙌 |
Thanks for the PR. Will try to review later today. |
@ricardozanini do you mind sharing more on how you reproduce the issue? We do have some tests in https://github.com/OpenAPITools/openapi-generator/blob/master/samples/client/petstore/java/vertx/src/test/java/org/openapitools/client/api/PetApiTest.java#L55-L61 so would appreciate if you can add some tests in that test file to catch the issue moving forward. |
@wing328, the error only occurs on JUnit 5 + Vertx 3.9.x. This test case of yours will always work. In the PR, I added a verification code to ensure the Vertx context is never null. Instead of using the static class, we use the one provided by the constructor. You would need to create a JUnit test like this one: Since our project here uses Junit 4, we won't catch the problem. I don't think we need another unit test. What would be great is to upgrade to JUnit 5 and Vertx 4.x. I can do it another time. |
@ricardozanini thanks for the explanation. I've merged your fix. Can you please file a PR to upgrade dependencies to JUnit 5 and Vertx 4.x when you've time? |
@wing328 of course, I'll do it. Should I open an issue first? |
Up to you. You can also link the PR to the discussion here |
Bug Report Checklist
Description
Hi!
While testing the generated client code for the
petstore.yaml
example, theApiClient.java
code is returning NPEs the first time it tries to create aWebClient
reference. More specifically here: https://github.com/OpenAPITools/openapi-generator/blob/master/modules/openapi-generator/src/main/resources/Java/libraries/vertx/ApiClient.mustache#L124-L132Is there a reason to not use
this.vertx.getOrCreateContext()
instead? Thevertx
attribute is final. I can send a small PR to fix this, but I'd like to hear from the contributors first.openapi-generator version
5.0.0
OpenAPI declaration file content or URL
Tested with
petstore.yaml
simple example.Generation Details
Here's my plugin configuration:
Steps to reproduce
Related issues/PRs
There's none
Suggest a fix
Replace
Vertx.currentContext
withthis.vertx.getOrCreateContext()
By the way, I see that the server-side was upgraded to Vertx 4 (#7352). Don't we need to upgrade the client code as well? I can also send a PR for this purpose.
The text was updated successfully, but these errors were encountered: