Fix NullPointerException in MigrateApiParamSchemaValue for argument-less @ApiParam#77
Open
jsgv wants to merge 1 commit into
Open
Fix NullPointerException in MigrateApiParamSchemaValue for argument-less @ApiParam#77jsgv wants to merge 1 commit into
jsgv wants to merge 1 commit into
Conversation
…ess @ApiParam A marker @ApiParam / @parameter annotation written without parentheses has null arguments (J.Annotation.getArguments() returns null, not an empty list). visitAnnotation iterated the arguments without a null check, throwing a NullPointerException and aborting the whole recipe run. Guard against null arguments and return the annotation unchanged, since there is nothing to migrate when no arguments are present.
ae892a1 to
f92bb66
Compare
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.
What's changed?
MigrateApiParamSchemaValue.visitAnnotationiteratesa.getArguments()without a null check. An@ApiParam/@Parameterannotation written without parentheses hasnullarguments (J.Annotation.getArguments()returnsnull, not an empty list), so the recipe throws aNullPointerExceptionand aborts the entire run.This guards against null arguments and returns the annotation unchanged, since there is nothing to migrate when no arguments are present.
What's your motivation?
Running
SwaggerToOpenAPI(transitively, viaUpgradeSpringBoot_4_0) on a real codebase that uses bare@ApiParamannotations on controller method parameters fails the whole migration:A single argument-less annotation anywhere in the sources aborts the run.
Anything in particular you'd like reviewers to focus on?
The cause is the recipe ordering in
MigrateApiParamToParameter: aChangeTypefirst rewrites@ApiParamtoio.swagger.v3.oas.annotations.Parameter, so a parenthesis-less@ApiParambecomes a parenthesis-less@Parameter, which then matchesPARAMETER_ANNOTATION_MATCHERand reaches the uncheckedgetArguments(). Non-@Parameterannotations (e.g.@Override,@RestController) are unaffected because the matcher returns early.Have you considered any alternatives or workarounds?
Returning early on null arguments is the minimal, semantically-correct fix — a bare
@Parameterhas nodefaultValue/allowableValuesto fold into a@Schema, so there is nothing to migrate.getArguments()is@Nullableby design, so callers must null-check.Any additional context
Added two regression tests covering a bare
@ApiParamon a field and on a method parameter (the latter reproduces the original crash); both migrate@ApiParam->@Parameterwithout error.Checklist