Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #8554: silently ignore missing annotations like javac #9096

Merged
merged 1 commit into from
Jun 1, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -534,6 +534,15 @@ class ClassfileParser(
*/
def parseAnnotation(attrNameIndex: Char, skip: Boolean = false)(implicit ctx: Context): Option[Annotation] = try {
val attrType = pool.getType(attrNameIndex)
attrType match
case tp: TypeRef =>
// Silently ignore missing annotation classes like javac
if tp.denot.infoOrCompleter.isInstanceOf[StubInfo] then
if ctx.debug then
ctx.warning(i"Error while parsing annotations in ${in.file}: annotation class $tp not present on classpath")
return None
case _ =>

val nargs = in.nextChar
val argbuf = new ListBuffer[untpd.Tree]
var hasError = false
Expand Down
17 changes: 17 additions & 0 deletions compiler/test/dotty/tools/AnnotationsTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,20 @@ class AnnotationsTest:
}
}
}

@Test def surviveMissingAnnot: Unit =
withJavaCompiled(
VirtualJavaSource("Annot.java",
"public @interface Annot {}"),
VirtualJavaSource("A.java",
"@Annot() public class A {}")) { javaOutputDir =>
Files.delete(javaOutputDir.resolve("Annot.class"))
inCompilerContext(javaOutputDir.toString + File.pathSeparator + TestConfiguration.basicClasspath) {
val cls = ctx.requiredClass("A")
val annots = cls.annotations.map(_.tree)
assert(annots == Nil,
s"class A should have no visible annotations since Annot is not on the classpath, but found: $annots")
assert(!ctx.reporter.hasErrors && !ctx.reporter.hasWarnings,
s"A missing annotation while parsing a Java class should be silently ignored but: ${ctx.reporter.summary}")
}
}