Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit db4101c7 authored by Chet Haase's avatar Chet Haase
Browse files

Better error logs for faulty ObjectAnimators

Previously, if you set up an ObjectAnimator with the name of a property
which could not be resolved to an existing method (e.g., "foo" becomes "getFoo()"
or "setFoo()"), the errors in the log could be a bit obscure and the animation might
just crash sometime later with an unexplained NPE. This change provides a more
detailed log message detailing the actual method/class involved.

Issue #5990756 NullPointerException on no such property

Change-Id: Ic5bf7069c4879623e00ab8a794b799773cce487c
parent 5380cdc2
Loading
Loading
Loading
Loading
+22 −10
Original line number Diff line number Diff line
@@ -384,8 +384,7 @@ public class PropertyValuesHolder implements Cloneable {
            try {
                returnVal = targetClass.getMethod(methodName, args);
            } catch (NoSuchMethodException e) {
                Log.e("PropertyValuesHolder",
                        "Couldn't find no-arg method for property " + mPropertyName + ": " + e);
                // Swallow the error, log it later
            }
        } else {
            args = new Class[1];
@@ -412,9 +411,12 @@ public class PropertyValuesHolder implements Cloneable {
                }
            }
            // If we got here, then no appropriate function was found
            Log.e("PropertyValuesHolder",
                    "Couldn't find setter/getter for property " + mPropertyName +
                            " with value type "+ mValueType);
        }

        if (returnVal == null) {
            Log.w("PropertyValuesHolder", "Method " +
                    getMethodName(prefix, mPropertyName) + "() with type " + mValueType +
                    " not found on target class " + targetClass);
        }

        return returnVal;
@@ -495,7 +497,7 @@ public class PropertyValuesHolder implements Cloneable {
                }
                return;
            } catch (ClassCastException e) {
                Log.e("PropertyValuesHolder","No such property (" + mProperty.getName() +
                Log.w("PropertyValuesHolder","No such property (" + mProperty.getName() +
                        ") on target object " + target + ". Trying reflection instead");
                mProperty = null;
            }
@@ -508,6 +510,10 @@ public class PropertyValuesHolder implements Cloneable {
            if (!kf.hasValue()) {
                if (mGetter == null) {
                    setupGetter(targetClass);
                    if (mGetter == null) {
                        // Already logged the error - just return to avoid NPE
                        return;
                    }
                }
                try {
                    kf.setValue(mGetter.invoke(target));
@@ -535,6 +541,10 @@ public class PropertyValuesHolder implements Cloneable {
            if (mGetter == null) {
                Class targetClass = target.getClass();
                setupGetter(targetClass);
                if (mGetter == null) {
                    // Already logged the error - just return to avoid NPE
                    return;
                }
            }
            kf.setValue(mGetter.invoke(target));
        } catch (InvocationTargetException e) {
@@ -854,8 +864,9 @@ public class PropertyValuesHolder implements Cloneable {
                    }
                }
            } catch (NoSuchMethodError e) {
                Log.d("PropertyValuesHolder",
                        "Can't find native method using JNI, use reflection" + e);
                // Couldn't find it via JNI - try reflection next. Probably means the method
                // doesn't exist, or the type is wrong. An error will be logged later if
                // reflection fails as well.
            } finally {
                mPropertyMapLock.writeLock().unlock();
            }
@@ -990,8 +1001,9 @@ public class PropertyValuesHolder implements Cloneable {
                    }
                }
            } catch (NoSuchMethodError e) {
                Log.d("PropertyValuesHolder",
                        "Can't find native method using JNI, use reflection" + e);
                // Couldn't find it via JNI - try reflection next. Probably means the method
                // doesn't exist, or the type is wrong. An error will be logged later if
                // reflection fails as well.
            } finally {
                mPropertyMapLock.writeLock().unlock();
            }