Do not fail when deserializing incompatible metadata

Catch all exceptions when deserializing metadata with an incompatible version
to prevent the compiler from failing on discovering incompatible classes on the
classpath. Note that this is not the perfect solution: any invariant may be
broken in the incompatible metadata and it may result in a later exception
This commit is contained in:
Alexander Udalov
2016-12-07 21:30:26 +03:00
parent 789483e1eb
commit 830d2f6603
9 changed files with 172 additions and 12 deletions
@@ -74,6 +74,28 @@ class WrongBytecodeVersionTest : KtUsefulTestCase() {
override fun visit(name: String, value: Any) {
super.visit(name, transform(name, value) ?: value)
}
override fun visitArray(name: String): AnnotationVisitor {
val entries = arrayListOf<String>()
val arrayVisitor = { super.visitArray(name) }
return object : AnnotationVisitor(Opcodes.ASM5) {
override fun visit(name: String?, value: Any) {
entries.add(value as String)
}
override fun visitEnd() {
@Suppress("UNCHECKED_CAST")
val result = transform(name, entries.toTypedArray()) as Array<String>? ?: entries.toTypedArray()
if (result.isEmpty()) return
with(arrayVisitor()) {
for (value in result) {
visit(null, value)
}
visitEnd()
}
}
}
}
}
}
return superVisitor