diff options
author | Sander Koning <askoning@gmail.com> | 2013-09-20 17:13:39 +0200 |
---|---|---|
committer | Sander Koning <askoning@gmail.com> | 2013-09-20 17:13:39 +0200 |
commit | 72b55dccb18f38b8aefd0ac8e7c2e8bd2dd5c057 (patch) | |
tree | 253be100a1c3402e42426dd028a8fdacf2161c9b /src/core/lombok | |
parent | cf7290f86133bbed53c78120453ddfc2ed734fac (diff) | |
download | lombok-72b55dccb18f38b8aefd0ac8e7c2e8bd2dd5c057.tar.gz lombok-72b55dccb18f38b8aefd0ac8e7c2e8bd2dd5c057.tar.bz2 lombok-72b55dccb18f38b8aefd0ac8e7c2e8bd2dd5c057.zip |
Issue 559: NullPointerException when @NonNull is used in abstract method
- Prevent NPE in javac and give a proper warning in both eclipse and javac
- Add test cases
Diffstat (limited to 'src/core/lombok')
-rw-r--r-- | src/core/lombok/eclipse/handlers/NonNullHandler.java | 5 | ||||
-rw-r--r-- | src/core/lombok/javac/handlers/NonNullHandler.java | 5 |
2 files changed, 10 insertions, 0 deletions
diff --git a/src/core/lombok/eclipse/handlers/NonNullHandler.java b/src/core/lombok/eclipse/handlers/NonNullHandler.java index 5c58069c..59fda801 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<NonNull> { 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> 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 415d6032..392e8390 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<NonNull> { 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> 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. |