Skip to content

Commit

Permalink
Fix regression from eclipse-jdt#683
Browse files Browse the repository at this point in the history
  • Loading branch information
stephan-herrmann authored and iloveeclipse committed Feb 7, 2023
1 parent 21ff5dd commit 005b7ab
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1322,6 +1322,7 @@ private static TypeBinding mergeAnnotationsIntoType(BlockScope scope, Annotation
oldLeafType = oldLeafType.withoutToplevelNullAnnotation();
} else if (se8nullBits == TagBits.AnnotationNonNull
&& location != Binding.DefaultLocationReturnType // normal return type cases are handled in MethodBinding.fillInDefaultNonNullness18()
&& location != Binding.DefaultLocationField // normal field type cases are handled in FieldBinding.fillInDefaultNonNullness()
&& scope.hasDefaultNullnessForType(typeRef.resolvedType, location, typeRef.sourceStart)) {
scope.problemReporter().nullAnnotationIsRedundant(typeRef, new Annotation[] { se8NullAnnotation });
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18726,4 +18726,26 @@ public void testBug499596() throws Exception {
runner.classLibraries = this.LIBS;
runner.runWarningTest();
}
public void testRedundantNonNull_field() {
Runner runner = new Runner();
runner.testFiles =
new String[] {
"test1/Foo.java",
"package test1;\n" +
"import org.eclipse.jdt.annotation.*;\n" +
"@NonNullByDefault\n" +
"public class Foo {\n" +
" @NonNull Object f=new Object();\n" +
"}\n"
};
runner.expectedCompilerLog =
"----------\n" +
"1. WARNING in test1\\Foo.java (at line 5)\n" +
" @NonNull Object f=new Object();\n" +
" ^^^^^^^^^^^^^^^\n" +
"The nullness annotation is redundant with a default that applies to this location\n" +
"----------\n";
runner.classLibraries = this.LIBS;
runner.runWarningTest();
}
}

0 comments on commit 005b7ab

Please sign in to comment.