[Fixes #807] The NonNull annotation can now be used documentary style on params of abstract methods. The warning has been eliminated.

This commit is contained in:
Reinier Zwitserloot committed 2015-10-05 21:58:00 +02:00
1 parent 264c66b53f
commit e94a5f9ee3
10 files changed
+32 -6

No files matched your search

+1
View File
@@ -3,6 +3,7 @@ Lombok Changelog
### v1.16.7 "Edgy Guinea Pig"
* BUGFIX: `@Value` and `@FieldDefaults` no longer make uninitialized static fields final. [Issue #928](https://github.com/rzwitserloot/lombok/issues/928).
* ENHANCEMENT: Putting `@NonNull` on a parameter of an abstract method no longer generates a warning, to allow you to use this annotation to document intended behaviour [Issue #807](https://github.com/rzwitserloot/lombok/issues/807).
### v1.16.6 (August 18th, 2015)
* FEATURE: `@Helper` can be placed on method-local inner classes to make all methods in the class accessible to the rest of the method. [Full documentation](https://projectlombok.org/features/experimental/Helper.html).
@@ -91,7 +91,7 @@ public class HandleNonNull extends EclipseAnnotationHandler<NonNull> {
if (isGenerated(declaration)) return;
if (declaration.isAbstract()) {
annotationNode.addWarning("@NonNull is meaningless on a parameter of an abstract method.");
// This used to be a warning, but as @NonNull also has a documentary purpose, better to not warn about this. Since 1.16.7
return;
}
@@ -85,7 +85,7 @@ public class HandleNonNull extends JavacAnnotationHandler<NonNull> {
}
if (declaration.body == null) {
annotationNode.addWarning("@NonNull is meaningless on a parameter of an abstract method.");
// This used to be a warning, but as @NonNull also has a documentary purpose, better to not warn about this. Since 1.16.7
return;
}
@@ -0,0 +1,9 @@
interface NonNullOnParameterOfDefaultMethod {
void test(@lombok.NonNull String arg);
default void test2(@lombok.NonNull String arg) {
if (arg == null) {
throw new java.lang.NullPointerException("arg");
}
System.out.println(arg);
}
}
@@ -0,0 +1,10 @@
interface NonNullOnParameterOfDefaultMethod {
void test(@lombok.NonNull String arg);
default void test2(@lombok.NonNull String arg) {
if ((arg == null))
{
throw new java.lang.NullPointerException("arg");
}
System.out.println(arg);
}
}
@@ -0,0 +1,6 @@
interface NonNullOnParameterOfDefaultMethod {
void test(@lombok.NonNull String arg);
default void test2(@lombok.NonNull String arg) {
System.out.println(arg);
}
}
@@ -1 +0,0 @@
6 @NonNull is meaningless on a parameter of an abstract method.
@@ -1 +0,0 @@
6 @NonNull is meaningless on a parameter of an abstract method.
@@ -1 +0,0 @@
9 @NonNull is meaningless on a parameter of an abstract method.
+4 -1
View File
@@ -15,7 +15,7 @@
<div class="overview">
<h3>Overview</h3>
<p>
<em>NEW in Lombok 0.11.10: </em>You can use <code>@NonNull</code> on the parameter of a method or constructor to have lombok generate a null-check statement for you.
<em>NEW in Lombok 0.11.10: </em>You can use <code>@NonNull</code> on the parameter of a method or constructor to have lombok generate a null-check statement for you.<br />
</p><p>
Lombok has always treated any annotation named <code>@NonNull</code> on a field as a signal to generate a null-check if lombok generates an entire method or constructor for you, via
for example <a href="Data.html"><code>@Data</code></a>. Now, however, using lombok's own <code>@lombok.NonNull</code> on a parameter results in the insertion of just the null-check
@@ -60,6 +60,9 @@
this feature only triggers on lombok's own <code>@NonNull</code> annotation from the <code>lombok</code> package.
</p><p>
A <code>@NonNull</code> on a primitive parameter results in a warning. No null-check will be generated.
</p><p>
A <code>@NonNull</code> on a parameter of an abstract method used to generate a warning; starting with version 1.16.8, this is no longer the case, to acknowledge the notion that <code>@NonNull</code> also has a
documentary role. For the same reason, you can annotate a method as <code>@NonNull</code>; this is allowed, generates no warning, and does not generate any code.
</p>
</div>
</div>