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

Commit c6077ed2 authored by Matthew Zavislak's avatar Matthew Zavislak Committed by Jonathan Klee
Browse files

Allow synthetic field(s) in ObjectWrapper

- Ignore the field(s) that JaCoCo instrumentation (or other parts of the build chain) may add.
  For example, JaCoCo adds:
  private static transient boolean[] com.google.android.gms.dynamic.ObjectWrapper.$jacocoData
parent 5faa1127
Loading
Loading
Loading
Loading
+28 −3
Original line number Diff line number Diff line
@@ -34,15 +34,40 @@ public class ObjectWrapper<T> extends IObjectWrapper.Stub {
        if (obj == null) {
            return null;
        }

        if (obj instanceof ObjectWrapper) {
            return ((ObjectWrapper) obj).t;
        }

        IBinder binder = obj.asBinder();
        Field[] fields = binder.getClass().getDeclaredFields();
        if (fields.length != 1) {
            throw new IllegalArgumentException();

        if (fields.length < 1) {
            throw new IllegalArgumentException("No fields were found");
        }

        // Ignore synthetic field(s) from JaCoCo or elsewhere
        // https://www.jacoco.org/jacoco/trunk/doc/faq.html

        @Nullable
        Field field = null;

        for (Field currentField : fields) {
            if (currentField.isSynthetic()) {
                continue;
            }

            if (field == null) {
                field = currentField;
            } else {
                throw new IllegalArgumentException("Too many non-synthetic fields were found");
            }
        Field field = fields[0];
        }

        if (field == null) {
            throw new IllegalArgumentException("No non-synthetic fields were found");
        }

        if (!field.isAccessible()) {
            field.setAccessible(true);
            try {