Throw VerifyError when trying to extend a final class.
Comply with JLS 13.4.2. Previously we were throwing ICCE.
Test: Added another test to 066-mismatched-super.
Test: testrunner.py --host
Bug: 63754965
Change-Id: I5ceb9c67df99c5135436f6facb387fdb8f252b81
diff --git a/runtime/class_linker.cc b/runtime/class_linker.cc
index 1c3375c..199fb46 100644
--- a/runtime/class_linker.cc
+++ b/runtime/class_linker.cc
@@ -5653,12 +5653,18 @@
return false;
}
// Verify
- if (super->IsFinal() || super->IsInterface()) {
+ if (super->IsFinal()) {
+ ThrowVerifyError(klass.Get(),
+ "Superclass %s of %s is declared final",
+ super->PrettyDescriptor().c_str(),
+ klass->PrettyDescriptor().c_str());
+ return false;
+ }
+ if (super->IsInterface()) {
ThrowIncompatibleClassChangeError(klass.Get(),
- "Superclass %s of %s is %s",
+ "Superclass %s of %s is an interface",
super->PrettyDescriptor().c_str(),
- klass->PrettyDescriptor().c_str(),
- super->IsFinal() ? "declared final" : "an interface");
+ klass->PrettyDescriptor().c_str());
return false;
}
if (!klass->CanAccess(super)) {