summaryrefslogtreecommitdiffstats
path: root/core/java/android/view
diff options
context:
space:
mode:
authorGilles Debunne <debunne@google.com>2010-04-20 17:24:04 -0700
committerGilles Debunne <debunne@google.com>2010-04-27 15:05:16 -0700
commit9afed28629e9a35d341a39f8b4ee21b418079263 (patch)
treeb093c3bf64efa4204b31cbf07edfc0305be71f54 /core/java/android/view
parent6dee0a3fac648a82ae998348b6673cb7823bd15d (diff)
downloadframeworks_base-9afed28629e9a35d341a39f8b4ee21b418079263.zip
frameworks_base-9afed28629e9a35d341a39f8b4ee21b418079263.tar.gz
frameworks_base-9afed28629e9a35d341a39f8b4ee21b418079263.tar.bz2
Raw types warnings removed.
Raw types replaced. Added a asSubClass method in LayoutInflater which will (correctly) throw a ClassCastException when the inflated class is not a View subclass. Reduced the number of warnings in GenericInflater, but those remaining are valid. A lot of unsafe class casts happen between parent (P) and item (T) types that will generate runtime errors if the XML is not valid. Change-Id: I887fd67769a51ab54c6092e1270dbe3bfb6313ca
Diffstat (limited to 'core/java/android/view')
-rw-r--r--core/java/android/view/LayoutInflater.java31
1 files changed, 19 insertions, 12 deletions
diff --git a/core/java/android/view/LayoutInflater.java b/core/java/android/view/LayoutInflater.java
index e5985c1..428f308 100644
--- a/core/java/android/view/LayoutInflater.java
+++ b/core/java/android/view/LayoutInflater.java
@@ -16,15 +16,15 @@
package android.view;
+import org.xmlpull.v1.XmlPullParser;
+import org.xmlpull.v1.XmlPullParserException;
+
import android.content.Context;
import android.content.res.TypedArray;
import android.content.res.XmlResourceParser;
import android.util.AttributeSet;
import android.util.Xml;
-import org.xmlpull.v1.XmlPullParser;
-import org.xmlpull.v1.XmlPullParserException;
-
import java.io.IOException;
import java.lang.reflect.Constructor;
import java.util.HashMap;
@@ -71,11 +71,11 @@ public abstract class LayoutInflater {
private final Object[] mConstructorArgs = new Object[2];
- private static final Class[] mConstructorSignature = new Class[] {
+ private static final Class<?>[] mConstructorSignature = new Class[] {
Context.class, AttributeSet.class};
- private static final HashMap<String, Constructor> sConstructorMap =
- new HashMap<String, Constructor>();
+ private static final HashMap<String, Constructor<? extends View>> sConstructorMap =
+ new HashMap<String, Constructor<? extends View>>();
private HashMap<String, Boolean> mFilterMap;
@@ -453,18 +453,18 @@ public abstract class LayoutInflater {
* @param name The full name of the class to be instantiated.
* @param attrs The XML attributes supplied for this instance.
*
- * @return View The newly instantied view, or null.
+ * @return View The newly instantiated view, or null.
*/
public final View createView(String name, String prefix, AttributeSet attrs)
throws ClassNotFoundException, InflateException {
- Constructor constructor = sConstructorMap.get(name);
- Class clazz = null;
+ Constructor<? extends View> constructor = sConstructorMap.get(name);
+ Class<? extends View> clazz = null;
try {
if (constructor == null) {
// Class not found in the cache, see if it's real, and try to add it
clazz = mContext.getClassLoader().loadClass(
- prefix != null ? (prefix + name) : name);
+ prefix != null ? (prefix + name) : name).asSubclass(View.class);
if (mFilter != null && clazz != null) {
boolean allowed = mFilter.onLoadClass(clazz);
@@ -482,7 +482,7 @@ public abstract class LayoutInflater {
if (allowedState == null) {
// New class -- remember whether it is allowed
clazz = mContext.getClassLoader().loadClass(
- prefix != null ? (prefix + name) : name);
+ prefix != null ? (prefix + name) : name).asSubclass(View.class);
boolean allowed = clazz != null && mFilter.onLoadClass(clazz);
mFilterMap.put(name, allowed);
@@ -497,7 +497,7 @@ public abstract class LayoutInflater {
Object[] args = mConstructorArgs;
args[1] = attrs;
- return (View) constructor.newInstance(args);
+ return constructor.newInstance(args);
} catch (NoSuchMethodException e) {
InflateException ie = new InflateException(attrs.getPositionDescription()
@@ -506,6 +506,13 @@ public abstract class LayoutInflater {
ie.initCause(e);
throw ie;
+ } catch (ClassCastException e) {
+ // If loaded class is not a View subclass
+ InflateException ie = new InflateException(attrs.getPositionDescription()
+ + ": Class is not a View "
+ + (prefix != null ? (prefix + name) : name));
+ ie.initCause(e);
+ throw ie;
} catch (ClassNotFoundException e) {
// If loadClass fails, we should propagate the exception.
throw e;