mirror of
https://github.com/tiennm99/lombok.git
synced 2026-10-14 20:17:25 +00:00
fixed Issue 271: @NotNull annotations should introduce a null check
This commit is contained in:
1 parent
25fbdf0c5b
commit
236c88fc5c
6 files changed
+102
-22
No files matched your search
@@ -72,7 +72,7 @@ public class TransformationsUtil {
|
||||
public static final Pattern PRIMITIVE_TYPE_NAME_PATTERN = Pattern.compile(
|
||||
"^(boolean|byte|short|int|long|float|double|char)$");
|
||||
|
||||
public static final Pattern NON_NULL_PATTERN = Pattern.compile("^nonnull$", Pattern.CASE_INSENSITIVE);
|
||||
public static final Pattern NON_NULL_PATTERN = Pattern.compile("^(?:notnull|nonnull)$", Pattern.CASE_INSENSITIVE);
|
||||
public static final Pattern NULLABLE_PATTERN = Pattern.compile("^(?:nullable|checkfornull)$", Pattern.CASE_INSENSITIVE);
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,25 +1,60 @@
|
||||
import java.lang.annotation.*;
|
||||
|
||||
class NonNullPlain {
|
||||
@lombok.NonNull
|
||||
int i;
|
||||
@lombok.NonNull
|
||||
String s;
|
||||
@java.lang.SuppressWarnings("all")
|
||||
public void setI(@lombok.NonNull final int i) {
|
||||
this.i = i;
|
||||
@NotNull
|
||||
Object o;
|
||||
|
||||
@Target({ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER, ElementType.LOCAL_VARIABLE})
|
||||
@Retention(RetentionPolicy.CLASS)
|
||||
public @interface NotNull {
|
||||
}
|
||||
|
||||
@java.beans.ConstructorProperties({"i", "s", "o"})
|
||||
@java.lang.SuppressWarnings("all")
|
||||
public NonNullPlain(@lombok.NonNull final int i, @lombok.NonNull final String s, @NotNull final Object o) {
|
||||
if (s == null) throw new java.lang.NullPointerException("s");
|
||||
if (o == null) throw new java.lang.NullPointerException("o");
|
||||
this.i = i;
|
||||
this.s = s;
|
||||
this.o = o;
|
||||
}
|
||||
|
||||
@lombok.NonNull
|
||||
@java.lang.SuppressWarnings("all")
|
||||
public int getI() {
|
||||
return this.i;
|
||||
}
|
||||
|
||||
@lombok.NonNull
|
||||
@java.lang.SuppressWarnings("all")
|
||||
public String getS() {
|
||||
return this.s;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@java.lang.SuppressWarnings("all")
|
||||
public Object getO() {
|
||||
return this.o;
|
||||
}
|
||||
|
||||
@java.lang.SuppressWarnings("all")
|
||||
public void setI(@lombok.NonNull final int i) {
|
||||
this.i = i;
|
||||
}
|
||||
|
||||
@java.lang.SuppressWarnings("all")
|
||||
public void setS(@lombok.NonNull final String s) {
|
||||
if (s == null) throw new java.lang.NullPointerException("s");
|
||||
this.s = s;
|
||||
}
|
||||
|
||||
@java.lang.SuppressWarnings("all")
|
||||
public void setO(@NotNull final Object o) {
|
||||
if (o == null) throw new java.lang.NullPointerException("o");
|
||||
this.o = o;
|
||||
}
|
||||
}
|
||||
@@ -1,8 +1,19 @@
|
||||
class NonNullPlain {
|
||||
@lombok.Setter @lombok.NonNull @lombok.Getter int i;
|
||||
@lombok.Getter @lombok.Setter @lombok.NonNull String s;
|
||||
public @java.lang.SuppressWarnings("all") void setI(final @lombok.NonNull int i) {
|
||||
import java.lang.annotation.*;
|
||||
@lombok.RequiredArgsConstructor @lombok.Getter @lombok.Setter class NonNullPlain {
|
||||
public @Target({ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER, ElementType.LOCAL_VARIABLE}) @Retention(RetentionPolicy.CLASS) @interface NotNull {
|
||||
}
|
||||
@lombok.NonNull int i;
|
||||
@lombok.NonNull String s;
|
||||
@NotNull Object o;
|
||||
public @java.beans.ConstructorProperties({"i", "s", "o"}) @java.lang.SuppressWarnings("all") NonNullPlain(final @lombok.NonNull int i, final @lombok.NonNull String s, final @NotNull Object o) {
|
||||
super();
|
||||
if ((s == null))
|
||||
throw new java.lang.NullPointerException("s");
|
||||
if ((o == null))
|
||||
throw new java.lang.NullPointerException("o");
|
||||
this.i = i;
|
||||
this.s = s;
|
||||
this.o = o;
|
||||
}
|
||||
public @lombok.NonNull @java.lang.SuppressWarnings("all") int getI() {
|
||||
return this.i;
|
||||
@@ -10,12 +21,20 @@ class NonNullPlain {
|
||||
public @lombok.NonNull @java.lang.SuppressWarnings("all") String getS() {
|
||||
return this.s;
|
||||
}
|
||||
public @NotNull @java.lang.SuppressWarnings("all") Object getO() {
|
||||
return this.o;
|
||||
}
|
||||
public @java.lang.SuppressWarnings("all") void setI(final @lombok.NonNull int i) {
|
||||
this.i = i;
|
||||
}
|
||||
public @java.lang.SuppressWarnings("all") void setS(final @lombok.NonNull String s) {
|
||||
if ((s == null))
|
||||
throw new java.lang.NullPointerException("s");
|
||||
this.s = s;
|
||||
}
|
||||
NonNullPlain() {
|
||||
super();
|
||||
public @java.lang.SuppressWarnings("all") void setO(final @NotNull Object o) {
|
||||
if ((o == null))
|
||||
throw new java.lang.NullPointerException("o");
|
||||
this.o = o;
|
||||
}
|
||||
}
|
||||
@@ -1,8 +1,19 @@
|
||||
class NonNullPlain {
|
||||
@lombok.Setter @lombok.NonNull @lombok.Getter int i;
|
||||
@lombok.Getter @lombok.Setter @lombok.NonNull String s;
|
||||
public @java.lang.SuppressWarnings("all") void setI(final @lombok.NonNull int i) {
|
||||
import java.lang.annotation.*;
|
||||
@lombok.RequiredArgsConstructor @lombok.Getter @lombok.Setter class NonNullPlain {
|
||||
public @Target({ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER, ElementType.LOCAL_VARIABLE}) @Retention(RetentionPolicy.CLASS) @interface NotNull {
|
||||
}
|
||||
@lombok.NonNull int i;
|
||||
@lombok.NonNull String s;
|
||||
@NotNull Object o;
|
||||
public @java.beans.ConstructorProperties({"i", "s", "o"}) @java.lang.SuppressWarnings("all") NonNullPlain(final @lombok.NonNull int i, final @lombok.NonNull String s, final @NotNull Object o) {
|
||||
super();
|
||||
if ((s == null))
|
||||
throw new java.lang.NullPointerException("s");
|
||||
if ((o == null))
|
||||
throw new java.lang.NullPointerException("o");
|
||||
this.i = i;
|
||||
this.s = s;
|
||||
this.o = o;
|
||||
}
|
||||
public @lombok.NonNull @java.lang.SuppressWarnings("all") int getI() {
|
||||
return this.i;
|
||||
@@ -10,12 +21,20 @@ class NonNullPlain {
|
||||
public @lombok.NonNull @java.lang.SuppressWarnings("all") String getS() {
|
||||
return this.s;
|
||||
}
|
||||
public @NotNull @java.lang.SuppressWarnings("all") Object getO() {
|
||||
return this.o;
|
||||
}
|
||||
public @java.lang.SuppressWarnings("all") void setI(final @lombok.NonNull int i) {
|
||||
this.i = i;
|
||||
}
|
||||
public @java.lang.SuppressWarnings("all") void setS(final @lombok.NonNull String s) {
|
||||
if ((s == null))
|
||||
throw new java.lang.NullPointerException("s");
|
||||
this.s = s;
|
||||
}
|
||||
NonNullPlain() {
|
||||
super();
|
||||
public @java.lang.SuppressWarnings("all") void setO(final @NotNull Object o) {
|
||||
if ((o == null))
|
||||
throw new java.lang.NullPointerException("o");
|
||||
this.o = o;
|
||||
}
|
||||
}
|
||||
@@ -1,10 +1,17 @@
|
||||
import java.lang.annotation.*;
|
||||
|
||||
@lombok.RequiredArgsConstructor
|
||||
@lombok.Getter
|
||||
@lombok.Setter
|
||||
class NonNullPlain {
|
||||
@lombok.Setter
|
||||
@lombok.NonNull
|
||||
@lombok.Getter int i;
|
||||
|
||||
@lombok.Getter
|
||||
@lombok.Setter
|
||||
int i;
|
||||
@lombok.NonNull
|
||||
String s;
|
||||
@NotNull
|
||||
Object o;
|
||||
|
||||
@Target({ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER, ElementType.LOCAL_VARIABLE})
|
||||
@Retention(RetentionPolicy.CLASS)
|
||||
public @interface NotNull {}
|
||||
}
|
||||
@@ -58,7 +58,7 @@
|
||||
Any variation on <code>boolean</code> will <em>not</em> result in using the <code>is</code> prefix instead of the <code>get</code> prefix; for example,
|
||||
returning <code>java.lang.Boolean</code> results in a <code>get</code> prefix, not an <code>is</code> prefix.
|
||||
</p><p>
|
||||
Any annotations named <code>@NonNull</code> (case insensitive) on the field are interpreted as: This field must not ever hold
|
||||
Any annotations named <code>@NonNull</code> or <code>@NotNull</code> (case insensitive) on the field are interpreted as: This field must not ever hold
|
||||
<em>null</em>. Therefore, these annotations result in an explicit null check in the generated setter. Also, these
|
||||
annotations (as well as any annotation named <code>@Nullable</code> or <code>@CheckForNull</code>) are copied to setter parameter and getter method.
|
||||
</p><p>
|
||||
|
||||
Reference in new issue
Block a user