-
Notifications
You must be signed in to change notification settings - Fork 25.6k
Enable Kotlin compiler to recognise @org.elasticsearch.common.Nullable annotation for null checks. #43912
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
Conversation
|
Pinging @elastic/es-core-infra |
|
@elasticmachine test this please |
|
Couldn't reproduce the build failures in |
|
@elasticmachine update branch |
|
Thanks for the PR @vinoov. I've looked at this a bit. This will mostly have a minor effect due to the way we use There are a handful of cases where we annotate methods, and in this case there is a discernible difference when calling that code from Kotlin. If a method is annotated with @Nullable
public static String nullable() {
return null;
}We now get the following behavior when calling from Kotlin: I'd say this is definitely an improvement in terms of Kotlin support. Its impact is minimal as I say as there are only a few instances where methods are annotated with |
|
@mark-vieira The motivation for this was an NPE I hit by not checking the return value of RestRequest.getXContentType. Looking through the code some other @nullable APIs that plugins might hypothetically use are:
|
Agreed; for method arguments |
This would probably require a larger discussion. I'd probably start by opening an issue on the topic. |
This change allows the Kotlin compiler to type check methods annotated with the org.elasticsearch.common.Nullable annotation in Elasticsearch Java APIs as described in: https://kotlinlang.org/docs/reference/java-interop.html#jsr-305-support.
|
This has been merged. Thanks for the contribution @vinoov. |
|
hi @mark-vieira. Will this make it into an upcoming ES 7.x release or do I have to wait for 8.x? I'm not familiar with the github issue tags ES uses. Thanks in advance. |
|
The |
|
Thanks for clarifying @mark-vieira. Do I need to send a patch to backport to 7.x or is it done automatically? |
…lastic#43912) This change allows the Kotlin compiler to type check methods annotated with the org.elasticsearch.common.Nullable annotation in Elasticsearch Java APIs as described in: https://kotlinlang.org/docs/reference/java-interop.html#jsr-305-support. (cherry picked from commit 0d0485a)
|
I've created a PR to backport this to the |
…43912) (#44518) This change allows the Kotlin compiler to type check methods annotated with the org.elasticsearch.common.Nullable annotation in Elasticsearch Java APIs as described in: https://kotlinlang.org/docs/reference/java-interop.html#jsr-305-support. (cherry picked from commit 0d0485a)
|
@vinoov this has been backported to the |
|
Thanks @mark-vieira . |

This change allows Elasticsearch plugins written in Kotlin to read the nullability
information present in the ES API declarations and warn of unsafe API usage during compile time.
Details here: https://kotlinlang.org/docs/reference/java-interop.html#jsr-305-support.
gradle check?