Skip to content

Thrown java.lang.NoClassDefFoundError when reading 3.0.1 spec, v2.1.1 #1783

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
spacether opened this issue Aug 8, 2022 · 1 comment
Closed

Comments

@spacether
Copy link
Contributor

Thrown java.lang.NoClassDefFoundError when reading spec, v2.1.1
When parsing a local spec file java throws an exception:
Error

# Created at 2022-08-08T10:33:00.158
org.testng.TestNGException: 
Cannot instantiate class org.openapitools.codegen.kotlin.KotlinReservedWordsTest
	at org.testng.internal.objects.InstanceCreator.newInstance(InstanceCreator.java:41)
	at org.testng.ITestObjectFactory.newInstance(ITestObjectFactory.java:18)
	at org.testng.internal.objects.SimpleObjectDispenser.instantiateUsingDefaultConstructor(SimpleObjectDispenser.java:178)
	at org.testng.internal.objects.SimpleObjectDispenser.createInstance(SimpleObjectDispenser.java:87)
	at org.testng.internal.objects.SimpleObjectDispenser.dispense(SimpleObjectDispenser.java:40)
	at org.testng.internal.objects.GuiceBasedObjectDispenser.dispense(GuiceBasedObjectDispenser.java:28)
	at org.testng.internal.ClassImpl.getDefaultInstance(ClassImpl.java:106)
	at org.testng.internal.ClassImpl.getInstances(ClassImpl.java:136)
	at org.testng.TestClass.getInstances(TestClass.java:129)
	at org.testng.TestClass.initTestClassesAndInstances(TestClass.java:109)
	at org.testng.TestClass.init(TestClass.java:101)
	at org.testng.TestClass.<init>(TestClass.java:66)
	at org.testng.TestRunner.initMethods(TestRunner.java:465)
	at org.testng.TestRunner.init(TestRunner.java:333)
	at org.testng.TestRunner.init(TestRunner.java:286)
	at org.testng.TestRunner.<init>(TestRunner.java:176)
	at org.testng.SuiteRunner$DefaultTestRunnerFactory.newTestRunner(SuiteRunner.java:635)
	at org.testng.SuiteRunner.init(SuiteRunner.java:221)
	at org.testng.SuiteRunner.<init>(SuiteRunner.java:114)
	at org.testng.TestNG.createSuiteRunner(TestNG.java:1342)
	at org.testng.TestNG.createSuiteRunners(TestNG.java:1318)
	at org.testng.TestNG.runSuitesLocally(TestNG.java:1160)
	at org.testng.TestNG.runSuites(TestNG.java:1092)
	at org.testng.TestNG.run(TestNG.java:1060)
	at org.apache.maven.surefire.testng.TestNGExecutor.run(TestNGExecutor.java:151)
	at org.apache.maven.surefire.testng.TestNGDirectoryTestSuite.executeMulti(TestNGDirectoryTestSuite.java:192)
	at org.apache.maven.surefire.testng.TestNGDirectoryTestSuite.execute(TestNGDirectoryTestSuite.java:93)
	at org.apache.maven.surefire.testng.TestNGProvider.invoke(TestNGProvider.java:155)
	at org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:456)
	at org.apache.maven.surefire.booter.ForkedBooter.execute(ForkedBooter.java:169)
	at org.apache.maven.surefire.booter.ForkedBooter.run(ForkedBooter.java:595)
	at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:581)
Caused by: java.lang.reflect.InvocationTargetException
	at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
	at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
	at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
	at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:490)
	at org.testng.internal.objects.InstanceCreator.newInstance(InstanceCreator.java:38)
	... 31 more
Caused by: java.lang.NoClassDefFoundError: io/swagger/v3/oas/models/media/JsonSchema
	at io.swagger.v3.parser.OpenAPIV3Parser.parseJsonNode(OpenAPIV3Parser.java:142)
	at io.swagger.v3.parser.OpenAPIV3Parser.readContents(OpenAPIV3Parser.java:173)
	at io.swagger.v3.parser.OpenAPIV3Parser.readLocation(OpenAPIV3Parser.java:94)
	at io.swagger.parser.OpenAPIParser.readLocation(OpenAPIParser.java:16)
	at org.openapitools.codegen.TestUtils.parseSpec(TestUtils.java:71)
	at org.openapitools.codegen.TestUtils.parseFlattenSpec(TestUtils.java:54)
	at org.openapitools.codegen.kotlin.KotlinReservedWordsTest.<init>(KotlinReservedWordsTest.java:24)
	... 36 more
Caused by: java.lang.ClassNotFoundException: io.swagger.v3.oas.models.media.JsonSchema
	at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:581)
	at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)
	at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:522)
	... 43 more

Spec file:

openapi: 3.0.1
info:
  title: Test for Kotlin reserved words
  version: 1.0.0
paths:
  /ping:
    get:
      summary: Ping
      description: Pingy Ping
      parameters:
        - name: as
          in: header
          schema:
            type: string
        - name: break
          in: header
          schema:
            type: string
        - name: class
          in: header
          schema:
            type: string
        - name: continue
          in: header
          schema:
            type: string
        - name: do
          in: header
          schema:
            type: string
        - name: else
          in: header
          schema:
            type: string
        - name: "false"
          in: header
          schema:
            type: string
        - name: for
          in: header
          schema:
            type: string
        - name: fun
          in: header
          schema:
            type: string
        - name: if
          in: header
          schema:
            type: string
        - name: in
          in: header
          schema:
            type: string
        - name: interface
          in: header
          schema:
            type: string
        - name: is
          in: header
          schema:
            type: string
        - name: "null"
          in: header
          schema:
            type: string
        - name: object
          in: header
          schema:
            type: string
        - name: package
          in: header
          schema:
            type: string
        - name: return
          in: header
          schema:
            type: string
        - name: super
          in: header
          schema:
            type: string
        - name: this
          in: header
          schema:
            type: string
        - name: throw
          in: header
          schema:
            type: string
        - name: "true"
          in: header
          schema:
            type: string
        - name: try
          in: header
          schema:
            type: string
        - name: typealias
          in: header
          schema:
            type: string
        - name: typeof
          in: header
          schema:
            type: string
        - name: val
          in: header
          schema:
            type: string
        - name: value
          in: header
          schema:
            type: string
        - name: var
          in: header
          schema:
            type: string
        - name: when
          in: header
          schema:
            type: string
        - name: while
          in: header
          schema:
            type: string
        - name: open
          in: header
          schema:
            type: string
        - name: external
          in: header
          schema:
            type: string
        - name: internal
          in: header
          schema:
            type: string
      responses:
        '200':
          $ref: "#/components/schemas/Good"

components:
  schemas:
    Good:
      description: OK, Good
      type: object
      properties:
        as:
          type: string
        break:
          type: string
        class:
          type: string
        continue:
          type: string
        do:
          type: string
        else:
          type: string
        false:
          type: string
        for:
          type: string
        fun:
          type: string
        if:
          type: string
        in:
          type: string
        interface:
          type: string
        is:
          type: string
#        null:
#          type: string
        object:
          type: string
        package:
          type: string
        return:
          type: string
        super:
          type: string
        this:
          type: string
        throw:
          type: string
        true:
          type: string
        try:
          type: string
        typealias:
          type: string
        typeof:
          type: string
        val:
          type: string
        value:
          type: string
        var:
          type: string
        when:
          type: string
        while:
          type: string
        open:
          type: string
        external:
          type: string
        internal:
          type: string
        linked:
          $ref: '#/components/schemas/Linked'

    Linked:
      description: Refernce links
      type: object
      properties:
        as:
          $ref: '#/components/schemas/as'
        break:
          $ref: '#/components/schemas/break'
        class:
          $ref: '#/components/schemas/class'
        continue:
          $ref: '#/components/schemas/continue'
        do:
          $ref: '#/components/schemas/do'
        else:
          $ref: '#/components/schemas/else'
        false:
          $ref: '#/components/schemas/false'
        for:
          $ref: '#/components/schemas/for'
        fun:
          $ref: '#/components/schemas/fun'
        if:
          $ref: '#/components/schemas/if'
        in:
          $ref: '#/components/schemas/in'
        interface:
          $ref: '#/components/schemas/interface'
        is:
          $ref: '#/components/schemas/is'
#        null:
#          $ref: '#/components/schemas/null'
        object:
          $ref: '#/components/schemas/object'
        package:
          $ref: '#/components/schemas/package'
        return:
          $ref: '#/components/schemas/return'
        super:
          $ref: '#/components/schemas/super'
        this:
          $ref: '#/components/schemas/this'
        throw:
          $ref: '#/components/schemas/throw'
        true:
          $ref: '#/components/schemas/true'
        try:
          $ref: '#/components/schemas/try'
        typealias:
          $ref: '#/components/schemas/typealias'
        typeof:
          $ref: '#/components/schemas/typeof'
        val:
          $ref: '#/components/schemas/val'
        value:
          $ref: '#/components/schemas/value'
        var:
          $ref: '#/components/schemas/var'
        when:
          $ref: '#/components/schemas/when'
        while:
          $ref: '#/components/schemas/while'
        open:
          $ref: '#/components/schemas/open'
        external:
          $ref: '#/components/schemas/external'
        internal:
          $ref: '#/components/schemas/internal'
    as:
      title: Testing reserved word 'as'
      type: object
      properties:
        id:
          type: integer
          format: int64

    break:
      title: Testing reserved word 'break'
      type: object
      properties:
        id:
          type: integer
          format: int64

    class:
      title: Testing reserved word 'class'
      type: object
      properties:
        id:
          type: integer
          format: int64

    continue:
      title: Testing reserved word 'continue'
      type: object
      properties:
        id:
          type: integer
          format: int64

    do:
      title: Testing reserved word 'do'
      type: object
      properties:
        id:
          type: integer
          format: int64

    else:
      title: Testing reserved word 'else'
      type: object
      properties:
        id:
          type: integer
          format: int64

    false:
      title: Testing reserved word 'false'
      type: object
      properties:
        id:
          type: integer
          format: int64

    for:
      title: Testing reserved word 'for'
      type: object
      properties:
        id:
          type: integer
          format: int64

    fun:
      title: Testing reserved word 'fun'
      type: object
      properties:
        id:
          type: integer
          format: int64

    if:
      title: Testing reserved word 'if'
      type: object
      properties:
        id:
          type: integer
          format: int64

    in:
      title: Testing reserved word 'in'
      type: object
      properties:
        id:
          type: integer
          format: int64

    interface:
      title: Testing reserved word 'interface'
      type: object
      properties:
        id:
          type: integer
          format: int64

    is:
      title: Testing reserved word 'is'
      type: object
      properties:
        id:
          type: integer
          format: int64

#    swagger-parser bug: https://github.com/swagger-api/swagger-parser/issues/1781
#    null:
#      title: Testing reserved word 'null'
#      type: object
#      properties:
#        id:
#          type: integer
#          format: int64

    object:
      title: Testing reserved word 'object'
      type: object
      properties:
        id:
          type: integer
          format: int64

    package:
      title: Testing reserved word 'package'
      type: object
      properties:
        id:
          type: integer
          format: int64

    return:
      title: Testing reserved word 'return'
      type: object
      properties:
        id:
          type: integer
          format: int64

    super:
      title: Testing reserved word 'super'
      type: object
      properties:
        id:
          type: integer
          format: int64

    this:
      title: Testing reserved word 'this'
      type: object
      properties:
        id:
          type: integer
          format: int64

    throw:
      title: Testing reserved word 'throw'
      type: object
      properties:
        id:
          type: integer
          format: int64

    true:
      title: Testing reserved word 'true'
      type: object
      properties:
        id:
          type: integer
          format: int64

    try:
      title: Testing reserved word 'try'
      type: object
      properties:
        id:
          type: integer
          format: int64

    typealias:
      title: Testing reserved word 'typealias'
      type: object
      properties:
        id:
          type: integer
          format: int64

    typeof:
      title: Testing reserved word 'typeof'
      type: object
      properties:
        id:
          type: integer
          format: int64

    val:
      title: Testing reserved word 'val'
      type: object
      properties:
        id:
          type: integer
          format: int64

    value:
      title: Testing reserved word 'value'
      type: object
      properties:
        id:
          type: integer
          format: int64

    var:
      title: Testing reserved word 'var'
      type: object
      properties:
        id:
          type: integer
          format: int64

    when:
      title: Testing reserved word 'when'
      type: object
      properties:
        id:
          type: integer
          format: int64

    while:
      title: Testing reserved word 'while'
      type: object
      properties:
        id:
          type: integer
          format: int64

    open:
      title: Testing reserved word 'open'
      type: object
      properties:
        id:
          type: integer
          format: int64

    external:
      title: Testing reserved word 'external'
      type: object
      properties:
        id:
          type: integer
          format: int64

    internal:
      title: Testing reserved word 'internal'
      type: object
      properties:
        id:
          type: integer
          format: int64
@spacether spacether changed the title Thrown java.lang.NoClassDefFoundError when reading spec, v2.1.1 Thrown java.lang.NoClassDefFoundError when reading 3.0.1 spec, v2.1.1 Aug 11, 2022
@spacether
Copy link
Contributor Author

This happened because the swagger-core.version also needed to be updated

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