OSDN Git Service

Don't double-set keyframe values when Property exists
authorChet Haase <chet@google.com>
Tue, 12 Jan 2016 00:27:20 +0000 (16:27 -0800)
committerChet Haase <chet@google.com>
Tue, 12 Jan 2016 00:27:20 +0000 (16:27 -0800)
There is logic in PVH.setupValue() that sets the value of
the appropriate keyframe from a Property, if that Property object
exists for the animator. But after that is done, it goes ahead and sets
the same keyframe value based on the getter for the target object.
This is not only redundant; it is wrong (in the odd situation in which
a getter would return something different than Property.get()).

The solution is to return early once we've set the value with the
Property object.

Issue #26471646  PropertyValuesHolder uses reflection in setupValue when a Property is being used

Change-Id: I12634a25661400f13f44872ba17625b32e93ca19

core/java/android/animation/PropertyValuesHolder.java

index 8928e99..e993cca 100644 (file)
@@ -861,22 +861,23 @@ public class PropertyValuesHolder implements Cloneable {
         if (mProperty != null) {
             Object value = convertBack(mProperty.get(target));
             kf.setValue(value);
-        }
-        try {
-            if (mGetter == null) {
-                Class targetClass = target.getClass();
-                setupGetter(targetClass);
+        } else {
+            try {
                 if (mGetter == null) {
-                    // Already logged the error - just return to avoid NPE
-                    return;
+                    Class targetClass = target.getClass();
+                    setupGetter(targetClass);
+                    if (mGetter == null) {
+                        // Already logged the error - just return to avoid NPE
+                        return;
+                    }
                 }
+                Object value = convertBack(mGetter.invoke(target));
+                kf.setValue(value);
+            } catch (InvocationTargetException e) {
+                Log.e("PropertyValuesHolder", e.toString());
+            } catch (IllegalAccessException e) {
+                Log.e("PropertyValuesHolder", e.toString());
             }
-            Object value = convertBack(mGetter.invoke(target));
-            kf.setValue(value);
-        } catch (InvocationTargetException e) {
-            Log.e("PropertyValuesHolder", e.toString());
-        } catch (IllegalAccessException e) {
-            Log.e("PropertyValuesHolder", e.toString());
         }
     }