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

Commit 3d612724 authored by Yigit Boyar's avatar Yigit Boyar
Browse files

Check for final observable fields

If a field is final, we know it cannot change thus cannot include it in dependency
logic. Unfortunately, observable final fields can invalidate themselves so
we should consider them dynamic.

Bug: 19299279
Change-Id: I643377f7faea6a7b0e858ee55d22318b3fc5898e
parent af890a67
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
@@ -34,6 +34,11 @@ public class BindToFinalObservableFieldTest extends BaseDataBinderTest<BindToFin
        mBinder.rebindDirty();
        final TextView textView = (TextView) mBinder.getRoot().findViewById(R.id.text_view);
        assertEquals(getActivity().getResources().getString(R.string.app_name), textView.getText().toString());
        vo.myFinalVo.setVal(R.string.rain);
        mBinder.rebindDirty();
        assertEquals("The field should be observed and its notify event should've invalidated"
                        + " binder flags.", getActivity().getResources().getString(R.string.rain),
                textView.getText().toString());
    }


+1 −0
Original line number Diff line number Diff line
@@ -13,4 +13,5 @@

<resources>
    <string name="app_name">TestApp</string>
    <string name="rain">Rain</string>
</resources>
+2 −2
Original line number Diff line number Diff line
@@ -149,7 +149,6 @@ public class ClassAnalyzer {
            try {
                Method method = klass.getMethod(methodName);
                Field backingField = findField(klass, name);

                if (Modifier.isPublic(method.getModifiers())) {
                    return new Callable(Callable.Type.METHOD, methodName, method.getReturnType(),
                            true, isBindable(method) || (backingField != null && isBindable(backingField)) );
@@ -176,7 +175,8 @@ public class ClassAnalyzer {
            Field field = klass.getField(name);
            if (Modifier.isPublic(field.getModifiers())) {
                return new Callable(Callable.Type.FIELD, name, field.getType(),
                        !Modifier.isFinal(field.getModifiers()), isBindable(field));
                        !Modifier.isFinal(field.getModifiers())
                        || isObservable(field.getType()), isBindable(field));
            }
        } catch (Throwable t) {