Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2772 from janrieke/superBuilderNPEwithSingular
[fixes #2701] fix NPE on customized SuperBuilder with Singular
- Loading branch information
Showing
4 changed files
with
157 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
77 changes: 77 additions & 0 deletions
77
test/transform/resource/after-delombok/SuperBuilderSingularCustomized.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
import java.util.Set; | ||
class SuperBuilderSingularCustomized { | ||
private Set<String> foos; | ||
public static abstract class SuperBuilderSingularCustomizedBuilder<C extends SuperBuilderSingularCustomized, B extends SuperBuilderSingularCustomized.SuperBuilderSingularCustomizedBuilder<C, B>> { | ||
@java.lang.SuppressWarnings("all") | ||
private java.util.ArrayList<String> foos; | ||
public B custom(final String value) { | ||
return self(); | ||
} | ||
@java.lang.SuppressWarnings("all") | ||
protected abstract B self(); | ||
@java.lang.SuppressWarnings("all") | ||
public abstract C build(); | ||
@java.lang.SuppressWarnings("all") | ||
public B foo(final String foo) { | ||
if (this.foos == null) this.foos = new java.util.ArrayList<String>(); | ||
this.foos.add(foo); | ||
return self(); | ||
} | ||
@java.lang.SuppressWarnings("all") | ||
public B foos(final java.util.Collection<? extends String> foos) { | ||
if (foos == null) { | ||
throw new java.lang.NullPointerException("foos cannot be null"); | ||
} | ||
if (this.foos == null) this.foos = new java.util.ArrayList<String>(); | ||
this.foos.addAll(foos); | ||
return self(); | ||
} | ||
@java.lang.SuppressWarnings("all") | ||
public B clearFoos() { | ||
if (this.foos != null) this.foos.clear(); | ||
return self(); | ||
} | ||
@java.lang.Override | ||
@java.lang.SuppressWarnings("all") | ||
public java.lang.String toString() { | ||
return "SuperBuilderSingularCustomized.SuperBuilderSingularCustomizedBuilder(foos=" + this.foos + ")"; | ||
} | ||
} | ||
@java.lang.SuppressWarnings("all") | ||
private static final class SuperBuilderSingularCustomizedBuilderImpl extends SuperBuilderSingularCustomized.SuperBuilderSingularCustomizedBuilder<SuperBuilderSingularCustomized, SuperBuilderSingularCustomized.SuperBuilderSingularCustomizedBuilderImpl> { | ||
@java.lang.SuppressWarnings("all") | ||
private SuperBuilderSingularCustomizedBuilderImpl() { | ||
} | ||
@java.lang.Override | ||
@java.lang.SuppressWarnings("all") | ||
protected SuperBuilderSingularCustomized.SuperBuilderSingularCustomizedBuilderImpl self() { | ||
return this; | ||
} | ||
@java.lang.Override | ||
@java.lang.SuppressWarnings("all") | ||
public SuperBuilderSingularCustomized build() { | ||
return new SuperBuilderSingularCustomized(this); | ||
} | ||
} | ||
@java.lang.SuppressWarnings("all") | ||
protected SuperBuilderSingularCustomized(final SuperBuilderSingularCustomized.SuperBuilderSingularCustomizedBuilder<?, ?> b) { | ||
java.util.Set<String> foos; | ||
switch (b.foos == null ? 0 : b.foos.size()) { | ||
case 0: | ||
foos = java.util.Collections.emptySet(); | ||
break; | ||
case 1: | ||
foos = java.util.Collections.singleton(b.foos.get(0)); | ||
break; | ||
default: | ||
foos = new java.util.LinkedHashSet<String>(b.foos.size() < 1073741824 ? 1 + b.foos.size() + (b.foos.size() - 3) / 3 : java.lang.Integer.MAX_VALUE); | ||
foos.addAll(b.foos); | ||
foos = java.util.Collections.unmodifiableSet(foos); | ||
} | ||
this.foos = foos; | ||
} | ||
@java.lang.SuppressWarnings("all") | ||
public static SuperBuilderSingularCustomized.SuperBuilderSingularCustomizedBuilder<?, ?> builder() { | ||
return new SuperBuilderSingularCustomized.SuperBuilderSingularCustomizedBuilderImpl(); | ||
} | ||
} |
70 changes: 70 additions & 0 deletions
70
test/transform/resource/after-ecj/SuperBuilderSingularCustomized.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
import java.util.Set; | ||
@lombok.experimental.SuperBuilder class SuperBuilderSingularCustomized { | ||
public static abstract class SuperBuilderSingularCustomizedBuilder<C extends SuperBuilderSingularCustomized, B extends SuperBuilderSingularCustomized.SuperBuilderSingularCustomizedBuilder<C, B>> { | ||
private @java.lang.SuppressWarnings("all") java.util.ArrayList<String> foos; | ||
public SuperBuilderSingularCustomizedBuilder() { | ||
super(); | ||
} | ||
public B custom(final String value) { | ||
return self(); | ||
} | ||
protected abstract @java.lang.SuppressWarnings("all") B self(); | ||
public abstract @java.lang.SuppressWarnings("all") C build(); | ||
public @java.lang.SuppressWarnings("all") B foo(final String foo) { | ||
if ((this.foos == null)) | ||
this.foos = new java.util.ArrayList<String>(); | ||
this.foos.add(foo); | ||
return self(); | ||
} | ||
public @java.lang.SuppressWarnings("all") B foos(final java.util.Collection<? extends String> foos) { | ||
if ((foos == null)) | ||
{ | ||
throw new java.lang.NullPointerException("foos cannot be null"); | ||
} | ||
if ((this.foos == null)) | ||
this.foos = new java.util.ArrayList<String>(); | ||
this.foos.addAll(foos); | ||
return self(); | ||
} | ||
public @java.lang.SuppressWarnings("all") B clearFoos() { | ||
if ((this.foos != null)) | ||
this.foos.clear(); | ||
return self(); | ||
} | ||
public @java.lang.Override @java.lang.SuppressWarnings("all") java.lang.String toString() { | ||
return (("SuperBuilderSingularCustomized.SuperBuilderSingularCustomizedBuilder(foos=" + this.foos) + ")"); | ||
} | ||
} | ||
private static final @java.lang.SuppressWarnings("all") class SuperBuilderSingularCustomizedBuilderImpl extends SuperBuilderSingularCustomized.SuperBuilderSingularCustomizedBuilder<SuperBuilderSingularCustomized, SuperBuilderSingularCustomized.SuperBuilderSingularCustomizedBuilderImpl> { | ||
private SuperBuilderSingularCustomizedBuilderImpl() { | ||
super(); | ||
} | ||
protected @java.lang.Override @java.lang.SuppressWarnings("all") SuperBuilderSingularCustomized.SuperBuilderSingularCustomizedBuilderImpl self() { | ||
return this; | ||
} | ||
public @java.lang.Override @java.lang.SuppressWarnings("all") SuperBuilderSingularCustomized build() { | ||
return new SuperBuilderSingularCustomized(this); | ||
} | ||
} | ||
private @lombok.Singular Set<String> foos; | ||
protected @java.lang.SuppressWarnings("all") SuperBuilderSingularCustomized(final SuperBuilderSingularCustomized.SuperBuilderSingularCustomizedBuilder<?, ?> b) { | ||
super(); | ||
java.util.Set<String> foos; | ||
switch (((b.foos == null) ? 0 : b.foos.size())) { | ||
case 0 : | ||
foos = java.util.Collections.emptySet(); | ||
break; | ||
case 1 : | ||
foos = java.util.Collections.singleton(b.foos.get(0)); | ||
break; | ||
default : | ||
foos = new java.util.LinkedHashSet<String>(((b.foos.size() < 0x40000000) ? ((1 + b.foos.size()) + ((b.foos.size() - 3) / 3)) : java.lang.Integer.MAX_VALUE)); | ||
foos.addAll(b.foos); | ||
foos = java.util.Collections.unmodifiableSet(foos); | ||
} | ||
this.foos = foos; | ||
} | ||
public static @java.lang.SuppressWarnings("all") SuperBuilderSingularCustomized.SuperBuilderSingularCustomizedBuilder<?, ?> builder() { | ||
return new SuperBuilderSingularCustomized.SuperBuilderSingularCustomizedBuilderImpl(); | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
test/transform/resource/before/SuperBuilderSingularCustomized.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import java.util.Set; | ||
@lombok.experimental.SuperBuilder | ||
class SuperBuilderSingularCustomized { | ||
@lombok.Singular private Set<String> foos; | ||
public static abstract class SuperBuilderSingularCustomizedBuilder<C extends SuperBuilderSingularCustomized, B extends SuperBuilderSingularCustomized.SuperBuilderSingularCustomizedBuilder<C, B>> { | ||
public B custom(final String value) { | ||
return self(); | ||
} | ||
}} |