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 025c21c..53d8a6f 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 @@ -2474,6 +2474,91 @@ "Type mismatch: required \'@NonNull String\' but the provided value can be null\n" + "----------\n"); } +// witness for an AIOOBE in FlowContext.recordExpectedType() +public void test_message_send_in_control_structure_01() { + Map customOptions = getCompilerOptions(); + customOptions.put(JavaCore.COMPILER_PB_NULL_SPECIFICATION_INSUFFICIENT_INFO, JavaCore.IGNORE); + customOptions.put(JavaCore.COMPILER_PB_POTENTIAL_NULL_REFERENCE, JavaCore.WARNING); + runNegativeTestWithLibs( + new String[] { + "p/Scope.java", + "package p;\n" + + "@org.eclipse.jdt.annotation.NonNullByDefault\n" + + "public abstract class Scope {\n" + + " public ReferenceBinding findMemberType(char[] typeName, ReferenceBinding enclosingType) {\n" + + " ReferenceBinding enclosingSourceType = enclosingSourceType();\n" + + " PackageBinding currentPackage = getCurrentPackage();\n" + + " CompilationUnitScope unitScope = compilationUnitScope();\n" + + " ReferenceBinding memberType = enclosingType.getMemberType(typeName);\n" + + " ReferenceBinding currentType = enclosingType;\n" + + " ReferenceBinding[] interfacesToVisit = null;\n" + + " while (true) {\n" + + " ReferenceBinding[] itsInterfaces = currentType.superInterfaces();\n" + + " if (itsInterfaces != null) {\n" + + " if (interfacesToVisit == null) {\n" + + " interfacesToVisit = itsInterfaces;\n" + + " }\n" + + " }\n" + + " unitScope.recordReference(currentType, typeName);\n" + + " \n" + + " if ((memberType = currentType.getMemberType(typeName)) != null) {\n" + + " if (enclosingSourceType == null\n" + + " ? memberType.canBeSeenBy(currentPackage)\n" + + " : memberType.canBeSeenBy(enclosingType, enclosingSourceType)) {\n" + + " return memberType;\n" + + " }\n" + + " }\n" + + " }\n" + + " }\n" + + " private CompilationUnitScope compilationUnitScope() {\n" + + " return compilationUnitScope();\n" + + " }\n" + + " private PackageBinding getCurrentPackage() {\n" + + " return getCurrentPackage();\n" + + " }\n" + + " private ReferenceBinding enclosingSourceType() {\n" + + " return enclosingSourceType();\n" + + " }\n" + + "}\n", + "p/CompilationUnitScope.java", + "package p;\n" + + "@org.eclipse.jdt.annotation.NonNullByDefault\n" + + "public class CompilationUnitScope {\n" + + " void recordReference(ReferenceBinding rb, char[] name) {}\n" + + "}\n", + "p/PackageBinding.java", + "package p;\n" + + "@org.eclipse.jdt.annotation.NonNullByDefault\n" + + "public class PackageBinding {\n" + + "}\n", + "p/ReferenceBinding.java", + "package p;\n" + + "@org.eclipse.jdt.annotation.NonNullByDefault\n" + + "public class ReferenceBinding {\n" + + " ReferenceBinding getMemberType(char[] name) { return this; }\n" + + " ReferenceBinding[] superInterfaces() { return new ReferenceBinding[0]; }\n" + + " boolean canBeSeenBy(PackageBinding ob) { return true; }\n" + + " boolean canBeSeenBy(ReferenceBinding rb, ReferenceBinding rb2) { return true; }\n" + + "}\n" + }, + customOptions, + "----------\n" + + "1. ERROR in p\\Scope.java (at line 13)\n" + + " if (itsInterfaces != null) {\n" + + " ^^^^^^^^^^^^^\n" + + "Redundant null check: The variable itsInterfaces cannot be null at this location\n" + + "----------\n" + + "2. ERROR in p\\Scope.java (at line 20)\n" + + " if ((memberType = currentType.getMemberType(typeName)) != null) {\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Redundant null check: The variable memberType cannot be null at this location\n" + + "----------\n" + + "3. ERROR in p\\Scope.java (at line 21)\n" + + " if (enclosingSourceType == null\n" + + " ^^^^^^^^^^^^^^^^^^^\n" + + "Null comparison always yields false: The variable enclosingSourceType cannot be null at this location\n" + + "----------\n"); +} public void test_assignment_expression_1() { Map customOptions = getCompilerOptions(); // customOptions.put(CompilerOptions.OPTION_ReportPotentialNullSpecViolation, JavaCore.ERROR);