Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

NPE at ModelImpl #6259

Open
dantran opened this issue Aug 8, 2017 · 4 comments
Open

NPE at ModelImpl #6259

dantran opened this issue Aug 8, 2017 · 4 comments

Comments

@dantran
Copy link
Contributor

dantran commented Aug 8, 2017

Hi

I currently facing this stack trace

java.lang.RuntimeException: Could not process operation:
  Tag: AssetGroups
  Operation: addAssets
  Resource: put /api/v2/assetGroups/{id}/assetList
  Definitions: {Addresses=io.swagger.models.ModelImpl@9901aa0, 
AppHost=io.swagger.models.ModelImpl@8456d641, ....
  Exception: null
        at io.swagger.codegen.DefaultGenerator.processOperation(DefaultGenerator.java:861)
        at io.swagger.codegen.DefaultGenerator.processPaths(DefaultGenerator.java:763)
       at io.swagger.codegen.DefaultGenerator.generateApis(DefaultGenerator.java:388)
       at io.swagger.codegen.DefaultGenerator.generate(DefaultGenerator.java:700)

after upgrading from swagger-codegen-maven-plugin 2.2.2 to 2.2.3 where I generate java source from swagger spec

Need suggestion on how to look for abnormalities in my swagger spec file which can cause this issue ( or this can just be regression )

Thanks

Swagger-codegen version

2.2.3

@anweiss
Copy link

anweiss commented Aug 10, 2017

Also seeing this issue with swagger-codegen 2.2.3.

@jimschubert
Copy link
Contributor

jimschubert commented Aug 17, 2017

The line at the top of your is thrown here.

If you think your swagger spec is failing validation now, you can validate via command line.

This is the command (installed from brew install swagger-codegen on mac)

$ swagger-codegen help validate
NAME
        swagger-codegen-cli validate - Validate specification

SYNOPSIS
        swagger-codegen-cli validate (-i <spec file> | --input-spec <spec file>)

OPTIONS
        -i <spec file>, --input-spec <spec file>
            location of the swagger spec, as URL or file (required)

If your spec passes validation, I'd recommend debugging locally. The maven plugin is just a maven options wrapper around swagger-codgen's core, which you can also access via swagger-codegen-cli. Here are the steps if you're not familiar with it (I'm assuming you have IntelliJ available if you're using the maven plugin):

  • clone the repo
  • git checkout v2.2.3
  • compile: mvn clean package -Dmaven.test.skip=true -DskipTests
  • setup remote debugging to wait until a debugger is attached. I use the command:
    export JAVA_OPTS="-agentlib:jdwp=transport=dt_socket,server=y,address=5009,suspend=y"
  • In IntelliJ, create a new remote debugging configuration (see IntelliJ docs), and point to the address from the previous bullet (5009)
  • Set a breakpoint in DefaultGenerator.java
  • Run your codegen (from cloned repo's root):
    java $JAVA_OPTS -jar ./modules/swagger-codegen-cli/target/swagger-codegen-cli.jar \
        generate -i yourswagger.json -l java -o ./output #etc
    
  • Run the remote debugger configuration in IntelliJ and step through the debugger
  • When you're done, unset the JAVA_OPTS variable or close your shell session 💃

For 2.2.3, swagger parser and swagger core dependencies were updated (commit). It's possible the NPE is from a type pulled in from there. I did some investigation into DefaultGenerator.java changes between 2.2.2 and 2.2.3, and I don't see anywhere that a NPE would have been introduced.

I hope that helps.

@bingshiao
Copy link

Looks like it has been fixed right after v2.2.3 release.

#6079

The coming v2.3.0 should be fine.

@dantran
Copy link
Contributor Author

dantran commented Aug 17, 2017

@codegen dev, any plan to backport this fix to 2.2x branch and release with 2.2.4?

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants