Skip to content

Commit e46bffe

Browse files
Compilation error on full build but not on incremental build due to @deprecated (eclipse-jdt#4301)
+ when error reporting needs the since value, don't resolve all annots - this prevents that membervalue pairs of sibling annotations are prematurely type checked (before hierarchy is linked) + during initialization of deprecated annotation store it for later use eclipse-jdt#3907
1 parent 69070e0 commit e46bffe

6 files changed

Lines changed: 117 additions & 6 deletions

File tree

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1338,6 +1338,8 @@ public static void resolveDeprecatedAnnotations(BlockScope scope, Annotation[] a
13381338
break;
13391339
}
13401340
}
1341+
annotations[i].recipient = recipient;
1342+
annotations[i].resolveType(scope); // allow downstream access to since & forRemoval
13411343
}
13421344
recipient.tagBits |= deprecationTagBits;
13431345
}

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -708,6 +708,10 @@ public char[] genericTypeSignature() {
708708
public AnnotationBinding[] getAnnotations() {
709709
return this.type.getAnnotations();
710710
}
711+
@Override
712+
public AnnotationBinding[] getAnnotations(long requestedInitialization) {
713+
return this.type.getAnnotations(requestedInitialization);
714+
}
711715

712716
@Override
713717
public long getAnnotationTagBits() {

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

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1083,7 +1083,15 @@ public final int getAccessFlags() {
10831083
public AnnotationBinding[] getAnnotations() {
10841084
return retrieveAnnotations(prototype());
10851085
}
1086-
1086+
/**
1087+
* Get annotations, but request initialization only for specific ones
1088+
* @param requestedInitialization uses the bits from {@link ExtendedTagBits#DeprecatedAnnotationResolved}
1089+
* or {@link ExtendedTagBits#AllAnnotationsResolved} to request initialization of specific annotations
1090+
* (with option to select others in the future).
1091+
*/
1092+
public AnnotationBinding[] getAnnotations(long requestedInitialization) {
1093+
return getAnnotations();
1094+
}
10871095
/**
10881096
* @see org.eclipse.jdt.internal.compiler.lookup.Binding#getAnnotationTagBits()
10891097
*/

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

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2378,13 +2378,25 @@ protected boolean hasMethodWithNumArgs(char[] selector, int numArgs) {
23782378
}
23792379
return false;
23802380
}
2381+
@Override
2382+
public AnnotationBinding[] getAnnotations(long requestedInitialization) {
2383+
AnnotationHolder holder = retrieveAnnotationHolder(prototype(), requestedInitialization);
2384+
return holder == null ? Binding.NO_ANNOTATIONS : holder.getAnnotations();
2385+
}
23812386

23822387
@Override
23832388
public AnnotationHolder retrieveAnnotationHolder(Binding binding, boolean forceInitialization) {
2389+
return retrieveAnnotationHolder(binding, ExtendedTagBits.AllAnnotationsResolved);
2390+
}
2391+
private AnnotationHolder retrieveAnnotationHolder(Binding binding, long requestedInitialization) {
23842392
if (!isPrototype())
2385-
return this.prototype.retrieveAnnotationHolder(binding, forceInitialization);
2386-
if (forceInitialization)
2387-
binding.getAnnotationTagBits(); // ensure annotations are up to date
2393+
return this.prototype.retrieveAnnotationHolder(binding, requestedInitialization);
2394+
if (requestedInitialization == ExtendedTagBits.AllAnnotationsResolved) {
2395+
binding.getAnnotationTagBits(); // ensure all annotations are up to date
2396+
} else {
2397+
if ((requestedInitialization & ExtendedTagBits.DeprecatedAnnotationResolved) != 0)
2398+
binding.initializeDeprecatedAnnotationTagBits(); // selective initialization
2399+
}
23882400
return super.retrieveAnnotationHolder(binding, false);
23892401
}
23902402

org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/problem/ProblemReporter.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1916,7 +1916,7 @@ public void deprecatedType(TypeBinding type, ASTNode location) {
19161916
// a deprecated type in a qualified reference (see bug 292510)
19171917
public void deprecatedType(TypeBinding type, ASTNode location, int index) {
19181918
if (location == null) return; // 1G828DN - no type ref for synthetic arguments
1919-
final TypeBinding leafType = type.leafComponentType();
1919+
final ReferenceBinding leafType = (ReferenceBinding) type.leafComponentType();
19201920
if (!leafType.isReadyForAnnotations() && scheduleProblemForContext(() -> deprecatedType(type, location, index)))
19211921
return;
19221922
int sourceStart = -1;
@@ -1926,7 +1926,7 @@ public void deprecatedType(TypeBinding type, ASTNode location, int index) {
19261926
sourceStart = (int) (ref.sourcePositions[index] >> 32);
19271927
}
19281928
}
1929-
String sinceValue = deprecatedSinceValue(() -> leafType.getAnnotations());
1929+
String sinceValue = deprecatedSinceValue(() -> leafType.getAnnotations(ExtendedTagBits.DeprecatedAnnotationResolved));
19301930
if (sinceValue != null) {
19311931
this.handle(
19321932
((leafType.tagBits & TagBits.AnnotationTerminallyDeprecated) == 0) ? IProblem.UsingDeprecatedSinceVersionType : IProblem.UsingTerminallyDeprecatedSinceVersionType,

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

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1335,6 +1335,91 @@ public static void main(String[] args) {
13351335
});
13361336
}
13371337

1338+
// https://github.com/eclipse-jdt/eclipse.jdt.core/issues/3907
1339+
// Compilation error on full build but not on incremental build due to @deprecated
1340+
public void testIssue3907() {
1341+
runConformTest(new String[] {
1342+
"LoadExtension.java",
1343+
"""
1344+
public class LoadExtension extends AbstractLoad<Integer> {
1345+
}
1346+
""",
1347+
"TestIntegrationExtension.java",
1348+
"""
1349+
public final class TestIntegrationExtension implements Extension {
1350+
1351+
}
1352+
1353+
@ExtendWith(TestIntegrationExtension.class)
1354+
@interface TestIntegration {
1355+
}
1356+
1357+
@interface ExtendWith {
1358+
Class<? extends Extension>[] value();
1359+
}
1360+
1361+
interface Extension {
1362+
}
1363+
1364+
1365+
/**
1366+
* @deprecated
1367+
*/
1368+
@TestIntegration()
1369+
@Deprecated
1370+
abstract class AbstractLoad<T extends Number> {
1371+
1372+
}
1373+
"""
1374+
});
1375+
}
1376+
public void testIssue3907_since() {
1377+
Runner runner = new Runner();
1378+
runner.testFiles = new String[] {
1379+
"LoadExtension.java",
1380+
"""
1381+
public class LoadExtension extends AbstractLoad<Integer> {
1382+
}
1383+
""",
1384+
"TestIntegrationExtension.java",
1385+
"""
1386+
public final class TestIntegrationExtension implements Extension {
1387+
1388+
}
1389+
1390+
@ExtendWith(TestIntegrationExtension.class)
1391+
@interface TestIntegration {
1392+
}
1393+
1394+
@interface ExtendWith {
1395+
Class<? extends Extension>[] value();
1396+
}
1397+
1398+
interface Extension {
1399+
}
1400+
1401+
1402+
/**
1403+
* @deprecated
1404+
*/
1405+
@TestIntegration()
1406+
@Deprecated(since="13")
1407+
abstract class AbstractLoad<T extends Number> {
1408+
1409+
}
1410+
"""
1411+
};
1412+
runner.expectedCompilerLog =
1413+
"""
1414+
----------
1415+
1. WARNING in LoadExtension.java (at line 1)
1416+
public class LoadExtension extends AbstractLoad<Integer> {
1417+
^^^^^^^^^^^^
1418+
The type AbstractLoad<Integer> is deprecated since version 13
1419+
----------
1420+
""";
1421+
runner.runWarningTest();
1422+
}
13381423
public static Class<GenericsRegressionTest_9> testClass() {
13391424
return GenericsRegressionTest_9.class;
13401425
}

0 commit comments

Comments
 (0)