Skip to content
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

[JAVA] NullPointerException processing operation with string array body parameter #6122

Closed
tingley opened this issue Jul 19, 2017 · 2 comments

Comments

@tingley
Copy link

tingley commented Jul 19, 2017

Description

Release 2.2.3 crashes when processing our swagger.json. The stacktrace is:

  Exception: null
	at io.swagger.codegen.DefaultGenerator.processOperation(DefaultGenerator.java:861)
	at io.swagger.codegen.DefaultGenerator.processPaths(DefaultGenerator.java:764)
	at io.swagger.codegen.DefaultGenerator.generateApis(DefaultGenerator.java:388)
	at io.swagger.codegen.DefaultGenerator.generate(DefaultGenerator.java:700)
	at io.swagger.codegen.cmd.Generate.run(Generate.java:244)
	at io.swagger.codegen.SwaggerCodegen.main(SwaggerCodegen.java:43)
Caused by: java.lang.NullPointerException
	at io.swagger.codegen.languages.AbstractJavaCodegen.needToImport(AbstractJavaCodegen.java:912)
	at io.swagger.codegen.DefaultCodegen.fromOperation(DefaultCodegen.java:2219)
	at io.swagger.codegen.languages.AbstractJavaCodegen.fromOperation(AbstractJavaCodegen.java:974)
	at io.swagger.codegen.DefaultGenerator.processOperation(DefaultGenerator.java:808)
	... 5 more
Swagger-codegen version

2.2.3. This is a regression.

Swagger declaration file content or url

This is a slightly sanitized/abbreviated version of the JSON. The operation is a method that POSTs an array of string identifiers as body content. The JSON itself is being generated dynamically by an application.

    "/gizmo/{gizmoId}/add-widget": {
      "post": {
        "operationId": "addWidgets",
        "produces": [
          "application/json"
        ],
        "parameters": [
          {
            "name": "gizmoId",
            "in": "path",
            "required": true,
            "type": "integer",
            "format": "int64"
          },
          {
            "in": "body",
            "name": "body",
            "required": false,
            "schema": {
              "type": "array",
              "items": {
                "type": "string"
              }
            }
          }
        ],
      }
    },
Command line used for generation
swagger-codegen generate -l java \
    -o generated-classes --library jersey2 --invoker-package [invoker-package] \
    --model-package [model-package] --api-package [api-package] \
    --type-mappings "FormDataMultiPart=org.glassfish.jersey.media.multipart.FormDataMultiPart,FormDataBodyPart=org.glassfish.jersey.media.multipart.FormDataBodyPart,FormDataContentDisposition=org.glassfish.jersey.media.multipart.FormDataContentDisposition,BigDecimal=java.math.BigDecimal" \
    --import-mappings "JsonNode=com.fasterxml.jackson.databind.JsonNode,InputStream=java.io.InputStream" \
    -DsourceFolder=.,dateLibrary=joda
Steps to reproduce
  • Run swagger-codegen. The command fails with the exception noted above.
Related issues/PRs

Possibly issue #6098.

Suggest a fix/enhancement

git bisect indicates that this crash results from changes introduced in commit d35239c.

@tingley
Copy link
Author

tingley commented Jul 19, 2017

Looks like the problem is this line from commit d35239c. For arrays of native types, innerCp.complexType is null, but there's no null check here.

@tingley tingley changed the title [JAVA] NullPointerException importing body parameters [JAVA] NullPointerException processing operation with string array body parameter Jul 19, 2017
@tingley
Copy link
Author

tingley commented Jul 19, 2017

Oh wait, this is fixed as issue #6079,

@tingley tingley closed this as completed Jul 19, 2017
wing328 pushed a commit that referenced this issue Feb 1, 2018
Please use the latest version in the snippet as the older ones may contain nasty bugs (like this one #6122). Thanks.
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

1 participant