-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
AVRO-3641: Adds support for nullSafeAnnotations to java SpecificCompiler #2142
Conversation
# Conflicts: # lang/java/pom.xml # lang/java/tools/src/test/java/org/apache/avro/tool/TestSpecificCompilerTool.java
👍🏻 |
...ls/src/test/compiler/output-string/avro/examples/baseball/NullSafeAnnotationsFieldsTest.java
Show resolved
Hide resolved
Given that this package main use case are the command line tools / build plugins, I'm fine with adding the jetbrains dependency. |
lang/java/ipc/pom.xml
Outdated
<dependency> | ||
<groupId>org.jetbrains</groupId> | ||
<artifactId>annotations</artifactId> | ||
</dependency> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this dependency actually used here?
lang/java/compiler/pom.xml
Outdated
<dependency> | ||
<groupId>org.jetbrains</groupId> | ||
<artifactId>annotations</artifactId> | ||
</dependency> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I only see the dependency being used in the test code (which is perfect IMHO). Can we please reduce the scope to test?
I think it does. Also, your question triggered me to take a closer look at the code & dependencies. It would actually be a good change, and relatively easy to do as well. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've left a few comments wrt use of dependencies.
I think a configurable approach, where the test configuration explicitly names the org.jetbrains.annotations.Nullable
and org.jetbrains.annotations.NotNull
annotations.
…e it is only used in the produced jar
👍 |
The JSR to develop standard annotations (such as @nonnull) for Java is dead since August 2006: https://jcp.org/en/jsr/detail?id=305 Maybe this PR can be merged so that the most commonly used @nullable and @NotNull annotations can be used. This would be especially useful for Kotlin based projects, since it would add compile time safety when using Avro. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In general, this code looks good (nice, simple & clean).
As per the comments (also left by others), I think it would be better to prepare the template for using different annotation classes (i.e., remove the import statement). Actually implementing for other @Nullable/@NoptNull annotations is a lot easier then.
...ompiler/src/main/velocity/org/apache/avro/compiler/specific/templates/java/classic/record.vm
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In general, this code looks good (nice, simple & clean).
As per the comments (also left by others), I think it would be better to prepare the template for using different annotation classes (i.e., remove the import statement). Actually implementing for other @Nullable/@NoptNull annotations is a lot easier then.
Is there anything I can do to get this PR merged? It has been ready to merge for quite some time now? |
/** | ||
* The createNullSafeAnnotations parameters adds @Nullable and @NotNull | ||
* annotations for fhe fields of the record. The default is to not include | ||
* annotations. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we please mention here that the annotations are JetBrains annotations?
Then it'll automatically be documented by the plugin help. Ideally, it also lists the dependency coordinates / package-url (pkg:maven/org.jetbrains/[email protected]
).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
At this point in time, there are no other places on the website that document the maven plugin, or code generation options. It's only mentioned in passing on the "Getting started" page for Java.
Any chance to get this merged? |
@opwvhk Is there any planned version where this will be released? This would really help us a lot when working with Avro in Kotlin projects. |
@m-kay It will be in the next release, version 1.12.0. The most authoritative source on it is the dev mailing list. |
…ler (apache#2142) * AVRO-3641: Adds support for nullSafeAnnotations to java SpecificCompiler * AVRO-3641: Removes maven dependency to org.jetbrains:annotations since it is only used in the produced jar * AVRO-3641: Removes the unused property for jetbrains-annotations version * AVRO-3641: Removes empty lines from expected output file * Revert "AVRO-3641: Removes empty lines from expected output file" This reverts commit f99cf16. * AVRO-3641: Use full class name for null safe annotations instead of imports * AVRO-3641: Adds avro-maven-plugin config parameter for createNullSafeAnnotations * AVRO-3641: Clarifies the source of the nullability annotations * AVRO-3641: Minor javadoc formatting. * AVRO-3641: Fixes spotless formatting * AVRO-3641: Adds license exclude for NullSafeAnnotationsFieldsTest.java --------- Co-authored-by: pknu <[email protected]>
What is the purpose of the change
*This pull request adds support for JetBrains
@Nullable
and@NotNull
annotations based on schema.isNullable(), fixing AVRO-3641.Verifying this change
This change added tests and can be verified as follows:
Run
TestSpecificCompilerTool.compileSchemaWithNullSafeAnnotationsFields()
to fully verify the generated java codeDocumentation
Adding configuration option
<createNullSafeAnnotations>true<createNullSafeAnnotations/>
enables this feature.It is disabled by default to conform to the default behavior.