aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/core/lombok/javac/handlers/HandleSuperBuilder.java7
-rw-r--r--test/transform/resource/after-delombok/SuperBuilderWithNonNull.java6
-rw-r--r--test/transform/resource/before/SuperBuilderWithNonNull.java2
3 files changed, 8 insertions, 7 deletions
diff --git a/src/core/lombok/javac/handlers/HandleSuperBuilder.java b/src/core/lombok/javac/handlers/HandleSuperBuilder.java
index cc295beb..aaf94dd8 100644
--- a/src/core/lombok/javac/handlers/HandleSuperBuilder.java
+++ b/src/core/lombok/javac/handlers/HandleSuperBuilder.java
@@ -420,14 +420,15 @@ public class HandleSuperBuilder extends JavacAnnotationHandler<SuperBuilder> {
JCFieldAccess fieldInThis = maker.Select(maker.Ident(typeNode.toName("this")), bfd.rawName);
JCStatement assign = maker.Exec(maker.Assign(fieldInThis, rhs));
- statements.append(assign);
- // In case of @Builder.Default, set the value to the default if it was NOT set in the builder.
+ // In case of @Builder.Default, set the value to the default if it was not set in the builder.
if (bfd.nameOfSetFlag != null) {
JCFieldAccess setField = maker.Select(maker.Ident(builderVariableName), bfd.nameOfSetFlag);
fieldInThis = maker.Select(maker.Ident(typeNode.toName("this")), bfd.rawName);
JCAssign assignDefault = maker.Assign(fieldInThis, maker.Apply(typeParameterNames(maker, ((JCClassDecl) typeNode.get()).typarams), maker.Select(maker.Ident(((JCClassDecl) typeNode.get()).name), bfd.nameOfDefaultProvider), List.<JCExpression>nil()));
- statements.append(maker.If(maker.Unary(CTC_NOT, setField), maker.Exec(assignDefault), null));
+ statements.append(maker.If(setField, assign, maker.Exec(assignDefault)));
+ } else {
+ statements.append(assign);
}
List<JCAnnotation> nonNulls = findAnnotations(bfd.originalFieldNode, NON_NULL_PATTERN);
diff --git a/test/transform/resource/after-delombok/SuperBuilderWithNonNull.java b/test/transform/resource/after-delombok/SuperBuilderWithNonNull.java
index 6fea9d17..5eba938f 100644
--- a/test/transform/resource/after-delombok/SuperBuilderWithNonNull.java
+++ b/test/transform/resource/after-delombok/SuperBuilderWithNonNull.java
@@ -2,7 +2,7 @@ import java.util.List;
public class SuperBuilderWithNonNull {
public static class Parent {
@lombok.NonNull
- String nonNullParentField;
+ final String nonNullParentField;
@java.lang.SuppressWarnings("all")
private static String $default$nonNullParentField() {
return "default";
@@ -47,8 +47,8 @@ public class SuperBuilderWithNonNull {
}
@java.lang.SuppressWarnings("all")
protected Parent(final ParentBuilder<?, ?> b) {
- this.nonNullParentField = b.nonNullParentField;
- if (!b.nonNullParentField$set) this.nonNullParentField = Parent.$default$nonNullParentField();
+ if (b.nonNullParentField$set) this.nonNullParentField = b.nonNullParentField;
+ else this.nonNullParentField = Parent.$default$nonNullParentField();
if (nonNullParentField == null) {
throw new java.lang.NullPointerException("nonNullParentField is marked @NonNull but is null");
}
diff --git a/test/transform/resource/before/SuperBuilderWithNonNull.java b/test/transform/resource/before/SuperBuilderWithNonNull.java
index 21f67a47..34668bbc 100644
--- a/test/transform/resource/before/SuperBuilderWithNonNull.java
+++ b/test/transform/resource/before/SuperBuilderWithNonNull.java
@@ -5,7 +5,7 @@ public class SuperBuilderWithNonNull {
public static class Parent {
@lombok.NonNull
@lombok.Builder.Default
- String nonNullParentField = "default";
+ final String nonNullParentField = "default";
}
@lombok.experimental.SuperBuilder