diff options
author | Jan Rieke <rieke@subshell.com> | 2018-08-16 17:48:50 +0200 |
---|---|---|
committer | Jan Rieke <rieke@subshell.com> | 2018-08-16 17:48:50 +0200 |
commit | 46837d6d8be26cea9d0b8cf2959866ac308cbf2d (patch) | |
tree | 7f9522d0c9947f66a299bf1bb9661f826ba6408b /src/core/lombok/javac/handlers | |
parent | 8439cb5428a7dedbfa836b7028db7c7dba61293a (diff) | |
download | lombok-46837d6d8be26cea9d0b8cf2959866ac308cbf2d.tar.gz lombok-46837d6d8be26cea9d0b8cf2959866ac308cbf2d.tar.bz2 lombok-46837d6d8be26cea9d0b8cf2959866ac308cbf2d.zip |
do null checks after assignment so that default==null is covered
Diffstat (limited to 'src/core/lombok/javac/handlers')
-rw-r--r-- | src/core/lombok/javac/handlers/HandleSuperBuilder.java | 15 |
1 files changed, 7 insertions, 8 deletions
diff --git a/src/core/lombok/javac/handlers/HandleSuperBuilder.java b/src/core/lombok/javac/handlers/HandleSuperBuilder.java index c00bd66d..cc295beb 100644 --- a/src/core/lombok/javac/handlers/HandleSuperBuilder.java +++ b/src/core/lombok/javac/handlers/HandleSuperBuilder.java @@ -406,17 +406,10 @@ public class HandleSuperBuilder extends JavacAnnotationHandler<SuperBuilder> { AccessLevel level = AccessLevel.PROTECTED; - ListBuffer<JCStatement> nullChecks = new ListBuffer<JCStatement>(); ListBuffer<JCStatement> statements = new ListBuffer<JCStatement>(); Name builderVariableName = typeNode.toName("b"); for (BuilderFieldData bfd : builderFields) { - List<JCAnnotation> nonNulls = findAnnotations(bfd.originalFieldNode, NON_NULL_PATTERN); - if (!nonNulls.isEmpty()) { - JCStatement nullCheck = generateNullCheck(maker, bfd.originalFieldNode, source); - if (nullCheck != null) nullChecks.append(nullCheck); - } - JCExpression rhs; if (bfd.singularData != null && bfd.singularData.getSingularizer() != null) { bfd.singularData.getSingularizer().appendBuildCode(bfd.singularData, bfd.originalFieldNode, bfd.type, statements, bfd.name, "b"); @@ -436,6 +429,12 @@ public class HandleSuperBuilder extends JavacAnnotationHandler<SuperBuilder> { 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)); } + + List<JCAnnotation> nonNulls = findAnnotations(bfd.originalFieldNode, NON_NULL_PATTERN); + if (!nonNulls.isEmpty()) { + JCStatement nullCheck = generateNullCheck(maker, bfd.originalFieldNode, source); + if (nullCheck != null) statements.append(nullCheck); + } } JCModifiers mods = maker.Modifiers(toJavacModifier(level), List.<JCAnnotation>nil()); @@ -465,7 +464,7 @@ public class HandleSuperBuilder extends JavacAnnotationHandler<SuperBuilder> { JCMethodDecl constr = recursiveSetGeneratedBy(maker.MethodDef(mods, typeNode.toName("<init>"), null, List.<JCTypeParameter>nil(), params.toList(), List.<JCExpression>nil(), - maker.Block(0L, nullChecks.appendList(statements).toList()), null), source.get(), typeNode.getContext()); + maker.Block(0L, statements.toList()), null), source.get(), typeNode.getContext()); injectMethod(typeNode, constr, null, Javac.createVoidType(typeNode.getSymbolTable(), CTC_VOID)); } |