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

There is a case that KotlinModule can overwrite hasRequiredMarker incorrectly. #922

Closed
4 tasks done
k163377 opened this issue Mar 19, 2025 · 0 comments · Fixed by #929
Closed
4 tasks done

There is a case that KotlinModule can overwrite hasRequiredMarker incorrectly. #922

k163377 opened this issue Mar 19, 2025 · 0 comments · Fixed by #929
Labels

Comments

@k163377
Copy link
Contributor

k163377 commented Mar 19, 2025

Search before asking

  • I searched in the issues and found nothing similar.
  • I have confirmed that the same problem is not reproduced if I exclude the KotlinModule.
  • I searched in the issues of databind and other modules used and found nothing similar.
  • I have confirmed that the problem does not reproduce in Java and only occurs when using Kotlin and KotlinModule.

Describe the bug

KotlinAnnotationIntrospector.hasRequiredMarker has following problems

  1. If nullToEmptyCollection or nullToEmptyMap is specified, the specification by annotation is overridden.
  2. If nullToEmptyCollection or nullToEmptyMap is specified, the KotlinModule specification is applied to non Kotlin members.
  3. The nullToEmptyCollection and nullToEmptyMap only work with parameters for now, but as for hasRequiredMarker, it applies to fields, setters and getters.
    • I created a test and confirmed that the setters were not affected.

try {
when {
nullToEmptyCollection && m.type.isCollectionLikeType -> false
nullToEmptyMap && m.type.isMapLikeType -> false
m.member.declaringClass.isKotlinClass() -> when (m) {
is AnnotatedField -> m.hasRequiredMarker()
is AnnotatedMethod -> m.hasRequiredMarker()
is AnnotatedParameter -> m.hasRequiredMarker()
else -> null
}
else -> null
}
} catch (ex: UnsupportedOperationException) {
null
}

To Reproduce

It can be read from the code.

Expected behavior

The behavior should satisfy the following three points

  1. Annotation specifications are not overridden as much as possible.
  2. Only apply to members defined in Kotlin.
  3. The nullToEmptyCollection and nullToEmptyMap are applied only to parameters.

Versions

This has not been corrected in 2.19.

Additional context

In the modification process, changes need to be made regarding the new isRequired property.
FasterXML/jackson-databind#5020 (comment)

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

Successfully merging a pull request may close this issue.

1 participant