From bad93ae677622c79883f658a53484d455e36ce9a Mon Sep 17 00:00:00 2001 From: Roel Spilker Date: Mon, 19 Aug 2013 23:50:57 +0200 Subject: Only look at the line number for errors and warnings. --- .../resource/messages-idempotent/NonNullOnParameter.java.messages | 2 +- .../resource/messages-idempotent/NonNullPlain.java.messages | 6 +++--- .../resource/messages-idempotent/SimpleTypeResolution.java.messages | 2 +- .../SynchronizedNameStaticToInstanceRef.java.messages | 2 +- test/transform/resource/messages-idempotent/ValErrors.java.messages | 6 +++--- .../resource/messages-idempotent/ValInBasicFor.java.messages | 2 +- 6 files changed, 10 insertions(+), 10 deletions(-) (limited to 'test/transform/resource/messages-idempotent') diff --git a/test/transform/resource/messages-idempotent/NonNullOnParameter.java.messages b/test/transform/resource/messages-idempotent/NonNullOnParameter.java.messages index fd23a32a..57556bf3 100644 --- a/test/transform/resource/messages-idempotent/NonNullOnParameter.java.messages +++ b/test/transform/resource/messages-idempotent/NonNullOnParameter.java.messages @@ -1 +1 @@ -33:89 @NonNull is meaningless on a primitive. \ No newline at end of file +33 @NonNull is meaningless on a primitive. \ No newline at end of file diff --git a/test/transform/resource/messages-idempotent/NonNullPlain.java.messages b/test/transform/resource/messages-idempotent/NonNullPlain.java.messages index c48da311..1d8c4d9c 100644 --- a/test/transform/resource/messages-idempotent/NonNullPlain.java.messages +++ b/test/transform/resource/messages-idempotent/NonNullPlain.java.messages @@ -1,3 +1,3 @@ -4:9 @NonNull is meaningless on a primitive. -18:29 @NonNull is meaningless on a primitive. -44:26 @NonNull is meaningless on a primitive. \ No newline at end of file +3 @NonNull is meaningless on a primitive. +15 @NonNull is meaningless on a primitive. +37 @NonNull is meaningless on a primitive. \ No newline at end of file diff --git a/test/transform/resource/messages-idempotent/SimpleTypeResolution.java.messages b/test/transform/resource/messages-idempotent/SimpleTypeResolution.java.messages index 7acd35ed..ec74f090 100644 --- a/test/transform/resource/messages-idempotent/SimpleTypeResolution.java.messages +++ b/test/transform/resource/messages-idempotent/SimpleTypeResolution.java.messages @@ -1 +1 @@ -2:10 cannot find symbol +2 cannot find symbol diff --git a/test/transform/resource/messages-idempotent/SynchronizedNameStaticToInstanceRef.java.messages b/test/transform/resource/messages-idempotent/SynchronizedNameStaticToInstanceRef.java.messages index ed3eccb1..53b39d98 100644 --- a/test/transform/resource/messages-idempotent/SynchronizedNameStaticToInstanceRef.java.messages +++ b/test/transform/resource/messages-idempotent/SynchronizedNameStaticToInstanceRef.java.messages @@ -1 +1 @@ -5:66 non-static variable read cannot be referenced from a static context +5 non-static variable read cannot be referenced from a static context diff --git a/test/transform/resource/messages-idempotent/ValErrors.java.messages b/test/transform/resource/messages-idempotent/ValErrors.java.messages index 9bee37d4..c2432c6a 100644 --- a/test/transform/resource/messages-idempotent/ValErrors.java.messages +++ b/test/transform/resource/messages-idempotent/ValErrors.java.messages @@ -1,3 +1,3 @@ -3:44 cannot find symbol -6:17 cannot find symbol -6:25 illegal initializer for +3 cannot find symbol +6 cannot find symbol +6 illegal initializer for diff --git a/test/transform/resource/messages-idempotent/ValInBasicFor.java.messages b/test/transform/resource/messages-idempotent/ValInBasicFor.java.messages index fb675485..67842eb9 100644 --- a/test/transform/resource/messages-idempotent/ValInBasicFor.java.messages +++ b/test/transform/resource/messages-idempotent/ValInBasicFor.java.messages @@ -1 +1 @@ -5:53 'val' is not allowed in old-style for loops +5 'val' is not allowed in old-style for loops -- cgit From 72b55dccb18f38b8aefd0ac8e7c2e8bd2dd5c057 Mon Sep 17 00:00:00 2001 From: Sander Koning Date: Fri, 20 Sep 2013 17:13:39 +0200 Subject: 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 --- src/core/lombok/eclipse/handlers/NonNullHandler.java | 5 +++++ src/core/lombok/javac/handlers/NonNullHandler.java | 5 +++++ .../resource/after-delombok/NonNullOnParameterAbstract.java | 10 ++++++++++ .../resource/after-ecj/NonNullOnParameterAbstract.java | 13 +++++++++++++ .../resource/before/NonNullOnParameterAbstract.java | 7 +++++++ .../NonNullOnParameterAbstract.java.messages | 1 + .../messages-ecj/NonNullOnParameterAbstract.java.messages | 1 + .../NonNullOnParameterAbstract.java.messages | 1 + 8 files changed, 43 insertions(+) create mode 100644 test/transform/resource/after-delombok/NonNullOnParameterAbstract.java create mode 100644 test/transform/resource/after-ecj/NonNullOnParameterAbstract.java create mode 100644 test/transform/resource/before/NonNullOnParameterAbstract.java create mode 100644 test/transform/resource/messages-delombok/NonNullOnParameterAbstract.java.messages create mode 100644 test/transform/resource/messages-ecj/NonNullOnParameterAbstract.java.messages create mode 100644 test/transform/resource/messages-idempotent/NonNullOnParameterAbstract.java.messages (limited to 'test/transform/resource/messages-idempotent') 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 { 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 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 { 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 00000000..e0330bd6 --- /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 00000000..a7dae247 --- /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 00000000..16691184 --- /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 00000000..1ebeea05 --- /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 00000000..48d1508e --- /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 00000000..00547171 --- /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 -- cgit From 7b8a85e1f991f838d6692ef789f53ed604a4a4e9 Mon Sep 17 00:00:00 2001 From: Reinier Zwitserloot Date: Tue, 24 Sep 2013 01:33:22 +0200 Subject: Fixed slight typo issues with the tests due to merging and icelandic on the fly bug fixing. --- .../EqualsAndHashCodeWithSomeExistingMethods.java.messages | 4 ++-- .../messages-delombok/NonNullOnParameterAbstract.java.messages | 2 +- .../EqualsAndHashCodeWithSomeExistingMethods.java.messages | 4 ++-- .../resource/messages-ecj/NonNullOnParameterAbstract.java.messages | 2 +- .../messages-idempotent/NonNullOnParameterAbstract.java.messages | 2 +- 5 files changed, 7 insertions(+), 7 deletions(-) (limited to 'test/transform/resource/messages-idempotent') diff --git a/test/transform/resource/messages-delombok/EqualsAndHashCodeWithSomeExistingMethods.java.messages b/test/transform/resource/messages-delombok/EqualsAndHashCodeWithSomeExistingMethods.java.messages index f5dfd559..75ddfa54 100644 --- a/test/transform/resource/messages-delombok/EqualsAndHashCodeWithSomeExistingMethods.java.messages +++ b/test/transform/resource/messages-delombok/EqualsAndHashCodeWithSomeExistingMethods.java.messages @@ -1,2 +1,2 @@ -4 Not generating equals: One of equals, hashCode, and canEqual exists. You should either write all of these are none of these (in the latter case, lombok generates them). -15 Not generating equals and hashCode: One of equals, hashCode, and canEqual exists. You should either write all of these are none of these (in the latter case, lombok generates them). +4 Not generating equals: One of equals, hashCode, and canEqual exists. You should either write all of these or none of these (in the latter case, lombok generates them). +15 Not generating equals and hashCode: One of equals, hashCode, and canEqual exists. You should either write all of these or none of these (in the latter case, lombok generates them). diff --git a/test/transform/resource/messages-delombok/NonNullOnParameterAbstract.java.messages b/test/transform/resource/messages-delombok/NonNullOnParameterAbstract.java.messages index 1ebeea05..fd5bffd5 100644 --- a/test/transform/resource/messages-delombok/NonNullOnParameterAbstract.java.messages +++ b/test/transform/resource/messages-delombok/NonNullOnParameterAbstract.java.messages @@ -1 +1 @@ -6:36 @NonNull is meaningless on a parameter of an abstract method. +6 @NonNull is meaningless on a parameter of an abstract method. diff --git a/test/transform/resource/messages-ecj/EqualsAndHashCodeWithSomeExistingMethods.java.messages b/test/transform/resource/messages-ecj/EqualsAndHashCodeWithSomeExistingMethods.java.messages index f5dfd559..75ddfa54 100644 --- a/test/transform/resource/messages-ecj/EqualsAndHashCodeWithSomeExistingMethods.java.messages +++ b/test/transform/resource/messages-ecj/EqualsAndHashCodeWithSomeExistingMethods.java.messages @@ -1,2 +1,2 @@ -4 Not generating equals: One of equals, hashCode, and canEqual exists. You should either write all of these are none of these (in the latter case, lombok generates them). -15 Not generating equals and hashCode: One of equals, hashCode, and canEqual exists. You should either write all of these are none of these (in the latter case, lombok generates them). +4 Not generating equals: One of equals, hashCode, and canEqual exists. You should either write all of these or none of these (in the latter case, lombok generates them). +15 Not generating equals and hashCode: One of equals, hashCode, and canEqual exists. You should either write all of these or none of these (in the latter case, lombok generates them). diff --git a/test/transform/resource/messages-ecj/NonNullOnParameterAbstract.java.messages b/test/transform/resource/messages-ecj/NonNullOnParameterAbstract.java.messages index 48d1508e..8eb312ef 100644 --- a/test/transform/resource/messages-ecj/NonNullOnParameterAbstract.java.messages +++ b/test/transform/resource/messages-ecj/NonNullOnParameterAbstract.java.messages @@ -1 +1 @@ -6:154 @NonNull is meaningless on a parameter of an abstract method. \ No newline at end of file +6 @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 index 00547171..0d9fcfdc 100644 --- a/test/transform/resource/messages-idempotent/NonNullOnParameterAbstract.java.messages +++ b/test/transform/resource/messages-idempotent/NonNullOnParameterAbstract.java.messages @@ -1 +1 @@ -9:36 @NonNull is meaningless on a parameter of an abstract method. \ No newline at end of file +9 @NonNull is meaningless on a parameter of an abstract method. \ No newline at end of file -- cgit