[
https://issues.apache.org/jira/browse/AVRO-4119?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18033840#comment-18033840
]
Peter Knuts commented on AVRO-4119:
-----------------------------------
It doesn't seem to work to simply replace the Jetbrains annotation with the one
from Jspecify for the auto generated code since they all use the fully
qualified type name like java.lang.String. The code below is similar to what
the avro-maven-plugin would generate with the new configuration options:
{code:java}
package se.sbab.tnt;
public class TestClass {
private final String name;
public TestClass(@org.jspecify.annotations.NonNull java.lang.String name) {
this.name = name;
}
@org.jspecify.annotations.NonNull
public se.sbab.tnt.TestClass getMyClass() {
return this;
}
}{code}
Configuration:
{code:java}
<plugin>
<groupId>org.apache.avro</groupId>
<artifactId>avro-maven-plugin</artifactId>
<version>1.12.1</version>
<configuration>
<stringType>String</stringType>
<createNullSafeAnnotations>true</createNullSafeAnnotations>
<nullSafeAnnotationNullable>org.jspecify.annotations.Nullable</nullSafeAnnotationNullable>
<nullSafeAnnotationNotNull>org.jspecify.annotations.NonNull</nullSafeAnnotationNotNull>
</configuration>
</plugin>{code}
For this to compile, the generated could would likely need to use a different
syntax:
{code:java}
package se.sbab.tnt;
public class TestClass {
private final String name;
public TestClass([email protected] String name) {
this.name = name;
}
public [email protected] TestClass getMyClass() {
return this;
}
}{code}
It would also work fine if the generated code didn't use the fully qualified
class names for the annotated code segments:
{code:java}
package se.sbab.tnt;
public class TestClass {
private final String name;
public TestClass(@org.jspecify.annotations.NonNull String name) {
this.name = name;
}
@org.jspecify.annotations.NonNull
public TestClass getMyClass() {
return this;
}
}{code}
Since the avro-maven-plugin consistently uses the fully qualified class names,
even for java.lang classes, this will likely not work?
More info here: https://github.com/jspecify/jspecify/issues/453
> Make Nullable and NotNull annotations configurable
> --------------------------------------------------
>
> Key: AVRO-4119
> URL: https://issues.apache.org/jira/browse/AVRO-4119
> Project: Apache Avro
> Issue Type: Improvement
> Components: java
> Reporter: Benedikt Werner
> Priority: Major
> Labels: pull-request-available
> Fix For: 1.12.1
>
> Time Spent: 1h 20m
> Remaining Estimate: 0h
>
> In AVRO-3641, the createNullSafeAnnotations option was added to the Java code
> generator to enable generating @Nullable and @NotNull annotations depending
> on a field's nullability.
> However, this always generates JetBrains nullability annotations, which isn't
> ideal for projects using one of the many other nullability annotations.
> A universal solution would be to make the exact annotations to generate
> configurable, defaulting to the JetBrains annotations for
> backwards-compatibility.
> I already created a PR with a proposed implementation.
--
This message was sent by Atlassian Jira
(v8.20.10#820010)