Skip to content

Commit

Permalink
@NonNullByDefault does not work for type arguments of a local type
Browse files Browse the repository at this point in the history
  • Loading branch information
stephan-herrmann committed Dec 5, 2023
1 parent dc8021b commit 27730ac
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
package org.eclipse.jdt.internal.compiler.lookup;

import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedHashSet;
Expand Down Expand Up @@ -373,6 +374,7 @@ void buildLocalTypeBinding(SourceTypeBinding enclosingType) {
checkParameterizedTypeBounds();
checkParameterizedSuperTypeCollisions();
}
this.referenceContext.updateSupertypesWithAnnotations(Collections.emptyMap());
buildFieldsAndMethods();
localType.faultInTypesForFieldsAndMethods();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19132,4 +19132,78 @@ void foo(String... strings) {
runner.classLibraries = this.LIBS;
runner.runConformTest();
}
public void testGH1693_a() {
Runner runner = new Runner();
runner.testFiles = new String[] {
"X.java",
"""
import java.util.Iterator;
import org.eclipse.jdt.annotation.NonNullByDefault;

@NonNullByDefault
public class X {
Iterator<String> getProcessIterator() {
abstract class StringIterator implements Iterator<String> { }
return new StringIterator() {
@Override
public boolean hasNext() {
return false;
}
@Override
public String next() {
return null;
}
};
}
}
"""
};
runner.customOptions = getCompilerOptions();
runner.classLibraries = this.LIBS;
runner.expectedCompilerLog =
"----------\n" +
"1. ERROR in X.java (at line 15)\n" +
" return null;\n" +
" ^^^^\n" +
"Null type mismatch: required \'@NonNull String\' but the provided value is null\n" +
"----------\n";
runner.runNegativeTest();
}
public void testGH1693_b() {
Runner runner = new Runner();
runner.testFiles = new String[] {
"X.java",
"""
import java.util.Iterator;
import org.eclipse.jdt.annotation.NonNullByDefault;

@NonNullByDefault
public class X {
Iterator<String> getProcessIterator() {
class StringIterator implements Iterator<String> {
@Override
public boolean hasNext() {
return false;
}
@Override
public String next() {
return null;
}
}
return new StringIterator();
}
}
"""
};
runner.customOptions = getCompilerOptions();
runner.classLibraries = this.LIBS;
runner.expectedCompilerLog =
"----------\n" +
"1. ERROR in X.java (at line 14)\n" +
" return null;\n" +
" ^^^^\n" +
"Null type mismatch: required \'@NonNull String\' but the provided value is null\n" +
"----------\n";
runner.runNegativeTest();
}
}

0 comments on commit 27730ac

Please sign in to comment.