Bug 415269 - [compiler][null] NonNullByDefault is not always inherited
to nested classes
diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/SourceTypeBinding.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/SourceTypeBinding.java
index f486b0f..13f1227 100644
--- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/SourceTypeBinding.java
+++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/SourceTypeBinding.java
@@ -1120,7 +1120,7 @@
this.scope.buildMethods();
}
-private void initializeNullDefault() {
+private int getNullDefault() {
// ensure nullness defaults are initialized at all enclosing levels:
switch (this.nullnessDefaultInitialized) {
case 0:
@@ -1130,6 +1130,7 @@
getPackage().isViewedAsDeprecated(); // initialize annotations
this.nullnessDefaultInitialized = 2;
}
+ return this.defaultNullness;
}
/**
@@ -1470,7 +1471,6 @@
// enum constants neither have a type declaration nor can they be null
field.tagBits |= TagBits.AnnotationNonNull;
} else {
- initializeNullDefault();
if (hasNonNullDefault()) {
field.fillInDefaultNonNullness(fieldDecl, initializationScope);
}
@@ -1658,7 +1658,7 @@
return method;
}
private void createArgumentBindings(MethodBinding method, CompilerOptions compilerOptions) {
- initializeNullDefault();
+ getNullDefault(); // ensure initialized
AbstractMethodDeclaration methodDecl = method.sourceMethod();
if (methodDecl != null) {
// while creating argument bindings we also collect explicit null annotations:
@@ -1728,8 +1728,7 @@
// return: should caller continue searching?
protected boolean checkRedundantNullnessDefaultOne(ASTNode location, Annotation[] annotations, long annotationTagBits) {
- initializeNullDefault();
- int thisDefault = this.defaultNullness;
+ int thisDefault = getNullDefault();
if (thisDefault == NONNULL_BY_DEFAULT) {
if ((annotationTagBits & TagBits.AnnotationNonNullByDefault) != 0) {
this.scope.problemReporter().nullDefaultAnnotationIsRedundant(location, annotations, this);
@@ -1759,8 +1758,7 @@
case Scope.CLASS_SCOPE:
currentType = ((ClassScope)currentScope).referenceContext.binding;
if (currentType != null) {
- currentType.initializeNullDefault();
- int foundDefaultNullness = currentType.defaultNullness;
+ int foundDefaultNullness = currentType.getNullDefault();
if (foundDefaultNullness != NO_NULL_DEFAULT) {
return foundDefaultNullness == NONNULL_BY_DEFAULT;
}