Skip to content

Commit 5696715

Browse files
authored
Merge branch 'eclipse-jdt:master' into master
2 parents c4c76f2 + 59344e2 commit 5696715

20 files changed

Lines changed: 176 additions & 166 deletions

File tree

org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/ast/ForStatement.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,8 @@ public FlowInfo analyseCode(BlockScope currentScope, FlowContext flowContext, Fl
242242
}
243243
}
244244
this.mergedInitStateIndex = currentScope.methodScope().recordInitializationStates(mergedInfo);
245-
this.scope.checkUnclosedCloseables(mergedInfo, loopingContext, null, null);
245+
if ((this.bits & ASTNode.NeededScope) != 0)
246+
this.scope.checkUnclosedCloseables(mergedInfo, loopingContext, null, null);
246247
if (this.condition != null)
247248
this.condition.updateFlowOnBooleanResult(mergedInfo, false);
248249
return mergedInfo;

org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/lookup/CaptureBinding18.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public boolean setUpperBounds(TypeBinding[] upperBounds, ReferenceBinding javaLa
4444
if (upperBounds.length > 0)
4545
this.firstBound = upperBounds[0];
4646
int numReferenceInterfaces = 0;
47-
if (!isConsistentIntersection(upperBounds))
47+
if (!isConsistentIntersection(upperBounds, InferenceContext18.SIMULATE_BUG_JDK_8026527))
4848
return false;
4949
for (TypeBinding aBound : upperBounds) {
5050
if (aBound instanceof ReferenceBinding) {

org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/lookup/ExtendedTagBits.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,4 +39,6 @@ public interface ExtendedTagBits {
3939
static boolean areAllAnnotationsResolved(long extendedTagBits) {
4040
return (extendedTagBits & AllAnnotationsResolved) == AllAnnotationsResolved;
4141
}
42+
43+
int IsNullAnnotationPackage = ASTNode.Bit1; // package
4244
}

org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/lookup/InferenceContext18.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1307,7 +1307,7 @@ private TypeBinding intersectionFromGlb(TypeBinding[] glbs) {
13071307
}
13081308
}
13091309
IntersectionTypeBinding18 intersection = (IntersectionTypeBinding18) this.environment.createIntersectionType18(refGlbs);
1310-
if (ReferenceBinding.isConsistentIntersection(intersection.intersectingTypes))
1310+
if (ReferenceBinding.isConsistentIntersection(intersection.intersectingTypes, InferenceContext18.SIMULATE_BUG_JDK_8026527))
13111311
return intersection;
13121312
return null;
13131313
}

org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/lookup/LookupEnvironment.java

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -126,10 +126,6 @@ public class LookupEnvironment implements ProblemReasons, TypeConstants {
126126
public boolean isProcessingAnnotations = false; // ROOT_ONLY
127127
public boolean mayTolerateMissingType = false;
128128

129-
PackageBinding nullableAnnotationPackage; // the package supposed to contain the Nullable annotation type
130-
PackageBinding nonnullAnnotationPackage; // the package supposed to contain the NonNull annotation type
131-
PackageBinding nonnullByDefaultAnnotationPackage; // the package supposed to contain the NonNullByDefault annotation type
132-
133129
AnnotationBinding nonNullAnnotation;
134130
AnnotationBinding nullableAnnotation;
135131

@@ -1627,6 +1623,11 @@ public char[][] getNonNullByDefaultAnnotationName() {
16271623
return this.globalOptions.nonNullByDefaultAnnotationName;
16281624
}
16291625

1626+
public char[][][] allNullAnnotationNames() {
1627+
// should we include names of secondary annotations?
1628+
return new char[][][] { getNullableAnnotationName(), getNonNullAnnotationName(), getNonNullByDefaultAnnotationName() };
1629+
}
1630+
16301631
public char[][] getOwningAnnotationName() {
16311632
return this.globalOptions.owningAnnotationName;
16321633
}
@@ -1708,10 +1709,6 @@ private boolean matchesSimpleName(char[] simpleName, char[][] qualifiedName) {
17081709
return CharOperation.equals(simpleName, qualifiedName[qualifiedName.length-1]);
17091710
}
17101711

1711-
public boolean isNullnessAnnotationPackage(PackageBinding pkg) {
1712-
return this.nonnullAnnotationPackage == pkg || this.nullableAnnotationPackage == pkg || this.nonnullByDefaultAnnotationPackage == pkg;
1713-
}
1714-
17151712
public boolean usesNullTypeAnnotations() {
17161713
if (!this.globalOptions.isAnnotationBasedNullAnalysisEnabled)
17171714
return false;

org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/lookup/PackageBinding.java

Lines changed: 11 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,11 @@ void addType(ReferenceBinding element) {
102102
((UnresolvedReferenceBinding) priorType).setResolvedType(element, this.environment);
103103
}
104104
if (this.environment.globalOptions.isAnnotationBasedNullAnalysisEnabled || this.environment.globalOptions.isAnnotationBasedResourceAnalysisEnabled)
105-
if (element.isAnnotationType() || element instanceof UnresolvedReferenceBinding) // unresolved types don't yet have the modifiers set
106-
checkIfAnalysisAnnotationType(element);
105+
if (element.isAnnotationType() || element instanceof UnresolvedReferenceBinding) {
106+
// check if type is one of the configured null annotation types
107+
// if so mark as a well known type using the corresponding typeBit:
108+
element.typeBits |= this.environment.getAnalysisAnnotationBit(element.compoundName);
109+
}
107110

108111
if (!element.isUnresolvedType() && this.wrappingSplitPackageBindings != null) {
109112
for (SplitPackageBinding splitPackageBinding : this.wrappingSplitPackageBindings) {
@@ -374,12 +377,12 @@ public int problemId() {
374377
void checkIfNullAnnotationPackage() {
375378
LookupEnvironment env = this.environment;
376379
if (env.globalOptions.isAnnotationBasedNullAnalysisEnabled) {
377-
if (isPackageOfQualifiedTypeName(this.compoundName, env.getNullableAnnotationName()))
378-
env.nullableAnnotationPackage = this;
379-
if (isPackageOfQualifiedTypeName(this.compoundName, env.getNonNullAnnotationName()))
380-
env.nonnullAnnotationPackage = this;
381-
if (isPackageOfQualifiedTypeName(this.compoundName, env.getNonNullByDefaultAnnotationName()))
382-
env.nonnullByDefaultAnnotationPackage = this;
380+
for (char[][] typeName : env.allNullAnnotationNames()) {
381+
if (isPackageOfQualifiedTypeName(this.compoundName, typeName)) {
382+
this.extendedTagBits |= ExtendedTagBits.IsNullAnnotationPackage;
383+
break;
384+
}
385+
}
383386
}
384387
}
385388
private boolean isPackageOfQualifiedTypeName(char[][] packageName, char[][] typeName) {
@@ -392,29 +395,6 @@ private boolean isPackageOfQualifiedTypeName(char[][] packageName, char[][] type
392395
return true;
393396
}
394397

395-
void checkIfAnalysisAnnotationType(ReferenceBinding type) {
396-
// check if type is one of the configured null annotation types
397-
// if so mark as a well known type using the corresponding typeBit:
398-
if (this.environment.nullableAnnotationPackage == this
399-
&& CharOperation.equals(type.compoundName, this.environment.getNullableAnnotationName())) {
400-
type.typeBits |= TypeIds.BitNullableAnnotation;
401-
if (!(type instanceof UnresolvedReferenceBinding)) // unresolved will need to check back for the resolved type
402-
this.environment.nullableAnnotationPackage = null; // don't check again
403-
} else if (this.environment.nonnullAnnotationPackage == this
404-
&& CharOperation.equals(type.compoundName, this.environment.getNonNullAnnotationName())) {
405-
type.typeBits |= TypeIds.BitNonNullAnnotation;
406-
if (!(type instanceof UnresolvedReferenceBinding)) // unresolved will need to check back for the resolved type
407-
this.environment.nonnullAnnotationPackage = null; // don't check again
408-
} else if (this.environment.nonnullByDefaultAnnotationPackage == this
409-
&& CharOperation.equals(type.compoundName, this.environment.getNonNullByDefaultAnnotationName())) {
410-
type.typeBits |= TypeIds.BitNonNullByDefaultAnnotation;
411-
if (!(type instanceof UnresolvedReferenceBinding)) // unresolved will need to check back for the resolved type
412-
this.environment.nonnullByDefaultAnnotationPackage = null; // don't check again
413-
} else {
414-
type.typeBits |= this.environment.getAnalysisAnnotationBit(type.compoundName);
415-
}
416-
}
417-
418398
@Override
419399
public char[] readableName() /*java.lang*/ {
420400
return CharOperation.concatWith(this.compoundName, '.');

org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/lookup/ReferenceBinding.java

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2227,14 +2227,16 @@ protected int applyCloseableClassWhitelists(CompilerOptions options) {
22272227
}
22282228
}
22292229
}
2230-
for (int i=0; i<3; i++) {
2231-
if (!CharOperation.equals(this.compoundName[i], TypeConstants.ONE_UTIL_STREAMEX[i])) {
2232-
return 0;
2230+
streamex: {
2231+
for (int i=0; i<3; i++) {
2232+
if (!CharOperation.equals(this.compoundName[i], TypeConstants.ONE_UTIL_STREAMEX[i])) {
2233+
break streamex;
2234+
}
22332235
}
2234-
}
2235-
for (char[] streamName : TypeConstants.RESOURCE_FREE_CLOSEABLE_STREAMEX) {
2236-
if (CharOperation.equals(this.compoundName[3], streamName)) {
2237-
return TypeIds.BitResourceFreeCloseable;
2236+
for (char[] streamName : TypeConstants.RESOURCE_FREE_CLOSEABLE_STREAMEX) {
2237+
if (CharOperation.equals(this.compoundName[3], streamName)) {
2238+
return TypeIds.BitResourceFreeCloseable;
2239+
}
22382240
}
22392241
}
22402242
break;
@@ -2529,7 +2531,7 @@ public MethodBinding getSingleAbstractMethod(Scope scope, boolean replaceWildcar
25292531
}
25302532

25312533
// See JLS 4.9 bullet 1
2532-
public static boolean isConsistentIntersection(TypeBinding[] intersectingTypes) {
2534+
public static boolean isConsistentIntersection(TypeBinding[] intersectingTypes, boolean simulatingBugJDK8026527) {
25332535
TypeBinding[] ci = new TypeBinding[intersectingTypes.length];
25342536
for (int i = 0; i < ci.length; i++) {
25352537
TypeBinding current = intersectingTypes[i];
@@ -2542,9 +2544,9 @@ public static boolean isConsistentIntersection(TypeBinding[] intersectingTypes)
25422544
// when invoked during type inference we only want to check inconsistency among real types:
25432545
if (current.isTypeVariable() || current.isWildcard() || !current.isProperType(true))
25442546
continue;
2545-
if (mostSpecific.isSubtypeOf(current, false))
2547+
if (mostSpecific.isSubtypeOf(current, simulatingBugJDK8026527))
25462548
continue;
2547-
else if (current.isSubtypeOf(mostSpecific, false))
2549+
else if (current.isSubtypeOf(mostSpecific, simulatingBugJDK8026527))
25482550
mostSpecific = current;
25492551
else
25502552
return false;

org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/lookup/SourceTypeBinding.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2317,7 +2317,7 @@ public void evaluateNullAnnotations() {
23172317
PackageBinding pkg = getPackage();
23182318
boolean isInDefaultPkg = (pkg.compoundName == CharOperation.NO_CHAR_CHAR);
23192319
if (!isPackageInfo) {
2320-
boolean isInNullnessAnnotationPackage = this.scope.environment().isNullnessAnnotationPackage(pkg);
2320+
boolean isInNullnessAnnotationPackage = (pkg.extendedTagBits & ExtendedTagBits.IsNullAnnotationPackage) != 0;
23212321
if (pkg.getDefaultNullness() == NO_NULL_DEFAULT && !isInDefaultPkg && !isInNullnessAnnotationPackage && !(this instanceof NestedTypeBinding)) {
23222322
ReferenceBinding packageInfo = pkg.getType(TypeConstants.PACKAGE_INFO_NAME, this.module);
23232323
if (packageInfo == null) {

org.eclipse.jdt.core.tests.builder/src/org/eclipse/jdt/core/tests/builder/MultiProjectTests.java

Lines changed: 0 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -2146,84 +2146,6 @@ public void test461074() throws JavaModelException {
21462146
env.removeProject(p2);
21472147
env.removeProject(p3);
21482148
}
2149-
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=461074, "indirectly referenced from required .class files" error for unreachable reference of type in overriding method declaration in a library on classpath
2150-
public void _2551_test461074_error() throws JavaModelException {
2151-
//----------------------------
2152-
// Project1
2153-
//----------------------------
2154-
IPath p1 = env.addProject("SampleMissing"); //$NON-NLS-1$
2155-
env.addExternalJars(p1, Util.getJavaClassLibs());
2156-
// remove old package fragment root so that names don't collide
2157-
env.removePackageFragmentRoot(p1, ""); //$NON-NLS-1$
2158-
IPath root1 = env.addPackageFragmentRoot(p1, "src"); //$NON-NLS-1$
2159-
env.setOutputFolder(p1, "bin"); //$NON-NLS-1$
2160-
2161-
env.addClass(root1, "pack.missing", "MissingType", //$NON-NLS-1$ //$NON-NLS-2$
2162-
"package pack.missing;\n" +
2163-
"public class MissingType {\n" +
2164-
"}\n"
2165-
);
2166-
2167-
//----------------------------
2168-
// Project2
2169-
//----------------------------
2170-
IPath p2 = env.addProject("SampleLib", CompilerOptions.getFirstSupportedJavaVersion()); //$NON-NLS-1$
2171-
env.addExternalJars(p2, Util.getJavaClassLibs());
2172-
// remove old package fragment root so that names don't collide
2173-
env.removePackageFragmentRoot(p2, ""); //$NON-NLS-1$
2174-
IPath root2 = env.addPackageFragmentRoot(p2, "src"); //$NON-NLS-1$
2175-
env.setOutputFolder(p2, "bin"); //$NON-NLS-1$
2176-
2177-
env.addClass(root2, "pack.lib", "TopClass", //$NON-NLS-1$ //$NON-NLS-2$
2178-
"package pack.lib;\n" +
2179-
"public abstract class TopClass {\n" +
2180-
" abstract Object get();\n" +
2181-
"}\n"
2182-
);
2183-
env.addClass(root2, "pack.lib", "SuperClass", //$NON-NLS-1$ //$NON-NLS-2$
2184-
"package pack.lib;\n" +
2185-
"import pack.missing.MissingType;\n" +
2186-
"public class SuperClass extends TopClass {\n" +
2187-
" @Override\n" +
2188-
" MissingType get() { return null; }\n" +
2189-
"}\n"
2190-
);
2191-
2192-
//----------------------------
2193-
// Project3
2194-
//----------------------------
2195-
IPath p3 = env.addProject("SampleTest", CompilerOptions.getFirstSupportedJavaVersion()); //$NON-NLS-1$
2196-
env.addExternalJars(p3, Util.getJavaClassLibs());
2197-
// remove old package fragment root so that names don't collide
2198-
env.removePackageFragmentRoot(p3, ""); //$NON-NLS-1$
2199-
IPath root3 = env.addPackageFragmentRoot(p3, "src"); //$NON-NLS-1$
2200-
env.setOutputFolder(p3, "bin"); //$NON-NLS-1$
2201-
2202-
IPath test = env.addClass(root3, "pack.test", "Test", //$NON-NLS-1$ //$NON-NLS-2$
2203-
"package pack.test;\n" +
2204-
"import pack.lib.SuperClass;\n" +
2205-
"public class Test extends SuperClass {/*empty*/}\n"
2206-
);
2207-
2208-
// for Project1
2209-
env.addRequiredProject(p2, p1);
2210-
env.addRequiredProject(p3, p2);
2211-
env.waitForManualRefresh();
2212-
fullBuild();
2213-
env.waitForAutoBuild();
2214-
expectingOnlySpecificProblemsFor(p3, new Problem[]{
2215-
new Problem("p3",
2216-
"The project was not built since its build path is incomplete. Cannot find the class file for pack.missing.MissingType. Fix the build path then try building this project",
2217-
p3, -1, -1, CategorizedProblem.CAT_BUILDPATH, IMarker.SEVERITY_ERROR),
2218-
new Problem("p3",
2219-
"The type pack.missing.MissingType cannot be resolved. It is indirectly referenced from required type pack.lib.SuperClass",
2220-
test, 0, 1, CategorizedProblem.CAT_BUILDPATH, IMarker.SEVERITY_ERROR),
2221-
});
2222-
env.setBuildOrder(null);
2223-
env.removeProject(p1);
2224-
env.removeProject(p2);
2225-
env.removeProject(p3);
2226-
}
22272149
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=461074, "indirectly referenced from required .class files" error for unreachable reference of type in overriding method declaration in a library on classpath
22282150
public void test461074_error_1_8() throws JavaModelException {
22292151
// as of https://github.com/eclipse-jdt/eclipse.jdt.core/pull/2543 and at 1.8+ we tolerate the missing type

org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/GenericsRegressionTest_9.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1583,6 +1583,21 @@ private record W2<T>(W1<T> t) {}
15831583
"""
15841584
});
15851585
}
1586+
public void testGH4498() {
1587+
runConformTest(new String[] {
1588+
"AFactory.java",
1589+
"""
1590+
public abstract class AFactory<T> {
1591+
1592+
public <U extends AFactory> U getProcess(Object object) {
1593+
return getProcess(object.getClass()); // Type mismatch: cannot convert from AFactory<capture#2-of ?> to U
1594+
}
1595+
1596+
public abstract <U extends AFactory<?>> U getProcess(Class<?> classeObject);
1597+
1598+
}
1599+
"""});
1600+
}
15861601
public static Class<GenericsRegressionTest_9> testClass() {
15871602
return GenericsRegressionTest_9.class;
15881603
}

0 commit comments

Comments
 (0)