mirror of
https://github.com/tiennm99/lombok.git
synced 2026-10-13 02:14:44 +00:00
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
This commit is contained in:
1 parent
cf7290f861
commit
72b55dccb1
8 files changed
+43
No files matched your search
@@ -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.
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
6:36 @NonNull is meaningless on a parameter of an abstract method.
|
||||
@@ -0,0 +1 @@
|
||||
6:154 @NonNull is meaningless on a parameter of an abstract method.
|
||||
@@ -0,0 +1 @@
|
||||
9:36 @NonNull is meaningless on a parameter of an abstract method.
|
||||
Reference in new issue
Block a user