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

Commit 523dd318 authored by Jeff Sharkey's avatar Jeff Sharkey Committed by Automerger Merge Worker
Browse files

Merge "Deep copy arguments to avoid accidental mutation." into rvc-dev am:...

Merge "Deep copy arguments to avoid accidental mutation." into rvc-dev am: 4af9a76e am: 55978c3e

Change-Id: If0caf9d7f2f6b6be83ad1214a4efe64e07a1635d
parents 006ad5f6 55978c3e
Loading
Loading
Loading
Loading
+29 −0
Original line number Diff line number Diff line
@@ -43,6 +43,7 @@ import com.android.internal.util.ArrayUtils;
import java.io.FileNotFoundException;
import java.io.PrintStream;
import java.text.Collator;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Locale;
import java.util.Map;
@@ -307,6 +308,34 @@ public class DatabaseUtils {
        return res.toString();
    }

    /**
     * Make a deep copy of the given argument list, ensuring that the returned
     * value is completely isolated from any changes to the original arguments.
     *
     * @hide
     */
    public static @Nullable Object[] deepCopyOf(@Nullable Object[] args) {
        if (args == null) return null;

        final Object[] res = new Object[args.length];
        for (int i = 0; i < args.length; i++) {
            final Object arg = args[i];

            if ((arg == null) || (arg instanceof Number) || (arg instanceof String)) {
                // When the argument is immutable, we can copy by reference
                res[i] = arg;
            } else if (arg instanceof byte[]) {
                // Need to deep copy blobs
                final byte[] castArg = (byte[]) arg;
                res[i] = Arrays.copyOf(castArg, castArg.length);
            } else {
                // Convert everything else to string, making it immutable
                res[i] = String.valueOf(arg);
            }
        }
        return res;
    }

    /**
     * Returns data type of the given object's value.
     *<p>
+4 −0
Original line number Diff line number Diff line
@@ -1066,6 +1066,10 @@ public final class SQLiteDatabase extends SQLiteClosable {
            throws SQLException {
        Objects.requireNonNull(sql);

        // Copy arguments to ensure that the caller doesn't accidentally change
        // the values used by future connections
        bindArgs = DatabaseUtils.deepCopyOf(bindArgs);

        synchronized (mLock) {
            throwIfNotOpenLocked();