From e69a991fcb141fb24de8afb433c753d35821b1c3 Mon Sep 17 00:00:00 2001 From: Reinier Zwitserloot Date: Mon, 6 May 2019 22:48:11 +0200 Subject: [fixes #2120] ecj was not generating explicit nullchecks for builder-setters. --- src/core/lombok/javac/handlers/HandleSetter.java | 4 ++-- src/core/lombok/javac/handlers/JavacHandlerUtil.java | 9 +++++++++ 2 files changed, 11 insertions(+), 2 deletions(-) (limited to 'src/core/lombok/javac') diff --git a/src/core/lombok/javac/handlers/HandleSetter.java b/src/core/lombok/javac/handlers/HandleSetter.java index 28f5318d..c661ab89 100644 --- a/src/core/lombok/javac/handlers/HandleSetter.java +++ b/src/core/lombok/javac/handlers/HandleSetter.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2009-2017 The Project Lombok Authors. + * Copyright (C) 2009-2019 The Project Lombok Authors. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -234,7 +234,7 @@ public class HandleSetter extends JavacAnnotationHandler { long flags = JavacHandlerUtil.addFinalIfNeeded(Flags.PARAMETER, field.getContext()); JCVariableDecl param = treeMaker.VarDef(treeMaker.Modifiers(flags, annsOnParam), fieldDecl.name, fieldDecl.vartype, null); - if (!hasNonNullAnnotations(field)) { + if (!hasNonNullAnnotations(field) && !hasNonNullAnnotations(field, onParam)) { statements.append(treeMaker.Exec(assign)); } else { JCStatement nullCheck = generateNullCheck(treeMaker, field, source); diff --git a/src/core/lombok/javac/handlers/JavacHandlerUtil.java b/src/core/lombok/javac/handlers/JavacHandlerUtil.java index 509a7397..e923c5c0 100644 --- a/src/core/lombok/javac/handlers/JavacHandlerUtil.java +++ b/src/core/lombok/javac/handlers/JavacHandlerUtil.java @@ -1418,6 +1418,15 @@ public class JavacHandlerUtil { return false; } + public static boolean hasNonNullAnnotations(JavacNode node, List anns) { + if (anns == null) return false; + for (JCAnnotation ann : anns) { + for (String nn : NONNULL_ANNOTATIONS) if (typeMatches(nn, node, ann)) return true; + } + + return false; + } + /** * Searches the given field node for annotations and returns each one that is 'copyable' (either via configuration or from the base list). */ -- cgit