FindBugs DefaultAnnotation alternative for javax.nnation for fields and methods

I am currently using

@DefaultAnnotation(NonNull.class) package jobs; import edu.umd.cs.findbugs.annotations.DefaultAnnotation; import edu.umd.cs.findbugs.annotations.NonNull; 

however the @ edu.umd.cs.findbugs.annotations.DefaultAnnotation annotation is deprecated: http://findbugs.sourceforge.net/api/edu/umd/cs/findbugs/annotations/DefaultAnnotation.html

They suggest using javax.annotation.ParametersAreNonnullByDefault. However, DefaultAnnotation not only targets parameters, but also fields and methods.

So what is the javax.annotation alternative for setting fields and methods in Nonnull by default?

+3
source share
2 answers

As far as I know, they are not. Wanting the same, I copied the source for ParametersAreNonnullByDefault to my own FieldsAreNonnullByDefault and MethodsAreNonnullByDefault and changed @TypeQualifierDefault to ( FIELD and METHOD respectively). FindBugs handles these new annotations perfectly.

Here is a sample for FieldsAreNonnullByDefault :

 package com.sample; import java.lang.annotation.Documented; import java.lang.annotation.ElementType; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import javax.annotation.meta.TypeQualifierDefault; /** * This annotation can be applied to a package or class to indicate that the * classes' fields in that element are nonnull by default unless there is * <ul> * <li>an explicit nullness annotation * <li>a default field annotation applied to a more tightly nested element. * </ul> */ @Documented @Nonnull @TypeQualifierDefault(ElementType.FIELD) // <-- METHOD for return values @Retention(RetentionPolicy.RUNTIME) public @interface FieldsAreNonnullByDefault { } 
+5
source

So, from a pure code point of view, there really is no significant difference.

The difference occurs after the distribution of the code begins.

Until you submit your code using annotations and JREs, you should be fine.

If you are distributing a JRE, then, as you already know, you need to run the Oracle Java Binary License .

You might want to refresh yourself with the terms of this license, in particular:

F. LIMITATIONS OF JAVA TECHNOLOGY. You may not create, modify or modify the behavior or allow your licensees to create, modify or modify the behavior of classes, interfaces or subpackages that are identified in any way as "java", "javax", sun "," oracle "or a similar agreement, as indicated by Oracle, in any legend designation.

So, if you distribute the JRE, and the same distribution includes a jar file that defines the classes in the javax , if the classes do not meet the specifications released and published by the JSR, you do not meet the Oracle Java binary license terms.

It is at this point that you should take a look at the official JSR 305 page.

At this point in time, JSR did not publish anything :

JSR - as of March 2016 - listed as sleeping

Thus, you will need to make sure that you are not distributing the jsr305.jar file next to the JRE in the Windows installer, OS-X installer, Docker image, etc.

0
source

Source: https://habr.com/ru/post/1212554/


All Articles