From 46837d6d8be26cea9d0b8cf2959866ac308cbf2d Mon Sep 17 00:00:00 2001 From: Jan Rieke Date: Thu, 16 Aug 2018 17:48:50 +0200 Subject: do null checks after assignment so that default==null is covered --- src/core/lombok/javac/handlers/HandleSuperBuilder.java | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) (limited to 'src/core/lombok') 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 { AccessLevel level = AccessLevel.PROTECTED; - ListBuffer nullChecks = new ListBuffer(); ListBuffer statements = new ListBuffer(); Name builderVariableName = typeNode.toName("b"); for (BuilderFieldData bfd : builderFields) { - List 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 { JCAssign assignDefault = maker.Assign(fieldInThis, maker.Apply(typeParameterNames(maker, ((JCClassDecl) typeNode.get()).typarams), maker.Select(maker.Ident(((JCClassDecl) typeNode.get()).name), bfd.nameOfDefaultProvider), List.nil())); statements.append(maker.If(maker.Unary(CTC_NOT, setField), maker.Exec(assignDefault), null)); } + + List 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.nil()); @@ -465,7 +464,7 @@ public class HandleSuperBuilder extends JavacAnnotationHandler { JCMethodDecl constr = recursiveSetGeneratedBy(maker.MethodDef(mods, typeNode.toName(""), null, List.nil(), params.toList(), List.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)); } -- cgit