diff options
author | Reinier Zwitserloot <reinier@zwitserloot.com> | 2018-10-15 21:12:45 +0200 |
---|---|---|
committer | Reinier Zwitserloot <reinier@zwitserloot.com> | 2018-10-15 21:16:03 +0200 |
commit | 94eadb5131b32b6cf599a3f5445524a08ba0569b (patch) | |
tree | 391e310ec42d25e9ee26bbff57290d492da23f51 /test/transform | |
parent | 06455de367932e93da707b9d91e1a347d0c072a6 (diff) | |
download | lombok-94eadb5131b32b6cf599a3f5445524a08ba0569b.tar.gz lombok-94eadb5131b32b6cf599a3f5445524a08ba0569b.tar.bz2 lombok-94eadb5131b32b6cf599a3f5445524a08ba0569b.zip |
[fixes #1324] toBuilder with @Singular marked collections that are null no longer throws NPE.
Diffstat (limited to 'test/transform')
5 files changed, 46 insertions, 123 deletions
diff --git a/test/transform/resource/after-delombok/BuilderSingularToBuilderWithNull.java b/test/transform/resource/after-delombok/BuilderSingularToBuilderWithNull.java index b0563858..96ffd2dc 100644 --- a/test/transform/resource/after-delombok/BuilderSingularToBuilderWithNull.java +++ b/test/transform/resource/after-delombok/BuilderSingularToBuilderWithNull.java @@ -58,6 +58,8 @@ class BuilderSingularToBuilderWithNull { } @java.lang.SuppressWarnings("all") public BuilderSingularToBuilderWithNullBuilder toBuilder() { - return new BuilderSingularToBuilderWithNullBuilder().elems(this.elems == null ? java.util.Collections.<String>emptyList() : this.elems); + final BuilderSingularToBuilderWithNullBuilder builder = new BuilderSingularToBuilderWithNullBuilder(); + if (this.elems != null) builder.elems(this.elems); + return builder; } } diff --git a/test/transform/resource/after-delombok/BuilderWithToBuilder.java b/test/transform/resource/after-delombok/BuilderWithToBuilder.java index 8615a40b..53256107 100644 --- a/test/transform/resource/after-delombok/BuilderWithToBuilder.java +++ b/test/transform/resource/after-delombok/BuilderWithToBuilder.java @@ -86,7 +86,9 @@ class BuilderWithToBuilder<T> { } @java.lang.SuppressWarnings("all") public BuilderWithToBuilderBuilder<T> toBuilder() { - return new BuilderWithToBuilderBuilder<T>().one(this.mOne).two(this.mTwo).foo(BuilderWithToBuilder.rrr(this)).bars(this.bars == null ? java.util.Collections.<T>emptyList() : this.bars); + final BuilderWithToBuilderBuilder<T> builder = new BuilderWithToBuilderBuilder<T>().one(this.mOne).two(this.mTwo).foo(BuilderWithToBuilder.rrr(this)); + if (this.bars != null) builder.bars(this.bars); + return builder; } } class ConstructorWithToBuilder<T> { @@ -94,15 +96,17 @@ class ConstructorWithToBuilder<T> { private String mTwo; private T foo; @lombok.Singular - private List<T> bars; - public ConstructorWithToBuilder(String mOne, T bar) { + private com.google.common.collect.ImmutableList<T> bars; + public ConstructorWithToBuilder(String mOne, T baz, com.google.common.collect.ImmutableList<T> bars) { } @java.lang.SuppressWarnings("all") public static class ConstructorWithToBuilderBuilder<T> { @java.lang.SuppressWarnings("all") private String mOne; @java.lang.SuppressWarnings("all") - private T bar; + private T baz; + @java.lang.SuppressWarnings("all") + private com.google.common.collect.ImmutableList<T> bars; @java.lang.SuppressWarnings("all") ConstructorWithToBuilderBuilder() { } @@ -112,18 +116,23 @@ class ConstructorWithToBuilder<T> { return this; } @java.lang.SuppressWarnings("all") - public ConstructorWithToBuilderBuilder<T> bar(final T bar) { - this.bar = bar; + public ConstructorWithToBuilderBuilder<T> baz(final T baz) { + this.baz = baz; + return this; + } + @java.lang.SuppressWarnings("all") + public ConstructorWithToBuilderBuilder<T> bars(final com.google.common.collect.ImmutableList<T> bars) { + this.bars = bars; return this; } @java.lang.SuppressWarnings("all") public ConstructorWithToBuilder<T> build() { - return new ConstructorWithToBuilder<T>(mOne, bar); + return new ConstructorWithToBuilder<T>(mOne, baz, bars); } @java.lang.Override @java.lang.SuppressWarnings("all") public java.lang.String toString() { - return "ConstructorWithToBuilder.ConstructorWithToBuilderBuilder(mOne=" + this.mOne + ", bar=" + this.bar + ")"; + return "ConstructorWithToBuilder.ConstructorWithToBuilderBuilder(mOne=" + this.mOne + ", baz=" + this.baz + ", bars=" + this.bars + ")"; } } @java.lang.SuppressWarnings("all") @@ -132,54 +141,6 @@ class ConstructorWithToBuilder<T> { } @java.lang.SuppressWarnings("all") public ConstructorWithToBuilderBuilder<T> toBuilder() { - return new ConstructorWithToBuilderBuilder<T>().mOne(this.mOne).bar(this.foo); + return new ConstructorWithToBuilderBuilder<T>().mOne(this.mOne).baz(this.foo).bars(this.bars); } -} -class StaticWithToBuilder<T, K> { - private String mOne; - private String mTwo; - private T foo; - private K bar; - @lombok.Singular - private List<T> bars; - public static <Z> StaticWithToBuilder<Z, String> test(String mOne, Z bar) { - return new StaticWithToBuilder<Z, String>(); - } - @java.lang.SuppressWarnings("all") - public static class StaticWithToBuilderBuilder<Z> { - @java.lang.SuppressWarnings("all") - private String mOne; - @java.lang.SuppressWarnings("all") - private Z bar; - @java.lang.SuppressWarnings("all") - StaticWithToBuilderBuilder() { - } - @java.lang.SuppressWarnings("all") - public StaticWithToBuilderBuilder<Z> mOne(final String mOne) { - this.mOne = mOne; - return this; - } - @java.lang.SuppressWarnings("all") - public StaticWithToBuilderBuilder<Z> bar(final Z bar) { - this.bar = bar; - return this; - } - @java.lang.SuppressWarnings("all") - public StaticWithToBuilder<Z, String> build() { - return StaticWithToBuilder.<Z>test(mOne, bar); - } - @java.lang.Override - @java.lang.SuppressWarnings("all") - public java.lang.String toString() { - return "StaticWithToBuilder.StaticWithToBuilderBuilder(mOne=" + this.mOne + ", bar=" + this.bar + ")"; - } - } - @java.lang.SuppressWarnings("all") - public static <Z> StaticWithToBuilderBuilder<Z> builder() { - return new StaticWithToBuilderBuilder<Z>(); - } - @java.lang.SuppressWarnings("all") - public StaticWithToBuilderBuilder<T> toBuilder() { - return new StaticWithToBuilderBuilder<T>().mOne(this.mOne).bar(this.foo); - } -} +}
\ No newline at end of file diff --git a/test/transform/resource/after-ecj/BuilderSingularToBuilderWithNull.java b/test/transform/resource/after-ecj/BuilderSingularToBuilderWithNull.java index bbbf9268..ccd6335a 100644 --- a/test/transform/resource/after-ecj/BuilderSingularToBuilderWithNull.java +++ b/test/transform/resource/after-ecj/BuilderSingularToBuilderWithNull.java @@ -52,6 +52,9 @@ import lombok.Singular; return new BuilderSingularToBuilderWithNullBuilder(); } public @java.lang.SuppressWarnings("all") BuilderSingularToBuilderWithNullBuilder toBuilder() { - return new BuilderSingularToBuilderWithNullBuilder().elems(((this.elems == null) ? java.util.Collections.<String>emptyList() : this.elems)); + final BuilderSingularToBuilderWithNullBuilder builder = new BuilderSingularToBuilderWithNullBuilder(); + if ((this.elems != null)) + builder.elems(this.elems); + return builder; } -} +}
\ No newline at end of file diff --git a/test/transform/resource/after-ecj/BuilderWithToBuilder.java b/test/transform/resource/after-ecj/BuilderWithToBuilder.java index 636dc42d..420f1583 100644 --- a/test/transform/resource/after-ecj/BuilderWithToBuilder.java +++ b/test/transform/resource/after-ecj/BuilderWithToBuilder.java @@ -74,13 +74,17 @@ import lombok.Builder; return new BuilderWithToBuilderBuilder<T>(); } public @java.lang.SuppressWarnings("all") BuilderWithToBuilderBuilder<T> toBuilder() { - return new BuilderWithToBuilderBuilder<T>().one(this.mOne).two(this.mTwo).foo(BuilderWithToBuilder.rrr(this)).bars(((this.bars == null) ? java.util.Collections.<T>emptyList() : this.bars)); + final BuilderWithToBuilderBuilder<T> builder = new BuilderWithToBuilderBuilder<T>().one(this.mOne).two(this.mTwo).foo(BuilderWithToBuilder.rrr(this)); + if ((this.bars != null)) + builder.bars(this.bars); + return builder; } } @lombok.experimental.Accessors(prefix = "m") class ConstructorWithToBuilder<T> { public static @java.lang.SuppressWarnings("all") class ConstructorWithToBuilderBuilder<T> { private @java.lang.SuppressWarnings("all") String mOne; - private @java.lang.SuppressWarnings("all") T bar; + private @java.lang.SuppressWarnings("all") T baz; + private @java.lang.SuppressWarnings("all") com.google.common.collect.ImmutableList<T> bars; @java.lang.SuppressWarnings("all") ConstructorWithToBuilderBuilder() { super(); } @@ -88,68 +92,32 @@ import lombok.Builder; this.mOne = mOne; return this; } - public @java.lang.SuppressWarnings("all") ConstructorWithToBuilderBuilder<T> bar(final T bar) { - this.bar = bar; + public @java.lang.SuppressWarnings("all") ConstructorWithToBuilderBuilder<T> baz(final T baz) { + this.baz = baz; + return this; + } + public @java.lang.SuppressWarnings("all") ConstructorWithToBuilderBuilder<T> bars(final com.google.common.collect.ImmutableList<T> bars) { + this.bars = bars; return this; } public @java.lang.SuppressWarnings("all") ConstructorWithToBuilder<T> build() { - return new ConstructorWithToBuilder<T>(mOne, bar); + return new ConstructorWithToBuilder<T>(mOne, baz, bars); } public @java.lang.Override @java.lang.SuppressWarnings("all") java.lang.String toString() { - return (((("ConstructorWithToBuilder.ConstructorWithToBuilderBuilder(mOne=" + this.mOne) + ", bar=") + this.bar) + ")"); + return (((((("ConstructorWithToBuilder.ConstructorWithToBuilderBuilder(mOne=" + this.mOne) + ", baz=") + this.baz) + ", bars=") + this.bars) + ")"); } } private String mOne; private String mTwo; private T foo; - private @lombok.Singular List<T> bars; - public @Builder(toBuilder = true) ConstructorWithToBuilder(String mOne, @Builder.ObtainVia(field = "foo") T bar) { + private @lombok.Singular com.google.common.collect.ImmutableList<T> bars; + public @Builder(toBuilder = true) ConstructorWithToBuilder(String mOne, @Builder.ObtainVia(field = "foo") T baz, com.google.common.collect.ImmutableList<T> bars) { super(); } public static @java.lang.SuppressWarnings("all") <T>ConstructorWithToBuilderBuilder<T> builder() { return new ConstructorWithToBuilderBuilder<T>(); } public @java.lang.SuppressWarnings("all") ConstructorWithToBuilderBuilder<T> toBuilder() { - return new ConstructorWithToBuilderBuilder<T>().mOne(this.mOne).bar(this.foo); - } -} -@lombok.experimental.Accessors(prefix = "m") class StaticWithToBuilder<T, K> { - public static @java.lang.SuppressWarnings("all") class StaticWithToBuilderBuilder<Z> { - private @java.lang.SuppressWarnings("all") String mOne; - private @java.lang.SuppressWarnings("all") Z bar; - @java.lang.SuppressWarnings("all") StaticWithToBuilderBuilder() { - super(); - } - public @java.lang.SuppressWarnings("all") StaticWithToBuilderBuilder<Z> mOne(final String mOne) { - this.mOne = mOne; - return this; - } - public @java.lang.SuppressWarnings("all") StaticWithToBuilderBuilder<Z> bar(final Z bar) { - this.bar = bar; - return this; - } - public @java.lang.SuppressWarnings("all") StaticWithToBuilder<Z, String> build() { - return StaticWithToBuilder.<Z>test(mOne, bar); - } - public @java.lang.Override @java.lang.SuppressWarnings("all") java.lang.String toString() { - return (((("StaticWithToBuilder.StaticWithToBuilderBuilder(mOne=" + this.mOne) + ", bar=") + this.bar) + ")"); - } - } - private String mOne; - private String mTwo; - private T foo; - private K bar; - private @lombok.Singular List<T> bars; - StaticWithToBuilder() { - super(); - } - public static @Builder(toBuilder = true) <Z>StaticWithToBuilder<Z, String> test(String mOne, @Builder.ObtainVia(field = "foo") Z bar) { - return new StaticWithToBuilder<Z, String>(); - } - public static @java.lang.SuppressWarnings("all") <Z>StaticWithToBuilderBuilder<Z> builder() { - return new StaticWithToBuilderBuilder<Z>(); - } - public @java.lang.SuppressWarnings("all") StaticWithToBuilderBuilder<T> toBuilder() { - return new StaticWithToBuilderBuilder<T>().mOne(this.mOne).bar(this.foo); + return new ConstructorWithToBuilderBuilder<T>().mOne(this.mOne).baz(this.foo).bars(this.bars); } } diff --git a/test/transform/resource/before/BuilderWithToBuilder.java b/test/transform/resource/before/BuilderWithToBuilder.java index 63e16ae8..50938ab2 100644 --- a/test/transform/resource/before/BuilderWithToBuilder.java +++ b/test/transform/resource/before/BuilderWithToBuilder.java @@ -13,19 +13,8 @@ class BuilderWithToBuilder<T> { class ConstructorWithToBuilder<T> { private String mOne, mTwo; private T foo; - @lombok.Singular private List<T> bars; - @Builder(toBuilder = true) - public ConstructorWithToBuilder(String mOne, @Builder.ObtainVia(field = "foo") T bar) { - } -} -@lombok.experimental.Accessors(prefix = "m") -class StaticWithToBuilder<T, K> { - private String mOne, mTwo; - private T foo; - private K bar; - @lombok.Singular private List<T> bars; + @lombok.Singular private com.google.common.collect.ImmutableList<T> bars; @Builder(toBuilder = true) - public static <Z> StaticWithToBuilder<Z, String> test(String mOne, @Builder.ObtainVia(field = "foo") Z bar) { - return new StaticWithToBuilder<Z, String>(); + public ConstructorWithToBuilder(String mOne, @Builder.ObtainVia(field = "foo") T baz, com.google.common.collect.ImmutableList<T> bars) { } } |