From 236c88fc5cb2444af353bec6370b43b915ed8fdb Mon Sep 17 00:00:00 2001 From: peichhorn Date: Mon, 5 Sep 2011 21:53:58 +0200 Subject: fixed Issue 271: @NotNull annotations should introduce a null check --- .../resource/after-delombok/NonNullPlain.java | 37 +++++++++++++++++++++- .../transform/resource/after-ecj/NonNullPlain.java | 31 ++++++++++++++---- .../resource/after-eclipse/NonNullPlain.java | 31 ++++++++++++++---- test/transform/resource/before/NonNullPlain.java | 17 +++++++--- 4 files changed, 98 insertions(+), 18 deletions(-) (limited to 'test/transform') diff --git a/test/transform/resource/after-delombok/NonNullPlain.java b/test/transform/resource/after-delombok/NonNullPlain.java index 0c58425c..17c9ab51 100644 --- a/test/transform/resource/after-delombok/NonNullPlain.java +++ b/test/transform/resource/after-delombok/NonNullPlain.java @@ -1,25 +1,60 @@ +import java.lang.annotation.*; + class NonNullPlain { @lombok.NonNull 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 { + } + + @java.beans.ConstructorProperties({"i", "s", "o"}) @java.lang.SuppressWarnings("all") - public void setI(@lombok.NonNull final int i) { + 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; + } } diff --git a/test/transform/resource/after-ecj/NonNullPlain.java b/test/transform/resource/after-ecj/NonNullPlain.java index 6f552436..252a2077 100644 --- a/test/transform/resource/after-ecj/NonNullPlain.java +++ b/test/transform/resource/after-ecj/NonNullPlain.java @@ -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; } } \ No newline at end of file diff --git a/test/transform/resource/after-eclipse/NonNullPlain.java b/test/transform/resource/after-eclipse/NonNullPlain.java index 6f552436..252a2077 100644 --- a/test/transform/resource/after-eclipse/NonNullPlain.java +++ b/test/transform/resource/after-eclipse/NonNullPlain.java @@ -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; } } \ No newline at end of file diff --git a/test/transform/resource/before/NonNullPlain.java b/test/transform/resource/before/NonNullPlain.java index 265b8c5a..a438d1d4 100644 --- a/test/transform/resource/before/NonNullPlain.java +++ b/test/transform/resource/before/NonNullPlain.java @@ -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 {} } \ No newline at end of file -- cgit