question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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

See original GitHub issue

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.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:8 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
wing328commented, Jan 28, 2021

Up to you. You can also link the PR to the discussion here

1reaction
wing328commented, Jan 28, 2021

@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?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Vert.x Web Client
The Web Client does not deprecate the Vert.x Core HttpClient , indeed it is based on this client and inherits its configuration and...
Read more >
java.lang.NullPointerException at org.vertx.java.core.http.impl ...
Hi, i'm getting this error when using an http client from within vertx when it is processing http responses. It might mean i...
Read more >
Java agent v4.11.0 | New Relic Documentation
The Java agent now provides visibility into your applications built using the Vert.x 3.6. The agent instruments Vert.x Web, Vert.x Core, ...
Read more >
Release Notes Red Hat JBoss Fuse 6.1
For the detailed solution, see the following Customer Portal article: Cannot create fabric in JBoss Fuse 6.1 Beta on Windows 7.
Read more >
java - random NullPointerException / onErrorDropped using ...
So it looks like request.getSession() returns null... but I have no idea why, and I am not able to find a pattern. Sometimes...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found