Merge "Prevent ActivityTestCase from erasing constants." into honeycomb
diff --git a/test-runner/src/android/test/ActivityTestCase.java b/test-runner/src/android/test/ActivityTestCase.java
index 18bfccc..c7b1d70 100644
--- a/test-runner/src/android/test/ActivityTestCase.java
+++ b/test-runner/src/android/test/ActivityTestCase.java
@@ -19,10 +19,11 @@
 import android.app.Activity;
 
 import java.lang.reflect.Field;
+import java.lang.reflect.Modifier;
 
 /**
  * This is common code used to support Activity test cases.  For more useful classes, please see
- * {@link android.test.ActivityUnitTestCase} and 
+ * {@link android.test.ActivityUnitTestCase} and
  * {@link android.test.ActivityInstrumentationTestCase}.
  */
 public abstract class ActivityTestCase extends InstrumentationTestCase {
@@ -38,7 +39,7 @@
     protected Activity getActivity() {
         return mActivity;
     }
-    
+
     /**
      * Set the activity under test.
      * @param testActivity The activity under test
@@ -46,15 +47,15 @@
     protected void setActivity(Activity testActivity) {
         mActivity = testActivity;
     }
-    
+
     /**
      * This function is called by various TestCase implementations, at tearDown() time, in order
      * to scrub out any class variables.  This protects against memory leaks in the case where a
      * test case creates a non-static inner class (thus referencing the test case) and gives it to
      * someone else to hold onto.
-     * 
+     *
      * @param testCaseClass The class of the derived TestCase implementation.
-     * 
+     *
      * @throws IllegalAccessException
      */
     protected void scrubClass(final Class<?> testCaseClass)
@@ -62,7 +63,8 @@
         final Field[] fields = getClass().getDeclaredFields();
         for (Field field : fields) {
             final Class<?> fieldClass = field.getDeclaringClass();
-            if (testCaseClass.isAssignableFrom(fieldClass) && !field.getType().isPrimitive()) {
+            if (testCaseClass.isAssignableFrom(fieldClass) && !field.getType().isPrimitive()
+                    && (field.getModifiers() & Modifier.FINAL) == 0) {
                 try {
                     field.setAccessible(true);
                     field.set(this, null);
@@ -77,6 +79,6 @@
         }
     }
 
-    
+
 
 }