swagger-api / swagger-api/swagger-codegen

[Java] unnecessary printStackTrace

Open
#11,016 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Mustache
Stars
17.8k
Forks
6k
PR merge metrics
No merged PRs in 30d

Description

Description

In certain conditions, when rendering of a specification fails, Codegen log exception's stack trace to stdout. This happen through an ex.printStackTrace(); in the DefaultGenerator class.
This print is calling directly the stdout stream creating an unnecessary log once this printStackTrace should be catch as an exception and logged properly.

} catch (Exception ex) {
    ex.printStackTrace();
    String msg = "Could not process operation:\n" //
            + "  Tag: " + tag + "\n"//
            + "  Operation: " + operation.getOperationId() + "\n" //
            + "  Resource: " + httpMethod + " " + resourcePath + "\n"//
           // + "  Definitions: " + swagger.getDefinitions() + "\n"  //
            + "  Exception: " + ex.getMessage();
    throw new RuntimeException(msg, ex);
}

The offending line that logs stack trace to stdout is the ex.printStackTrace(); in uk/nhs/digital/apispecs/swagger/CodegenDefaultGenerator.java:144;

This printStackTrace is not present in the 2.X version.

Swagger-codegen version

3.0.25

Steps to reproduce

When rendering of a specification fails due to schemas being referenced rather than embedded, the resulting NullPointerException's stack trace

Suggest a fix/enhancement

Remove the stackTrace line and the user must catch the exception and print it as desire.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Open uk/nhs/digital/apispecs/swagger/CodegenDefaultGenerator.java around line 144 and compare the handling with the 2.X version. Confirm that rendering failures no longer write a stack trace directly to stdout while the existing exception message and cause remain available to the caller.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
tooling
Issue type
Bug
Difficulty
1/5
Estimated time
Under an hour
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
55/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.