From 713822db9894cf99184aff57b3387f99846aa870 Mon Sep 17 00:00:00 2001 From: Reinier Zwitserloot Date: Tue, 27 May 2014 20:29:54 +0200 Subject: Changed the lombok.nonNull.exceptionType configkey to be an enum, partly to enforce only sensible exceptions and partly to make it possible to have the message be ‘x is null’ when throwing IAEs. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/core/lombok/javac/handlers/JavacHandlerUtil.java | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) (limited to 'src/core/lombok/javac') diff --git a/src/core/lombok/javac/handlers/JavacHandlerUtil.java b/src/core/lombok/javac/handlers/JavacHandlerUtil.java index 524af5de..6a60a420 100644 --- a/src/core/lombok/javac/handlers/JavacHandlerUtil.java +++ b/src/core/lombok/javac/handlers/JavacHandlerUtil.java @@ -43,6 +43,7 @@ import lombok.core.AnnotationValues; import lombok.core.AnnotationValues.AnnotationValue; import lombok.core.ReferenceFieldAugment; import lombok.core.TypeResolver; +import lombok.core.configuration.NullCheckExceptionType; import lombok.core.handlers.HandlerUtil; import lombok.delombok.LombokOptionsFactory; import lombok.experimental.Accessors; @@ -1046,21 +1047,14 @@ public class JavacHandlerUtil { * @param exName The name of the exception to throw; normally {@code java.lang.NullPointerException}. */ public static JCStatement generateNullCheck(JavacTreeMaker maker, JavacNode variable, JavacNode source) { - String exceptionType = source.getAst().readConfiguration(ConfigurationKeys.NON_NULL_EXCEPTION_TYPE); - if (exceptionType == null) { - exceptionType = HandlerUtil.DEFAULT_EXCEPTION_FOR_NON_NULL; - } else { - if (!HandlerUtil.isLegalBasicClassReference(exceptionType)) { - source.addWarning("Configuration key contains invalid java type reference '" + exceptionType + "'; use something like 'java.lang.NullPointerException' as value for this key."); - exceptionType = HandlerUtil.DEFAULT_EXCEPTION_FOR_NON_NULL; - } - } + NullCheckExceptionType exceptionType = source.getAst().readConfiguration(ConfigurationKeys.NON_NULL_EXCEPTION_TYPE); + if (exceptionType == null) exceptionType = NullCheckExceptionType.NULL_POINTER_EXCEPTION; JCVariableDecl varDecl = (JCVariableDecl) variable.get(); if (isPrimitive(varDecl.vartype)) return null; Name fieldName = varDecl.name; - JCExpression exType = genTypeRef(variable, exceptionType); - JCExpression exception = maker.NewClass(null, List.nil(), exType, List.of(maker.Literal(fieldName.toString())), null); + JCExpression exType = genTypeRef(variable, exceptionType.getExceptionType()); + JCExpression exception = maker.NewClass(null, List.nil(), exType, List.of(maker.Literal(exceptionType.toExceptionMessage(fieldName.toString()))), null); JCStatement throwStatement = maker.Throw(exception); JCBlock throwBlock = maker.Block(0, List.of(throwStatement)); return maker.If(maker.Binary(CTC_EQUAL, maker.Ident(fieldName), maker.Literal(CTC_BOT, null)), throwBlock, null); -- cgit