diff options
author | Shankha Banerjee | 2014-03-11 13:43:44 +0000 |
---|---|---|
committer | Stephan Herrmann | 2014-03-11 16:17:38 +0000 |
commit | cd22e7cc518ff2d997c93cef84c2cb3849fd35bd (patch) | |
tree | 35e6c97634aa18d9dfbd70cbe2a0d9de0b0ea8ab | |
parent | 04462acb576297f6fd2704a63e0758e525633e09 (diff) | |
download | eclipse.jdt.core-cd22e7cc518ff2d997c93cef84c2cb3849fd35bd.tar.gz eclipse.jdt.core-cd22e7cc518ff2d997c93cef84c2cb3849fd35bd.tar.xz eclipse.jdt.core-cd22e7cc518ff2d997c93cef84c2cb3849fd35bd.zip |
Bug 430084 - [compiler][null] NPE: Method without return value
Signed-off-by: Shankha Banerjee <shankhba@in.ibm.com>
2 files changed, 23 insertions, 7 deletions
diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/NullAnnotationTest.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/NullAnnotationTest.java index 44f66afb74..03aca42976 100644 --- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/NullAnnotationTest.java +++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/NullAnnotationTest.java @@ -6989,4 +6989,21 @@ public void testBug424624b() { getCompilerOptions(), ""); } +public void testBug430084() { + runNegativeTestWithLibs( + new String[] { + "X.java", + "import org.eclipse.jdt.annotation.NonNullByDefault;\n" + + "@NonNullByDefault\n" + + "public class X {" + + " Y() {} " + + "}" + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " public class X { Y() {} }\n" + + " ^^^\n" + + "Return type for the method is missing\n" + + "----------\n"); +} } diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/MethodBinding.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/MethodBinding.java index 4c2d4d815c..d6b8712080 100644 --- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/MethodBinding.java +++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/MethodBinding.java @@ -531,13 +531,12 @@ protected void fillInDefaultNonNullness18(AbstractMethodDeclaration sourceMethod } if (added) this.tagBits |= TagBits.HasParameterAnnotations; - if ( this.returnType != null - && !this.returnType.isBaseType() - && (this.returnType.tagBits & TagBits.AnnotationNullMASK) == 0) - { - this.returnType = env.createAnnotatedType(this.returnType, new AnnotationBinding[]{env.getNonNullAnnotation()}); - } else if (sourceMethod != null && (this.returnType.tagBits & TagBits.AnnotationNonNull) != 0) { - sourceMethod.scope.problemReporter().nullAnnotationIsRedundant(sourceMethod, -1/*signifies method return*/); + if (this.returnType != null) { + if (!this.returnType.isBaseType() && (this.returnType.tagBits & TagBits.AnnotationNullMASK) == 0) { + this.returnType = env.createAnnotatedType(this.returnType, new AnnotationBinding[]{env.getNonNullAnnotation()}); + } else if (sourceMethod != null && (this.returnType.tagBits & TagBits.AnnotationNonNull) != 0) { + sourceMethod.scope.problemReporter().nullAnnotationIsRedundant(sourceMethod, -1/*signifies method return*/); + } } } |