Skip to content

[BUG] [Client] [Java] [Vertx] Current context may return NPE when creating new WebClient #8492

@ricardozanini

Description

@ricardozanini

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

Hi!

While testing the generated client code for the petstore.yaml example, the ApiClient.java code is returning NPEs the first time it tries to create a WebClient reference. More specifically here: https://github.com/OpenAPITools/openapi-generator/blob/master/modules/openapi-generator/src/main/resources/Java/libraries/vertx/ApiClient.mustache#L124-L132

Is there a reason to not use this.vertx.getOrCreateContext() instead? The vertx 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:

<build>
    <plugins>
      <plugin>
        <groupId>org.openapitools</groupId>
        <artifactId>openapi-generator-maven-plugin</artifactId>
        <version>${version.openapi.generator}</version>
        <executions>
          <execution>
            <id>default</id>
            <goals>
              <goal>generate</goal>
            </goals>
            <configuration>
              <inputSpec>${project.basedir}/src/main/resources/petstore.yaml</inputSpec>
              <generatorName>java</generatorName>
              <library>vertx</library>
              <configOptions>
                <dateLibrary>java8</dateLibrary>
              </configOptions>
              <apiPackage>${project.groupId}.client</apiPackage>
              <modelPackage>${project.groupId}.client</modelPackage>
              <invokerPackage>${project.groupId}.client</invokerPackage>
              <generateApiTests>false</generateApiTests>
              <generateModelTests>false</generateModelTests>
              <generateModelDocumentation>false</generateModelDocumentation>
              <generateApiDocumentation>false</generateApiDocumentation>
            </configuration>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>
Steps to reproduce
  1. Generate the Code
  2. Run the tests with Junit5 and Vertx 3.9.5 (https://vertx.io/docs/3.9.5/vertx-junit5/java/)
Related issues/PRs

There's none

Suggest a fix

Replace Vertx.currentContext with this.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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions