Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
A pure-Java Spring Boot project using
springdoc-openapi-starter-webmvc-apicrashes onGET /v3/api-docswithjava.lang.NoClassDefFoundError: kotlin/reflect/full/KClasses.Root cause:
KotlinRequiredPropertyCustomizerwas instantiated and registered as a SpringModelConverterwheneverkotlin-stdlibis on the classpath. The outerSpringDocKotlinConfigurationclass is gated only by@ConditionalOnClass(Continuation::class)(kotlin-stdlib), but the customizer'sresolve()method useskotlin.reflect.full.*(kotlin-reflect).In a pure-Java project,
kotlin-stdlibis present whilekotlin-reflectis absent (both are<scope>provided</scope>in the common module'spom.xml). So the customizer was created, registered as aModelConverter, and threwNoClassDefFoundErrorthe first time model resolution touched aPageable/Sort/Pagetype — exactly the reporter's stack trace (KotlinRequiredPropertyCustomizer.resolve←PageableOpenAPIConverter.resolve←PageOpenAPIConverter.resolve←SortOpenAPIConverter.resolve).Solution
Moved the
kotlinRequiredPropertyCustomizer@Beanfrom the outerSpringDocKotlinConfigurationinto the innerKotlinReflectDependingConfiguration, which is gated by@ConditionalOnClass(name = ["kotlin.reflect.full.KClasses"]). This matches the other three Kotlin customizers already nested there.Now the bean is only created when kotlin-reflect is present. For pure-Java projects the customizer is never registered as a
ModelConverter, soresolve()is never invoked and theNoClassDefFoundErrorcannot occur.Result
Pure-Java and other non-Kotlin consumers (kotlin-stdlib present, kotlin-reflect absent) no longer crash:
GET /v3/api-docsnow resolvesPageable/Sort/Pagemodels and returns the OpenAPI document as expected.The failure path is eliminated —
KotlinRequiredPropertyCustomizeris never registered as aModelConverterunless kotlin-reflect is on the classpath, soresolve()can no longer throwNoClassDefFoundError: kotlin/reflect/full/KClasses.Kotlin projects are unaffected: kotlin-reflect is always present for them, so the customizer is still created and the required-property schema behavior is preserved.
Closes #54