File tree Expand file tree Collapse file tree 2 files changed +26
-0
lines changed
src/dotty/tools/dotc/core/classfile Expand file tree Collapse file tree 2 files changed +26
-0
lines changed Original file line number Diff line number Diff line change @@ -534,6 +534,15 @@ class ClassfileParser(
534534 */
535535 def parseAnnotation (attrNameIndex : Char , skip : Boolean = false )(implicit ctx : Context ): Option [Annotation ] = try {
536536 val attrType = pool.getType(attrNameIndex)
537+ attrType match
538+ case tp : TypeRef =>
539+ // Silently ignore missing annotation classes like javac
540+ if tp.denot.infoOrCompleter.isInstanceOf [StubInfo ] then
541+ if ctx.debug then
542+ ctx.warning(i " Error while parsing annotations in ${in.file}: annotation class $tp not present on classpath " )
543+ return None
544+ case _ =>
545+
537546 val nargs = in.nextChar
538547 val argbuf = new ListBuffer [untpd.Tree ]
539548 var hasError = false
Original file line number Diff line number Diff line change @@ -37,3 +37,20 @@ class AnnotationsTest:
3737 }
3838 }
3939 }
40+
41+ @ Test def surviveMissingAnnot : Unit =
42+ withJavaCompiled(
43+ VirtualJavaSource (" Annot.java" ,
44+ " public @interface Annot {}" ),
45+ VirtualJavaSource (" A.java" ,
46+ " @Annot() public class A {}" )) { javaOutputDir =>
47+ Files .delete(javaOutputDir.resolve(" Annot.class" ))
48+ inCompilerContext(javaOutputDir.toString + File .pathSeparator + TestConfiguration .basicClasspath) {
49+ val cls = ctx.requiredClass(" A" )
50+ val annots = cls.annotations.map(_.tree)
51+ assert(annots == Nil ,
52+ s " class A should have no visible annotations since Annot is not on the classpath, but found: $annots" )
53+ assert(! ctx.reporter.hasErrors && ! ctx.reporter.hasWarnings,
54+ s " A missing annotation while parsing a Java class should be silently ignored but: ${ctx.reporter.summary}" )
55+ }
56+ }
You can’t perform that action at this time.
0 commit comments