diff --git a/src/core/lombok/eclipse/handlers/NonNullHandler.java b/src/core/lombok/eclipse/handlers/NonNullHandler.java index 5c58069cf4..59fda8014a 100644 --- a/src/core/lombok/eclipse/handlers/NonNullHandler.java +++ b/src/core/lombok/eclipse/handlers/NonNullHandler.java @@ -82,6 +82,11 @@ public class NonNullHandler extends EclipseAnnotationHandler { if (isGenerated(declaration)) return; + if (declaration.isAbstract()) { + annotationNode.addWarning("@NonNull is meaningless on a parameter of an abstract method."); + return; + } + // Possibly, if 'declaration instanceof ConstructorDeclaration', fetch declaration.constructorCall, search it for any references to our parameter, // and if they exist, create a new method in the class: 'private static T lombok$nullCheck(T expr, String msg) {if (expr == null) throw NPE; return expr;}' and // wrap all references to it in the super/this to a call to this method. diff --git a/src/core/lombok/javac/handlers/NonNullHandler.java b/src/core/lombok/javac/handlers/NonNullHandler.java index 415d60329d..392e8390d7 100644 --- a/src/core/lombok/javac/handlers/NonNullHandler.java +++ b/src/core/lombok/javac/handlers/NonNullHandler.java @@ -76,6 +76,11 @@ public class NonNullHandler extends JavacAnnotationHandler { if (JavacHandlerUtil.isGenerated(declaration)) return; + if (declaration.body == null) { + annotationNode.addWarning("@NonNull is meaningless on a parameter of an abstract method."); + return; + } + // Possibly, if 'declaration instanceof ConstructorDeclaration', fetch declaration.constructorCall, search it for any references to our parameter, // and if they exist, create a new method in the class: 'private static T lombok$nullCheck(T expr, String msg) {if (expr == null) throw NPE; return expr;}' and // wrap all references to it in the super/this to a call to this method. diff --git a/test/transform/resource/after-delombok/NonNullOnParameterAbstract.java b/test/transform/resource/after-delombok/NonNullOnParameterAbstract.java new file mode 100644 index 0000000000..e0330bd6c8 --- /dev/null +++ b/test/transform/resource/after-delombok/NonNullOnParameterAbstract.java @@ -0,0 +1,10 @@ +abstract class NonNullOnParameterAbstract { + public void test(@lombok.NonNull String arg) { + if (arg == null) { + throw new java.lang.NullPointerException("arg"); + } + System.out.println("Hey"); + } + + public abstract void test2(@lombok.NonNull String arg); +} \ No newline at end of file diff --git a/test/transform/resource/after-ecj/NonNullOnParameterAbstract.java b/test/transform/resource/after-ecj/NonNullOnParameterAbstract.java new file mode 100644 index 0000000000..a7dae24708 --- /dev/null +++ b/test/transform/resource/after-ecj/NonNullOnParameterAbstract.java @@ -0,0 +1,13 @@ +abstract class NonNullOnParameterAbstract { + NonNullOnParameterAbstract() { + super(); + } + public void test(@lombok.NonNull String arg) { + if ((arg == null)) + { + throw new java.lang.NullPointerException("arg"); + } + System.out.println("Hey"); + } + public abstract void test2(@lombok.NonNull String arg); +} \ No newline at end of file diff --git a/test/transform/resource/before/NonNullOnParameterAbstract.java b/test/transform/resource/before/NonNullOnParameterAbstract.java new file mode 100644 index 0000000000..1669118416 --- /dev/null +++ b/test/transform/resource/before/NonNullOnParameterAbstract.java @@ -0,0 +1,7 @@ +abstract class NonNullOnParameterAbstract { + public void test(@lombok.NonNull String arg) { + System.out.println("Hey"); + } + + public abstract void test2(@lombok.NonNull String arg); +} \ No newline at end of file diff --git a/test/transform/resource/messages-delombok/NonNullOnParameterAbstract.java.messages b/test/transform/resource/messages-delombok/NonNullOnParameterAbstract.java.messages new file mode 100644 index 0000000000..1ebeea0545 --- /dev/null +++ b/test/transform/resource/messages-delombok/NonNullOnParameterAbstract.java.messages @@ -0,0 +1 @@ +6:36 @NonNull is meaningless on a parameter of an abstract method. diff --git a/test/transform/resource/messages-ecj/NonNullOnParameterAbstract.java.messages b/test/transform/resource/messages-ecj/NonNullOnParameterAbstract.java.messages new file mode 100644 index 0000000000..48d1508eb0 --- /dev/null +++ b/test/transform/resource/messages-ecj/NonNullOnParameterAbstract.java.messages @@ -0,0 +1 @@ +6:154 @NonNull is meaningless on a parameter of an abstract method. \ No newline at end of file diff --git a/test/transform/resource/messages-idempotent/NonNullOnParameterAbstract.java.messages b/test/transform/resource/messages-idempotent/NonNullOnParameterAbstract.java.messages new file mode 100644 index 0000000000..0054717166 --- /dev/null +++ b/test/transform/resource/messages-idempotent/NonNullOnParameterAbstract.java.messages @@ -0,0 +1 @@ +9:36 @NonNull is meaningless on a parameter of an abstract method. \ No newline at end of file