Fix a cts crash around proxy class fields.
org.apache.harmony.tests.java.io.SerializationStressTest4#test_writeObject_Proxy
As the static fields of proxy classes share the dex file indices, they
shouldn't be resolved in the dex cache or else Field::GetArtField()
may return a wrong art field that belong to a different proxy class.
(cherry pick commit a56ce5e267c9744ed99e40ae5cd9b527971e1d63)
Bug: 20557050
Change-Id: If672c0e67bc49e672e34d75ffbe29c65f5a423b9
diff --git a/runtime/mirror/field.cc b/runtime/mirror/field.cc
index 70311bb..933784e 100644
--- a/runtime/mirror/field.cc
+++ b/runtime/mirror/field.cc
@@ -54,7 +54,19 @@
}
ArtField* Field::GetArtField() {
- mirror::DexCache* const dex_cache = GetDeclaringClass()->GetDexCache();
+ mirror::Class* declaring_class = GetDeclaringClass();
+ if (UNLIKELY(declaring_class->IsProxyClass())) {
+ DCHECK(IsStatic());
+ DCHECK_EQ(declaring_class->NumStaticFields(), 2U);
+ // 0 == Class[] interfaces; 1 == Class[][] throws;
+ if (GetDexFieldIndex() == 0) {
+ return &declaring_class->GetSFields()[0];
+ } else {
+ DCHECK_EQ(GetDexFieldIndex(), 1U);
+ return &declaring_class->GetSFields()[1];
+ }
+ }
+ mirror::DexCache* const dex_cache = declaring_class->GetDexCache();
ArtField* const art_field = dex_cache->GetResolvedField(GetDexFieldIndex(), sizeof(void*));
CHECK(art_field != nullptr);
return art_field;