Skip to content

JavaClientCodegen: NullPointerException when using minimum/maximum #1143

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

Closed
ePaul opened this issue Aug 27, 2015 · 2 comments
Closed

JavaClientCodegen: NullPointerException when using minimum/maximum #1143

ePaul opened this issue Aug 27, 2015 · 2 comments

Comments

@ePaul
Copy link
Contributor

ePaul commented Aug 27, 2015

Summary
When using the min or max constraint for a property, JavaClientCodegen.postProcessModelMaps throws an exception.

This happens with current master (also using current master of swagger-core).

Reproducible by

bug-trigger.yaml:

swagger: '2.0'
info:
  title: Swagger Codegen bug trigger
  description: |
     This demonstrates a bug in swagger-codegen.
  version: 0.0.1
basePath: /api
definitions:
  manual_discount:
    type: object
    properties:
      percent_value:
        type: number
        minimum: 0.0
        maximum: 100.0

command line (with debugger):

java -XX:-OmitStackTraceInFastThrow \
-agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=8000 \
-jar /home/paulo/.m2/repository/io/swagger/swagger-codegen-cli/2.1.4-SNAPSHOT/swagger-codegen-cli-2.1.4-SNAPSHOT.jar \
generate -i src/main/resources/api/bug-trigger.yaml -l java \
-o target/generated-sources/swagger-codegen

This finishes without ouputting anything or writing any file.

Analysis
A breakpoint in DefaultGenerator.generate, line 322 shows a NullPointerException.

This exception is thrown in JavaClientCodegen.postProcessModels(), line 335: Here we try to iterate over a null list. That null list comes from allowableValues.get("values"), which for a string property could contain the values from an enum constraint. In this case, allowableValues is just a map with the min and max constraints.

Excepted behavior
This should generate a file for class ManualDiscount with a percentValue property.

Workaround
Don't use min or max.

@ePaul
Copy link
Contributor Author

ePaul commented Aug 27, 2015

The code throwing the exception was added in #1126.
Adding another null-check here should be enough, I'll try to create a pull request for that.

ePaul added a commit to ePaul/swagger-codegen that referenced this issue Aug 27, 2015
The problem was trying to iterate over a null list.
ePaul added a commit to ePaul/swagger-codegen that referenced this issue Aug 28, 2015
The problem was trying to iterate over a null list.
wing328 added a commit that referenced this issue Sep 1, 2015
@wing328
Copy link
Contributor

wing328 commented Sep 9, 2015

PR merged

@wing328 wing328 closed this as completed Sep 9, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants