- remove copying of inherited null annotations
+ add new warning for missing redeclaration of inherited annotation.
diff --git a/contrib/org.eclipse.objectteams.jdt.nullity/src/org/eclipse/objectteams/internal/jdt/nullity/CompilerAdaptation.java b/contrib/org.eclipse.objectteams.jdt.nullity/src/org/eclipse/objectteams/internal/jdt/nullity/CompilerAdaptation.java
index 841cead..174fd3b 100644
--- a/contrib/org.eclipse.objectteams.jdt.nullity/src/org/eclipse/objectteams/internal/jdt/nullity/CompilerAdaptation.java
+++ b/contrib/org.eclipse.objectteams.jdt.nullity/src/org/eclipse/objectteams/internal/jdt/nullity/CompilerAdaptation.java
@@ -482,46 +482,43 @@
// return type:
if ((inheritedBits & TagBits.AnnotationNonNull) != 0) {
- if ((currentBits & TagBits.AnnotationNullable) != 0) {
+ long currentNullBits = currentBits & (TagBits.AnnotationNonNull|TagBits.AnnotationNullable);
+ if (currentNullBits != TagBits.AnnotationNonNull) {
AbstractMethodDeclaration methodDecl = currentMethod.sourceMethod();
- getType().problemReporter().illegalReturnRedefinition(methodDecl, inheritedMethod,
- environment.getNonNullAnnotationName());
+ getType().problemReporter().illegalReturnRedefinition(methodDecl, inheritedMethod,
+ environment.getNonNullAnnotationName());
}
}
- if ((currentBits & (TagBits.AnnotationNonNull|TagBits.AnnotationNullable)) == 0)
- currentMethod.addTagBit(inheritedBits & (TagBits.AnnotationNonNull|TagBits.AnnotationNullable));
// parameters:
Argument[] currentArguments = currentMethod.sourceMethod().getArguments();
if (inheritedMethod.parameterNonNullness != null) {
- // inherited method has null-annotations, check and possibly transfer:
-
- // prepare for transferring (contract inheritance):
- if (currentMethod.parameterNonNullness == null)
- currentMethod.parameterNonNullness = new Boolean[currentMethod.getParameters().length];
-
+ // inherited method has null-annotations, check compatibility:
+
for (int i = 0; i < inheritedMethod.parameterNonNullness.length; i++) {
Boolean inheritedNonNullNess = inheritedMethod.parameterNonNullness[i];
- if (inheritedNonNullNess != Boolean.TRUE) { // super parameter is not restricted to @NonNull
- if (currentMethod.parameterNonNullness[i] == Boolean.TRUE) { // current parameter is restricted to @NonNull
+ Boolean currentNonNullNess = (currentMethod.parameterNonNullness == null)
+ ? null : currentMethod.parameterNonNullness[i];
+ if (inheritedNonNullNess != null) { // super has a null annotation
+ if (currentNonNullNess == null) { // current parameter lacks null annotation
+ getType().problemReporter().parameterLackingNonNullAnnotation(
+ currentArguments[i],
+ inheritedMethod.getDeclaringClass(),
+ environment.getNullableAnnotationName());
+ continue;
+ }
+ }
+ if (inheritedNonNullNess != Boolean.TRUE) { // super parameter is not restricted to @NonNull
+ if (currentNonNullNess == Boolean.TRUE) { // current parameter is restricted to @NonNull
getType().problemReporter().illegalRedefinitionToNonNullParameter(
currentArguments[i],
inheritedMethod.getDeclaringClass(),
inheritedNonNullNess == null
? null
: environment.getNullableAnnotationName());
- continue;
}
}
-
- if (currentMethod.parameterNonNullness[i] == null && inheritedNonNullNess != null) {
- // inherit this annotation as the current method has no annotation:
- currentMethod.parameterNonNullness[i] = inheritedNonNullNess;
- VariableBinding argumentBinding = currentArguments[i].binding;
- argumentBinding.tagBits |= inheritedNonNullNess.booleanValue()
- ? TagBits.AnnotationNonNull : TagBits.AnnotationNullable;
- }
}
} else if (currentMethod.parameterNonNullness != null) {
// super method has no annotations but current has
@@ -1023,6 +1020,14 @@
argument.type.sourceEnd);
}
}
+ public void parameterLackingNonNullAnnotation(Argument argument, ReferenceBinding declaringClass, char[][] inheritedAnnotationName) {
+ this.handle(
+ IProblem.ParameterLackingNonNullAnnotation,
+ new String[] { new String(argument.name), new String(declaringClass.readableName()), CharOperation.toString(inheritedAnnotationName)},
+ new String[] { new String(argument.name), new String(declaringClass.shortReadableName()), new String(inheritedAnnotationName[inheritedAnnotationName.length-1])},
+ argument.type.sourceStart,
+ argument.type.sourceEnd);
+ }
public void illegalReturnRedefinition(org.eclipse.jdt.internal.compiler.ast.AbstractMethodDeclaration abstractMethodDecl,
MethodBinding inheritedMethod, char[][] nonNullAnnotationName)
{
diff --git a/contrib/org.eclipse.objectteams.jdt.nullity/src/org/eclipse/objectteams/internal/jdt/nullity/Constants.java b/contrib/org.eclipse.objectteams.jdt.nullity/src/org/eclipse/objectteams/internal/jdt/nullity/Constants.java
index 4ebdbf2..7b2b2ea 100644
--- a/contrib/org.eclipse.objectteams.jdt.nullity/src/org/eclipse/objectteams/internal/jdt/nullity/Constants.java
+++ b/contrib/org.eclipse.objectteams.jdt.nullity/src/org/eclipse/objectteams/internal/jdt/nullity/Constants.java
@@ -67,9 +67,11 @@
/** @since 3.7 */
int IllegalDefinitionToNonNullParameter = MethodRelated + 892;
/** @since 3.7 */
- int PotentialNullMessageSendReference = Internal + 893;
+ int ParameterLackingNonNullAnnotation = 893;
/** @since 3.7 */
- int RedundantNullCheckOnNonNullMessageSend = 894;
+ int PotentialNullMessageSendReference = Internal + 894;
+ /** @since 3.7 */
+ int RedundantNullCheckOnNonNullMessageSend = 895;
}
/** Translate from a nullness annotation to the corresponding tag bit or 0L. */
diff --git a/contrib/org.eclipse.objectteams.jdt.nullity/src/org/eclipse/objectteams/internal/jdt/nullity/problem_messages.properties b/contrib/org.eclipse.objectteams.jdt.nullity/src/org/eclipse/objectteams/internal/jdt/nullity/problem_messages.properties
index 63c2d1e..b58a9dc 100644
--- a/contrib/org.eclipse.objectteams.jdt.nullity/src/org/eclipse/objectteams/internal/jdt/nullity/problem_messages.properties
+++ b/contrib/org.eclipse.objectteams.jdt.nullity/src/org/eclipse/objectteams/internal/jdt/nullity/problem_messages.properties
@@ -24,5 +24,6 @@
890 = The return type is incompatible with the @{1} return from {0}
891 = Illegal redefinition of parameter {0}, inherited method from {1} declares this parameter as @{2}
892 = Illegal redefinition of parameter {0}, inherited method from {1} does not constrain this parameter
-893 = Potential null pointer access: The method {0} may return null
-894 = Redundant null check: The method {0} cannot return null
+893 = Missing null annotation: inherited method from {1} declares this parameter as @{2}
+894 = Potential null pointer access: The method {0} may return null
+895 = Redundant null check: The method {0} cannot return null