Merge "Frameworks: Slightly refactor Parcel code"
This commit is contained in:
@@ -2797,14 +2797,19 @@ public final class Parcel {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
Parcelable.Creator<?> creator;
|
Parcelable.Creator<?> creator;
|
||||||
|
HashMap<String, Parcelable.Creator<?>> map;
|
||||||
synchronized (mCreators) {
|
synchronized (mCreators) {
|
||||||
HashMap<String,Parcelable.Creator<?>> map = mCreators.get(loader);
|
map = mCreators.get(loader);
|
||||||
if (map == null) {
|
if (map == null) {
|
||||||
map = new HashMap<>();
|
map = new HashMap<>();
|
||||||
mCreators.put(loader, map);
|
mCreators.put(loader, map);
|
||||||
}
|
}
|
||||||
creator = map.get(name);
|
creator = map.get(name);
|
||||||
if (creator == null) {
|
}
|
||||||
|
if (creator != null) {
|
||||||
|
return creator;
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// If loader == null, explicitly emulate Class.forName(String) "caller
|
// If loader == null, explicitly emulate Class.forName(String) "caller
|
||||||
// classloader" behavior.
|
// classloader" behavior.
|
||||||
@@ -2832,18 +2837,15 @@ public final class Parcel {
|
|||||||
+ "CREATOR on class " + name);
|
+ "CREATOR on class " + name);
|
||||||
}
|
}
|
||||||
creator = (Parcelable.Creator<?>) f.get(null);
|
creator = (Parcelable.Creator<?>) f.get(null);
|
||||||
}
|
} catch (IllegalAccessException e) {
|
||||||
catch (IllegalAccessException e) {
|
|
||||||
Log.e(TAG, "Illegal access when unmarshalling: " + name, e);
|
Log.e(TAG, "Illegal access when unmarshalling: " + name, e);
|
||||||
throw new BadParcelableException(
|
throw new BadParcelableException(
|
||||||
"IllegalAccessException when unmarshalling: " + name);
|
"IllegalAccessException when unmarshalling: " + name);
|
||||||
}
|
} catch (ClassNotFoundException e) {
|
||||||
catch (ClassNotFoundException e) {
|
|
||||||
Log.e(TAG, "Class not found when unmarshalling: " + name, e);
|
Log.e(TAG, "Class not found when unmarshalling: " + name, e);
|
||||||
throw new BadParcelableException(
|
throw new BadParcelableException(
|
||||||
"ClassNotFoundException when unmarshalling: " + name);
|
"ClassNotFoundException when unmarshalling: " + name);
|
||||||
}
|
} catch (NoSuchFieldException e) {
|
||||||
catch (NoSuchFieldException e) {
|
|
||||||
throw new BadParcelableException("Parcelable protocol requires a "
|
throw new BadParcelableException("Parcelable protocol requires a "
|
||||||
+ "Parcelable.Creator object called "
|
+ "Parcelable.Creator object called "
|
||||||
+ "CREATOR on class " + name);
|
+ "CREATOR on class " + name);
|
||||||
@@ -2854,9 +2856,9 @@ public final class Parcel {
|
|||||||
+ "CREATOR on class " + name);
|
+ "CREATOR on class " + name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
synchronized (mCreators) {
|
||||||
map.put(name, creator);
|
map.put(name, creator);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
return creator;
|
return creator;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user