File tree 2 files changed +33
-1
lines changed
src/dotty/tools/dotc/core/classfile
2 files changed +33
-1
lines changed Original file line number Diff line number Diff line change @@ -1127,7 +1127,16 @@ class ClassfileParser(
1127
1127
val outerName = entry.strippedOuter
1128
1128
val innerName = entry.originalName
1129
1129
val owner = classNameToSymbol(outerName)
1130
- val result = atPhase(typerPhase)(getMember(owner, innerName.toTypeName))
1130
+ val result = owner.denot.infoOrCompleter match
1131
+ case _ : StubInfo if hasAnnotation(entry.jflags) =>
1132
+ requiredClass(innerName.toTypeName)
1133
+ // It's okay for the classfiles of Java annotations to be missing
1134
+ // from the classpath. If an annotation is defined as an inner class
1135
+ // we need to avoid forcing the outer class symbol here, and instead
1136
+ // return a new stub symbol for the inner class. This is tested by
1137
+ // `surviveMissingInnerClassAnnot` in AnnotationsTests.scala
1138
+ case _ =>
1139
+ atPhase(typerPhase)(getMember(owner, innerName.toTypeName))
1131
1140
assert(result ne NoSymbol ,
1132
1141
i """ failure to resolve inner class:
1133
1142
|externalName = ${entry.externalName},
Original file line number Diff line number Diff line change @@ -66,3 +66,26 @@ class AnnotationsTest:
66
66
s " A missing annotation while parsing a Java class should be silently ignored but: ${ctx.reporter.summary}" )
67
67
}
68
68
}
69
+
70
+ @ Test def surviveMissingInnerClassAnnot : Unit =
71
+ withJavaCompiled(
72
+ VirtualJavaSource (" Outer.java" ,
73
+ """ |package a.b;
74
+ |public @interface Outer { public @interface Value { @interface Immutable {} } }
75
+ |""" .stripMargin),
76
+ VirtualJavaSource (" Baz.java" ,
77
+ """ |package a.b;
78
+ |@Outer.Value.Immutable abstract class Baz {}""" .stripMargin)
79
+ ) { javaOutputDir =>
80
+ Files .delete(javaOutputDir.resolve(" a/b/Outer.class" ))
81
+ Files .delete(javaOutputDir.resolve(" a/b/Outer$Value.class" ))
82
+ Files .delete(javaOutputDir.resolve(" a/b/Outer$Value$Immutable.class" ))
83
+ inCompilerContext(javaOutputDir.toString + File .pathSeparator + TestConfiguration .basicClasspath) {
84
+ val cls = requiredClass(" a.b.Baz" )
85
+ val annots = cls.annotations.map(_.tree)
86
+ assert(annots == Nil ,
87
+ s " class Baz should have no visible annotations since Outer.Value.Immutable is not on the classpath, but found: $annots" )
88
+ assert(! ctx.reporter.hasErrors && ! ctx.reporter.hasWarnings,
89
+ s " A missing annotation while parsing a Java class should be silently ignored but: ${ctx.reporter.summary}" )
90
+ }
91
+ }
You can’t perform that action at this time.
0 commit comments