diff --git a/java/core/src/main/java/com/google/protobuf/ProtobufArrayList.java b/java/core/src/main/java/com/google/protobuf/ProtobufArrayList.java index c990e0fa89..9ecfb3dba7 100644 --- a/java/core/src/main/java/com/google/protobuf/ProtobufArrayList.java +++ b/java/core/src/main/java/com/google/protobuf/ProtobufArrayList.java @@ -9,13 +9,16 @@ package com.google.protobuf; import static java.lang.Math.max; -import com.google.protobuf.Internal.ProtobufList; +import java.io.Serializable; +import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.RandomAccess; /** Implements {@link ProtobufList} for non-primitive and {@link String} types. */ -final class ProtobufArrayList extends AbstractProtobufList implements RandomAccess { +final class ProtobufArrayList extends AbstractProtobufList + implements RandomAccess +{ private static final Object[] EMPTY_ARRAY = new Object[0]; @@ -110,20 +113,6 @@ final class ProtobufArrayList extends AbstractProtobufList implements Rand if (o == this) { return true; } - if (o instanceof ProtobufArrayList) { - ProtobufArrayList otherArray = (ProtobufArrayList) o; - int size = size(); - if (size != otherArray.size()) { - return false; - } - for (int i = 0; i < size; i++) { - // ProtobufArrayLists never contain nulls, so don't need to check array[i] == null. - if (!array[i].equals(otherArray.array[i])) { - return false; - } - } - return true; - } if (!(o instanceof List)) { return false; } @@ -135,11 +124,22 @@ final class ProtobufArrayList extends AbstractProtobufList implements Rand } List other = (List) o; - int size = size(); + final int size = size(); if (size != other.size()) { return false; } + if (o instanceof ProtobufArrayList) { + ProtobufArrayList otherArray = (ProtobufArrayList) o; + for (int i = 0; i < size; i++) { + // ProtobufArrayLists never contain nulls, so don't need to check array[i] == null. + if (!array[i].equals(otherArray.array[i])) { + return false; + } + } + return true; + } + for (int i = 0; i < size; i++) { // ProtobufArrayLists never contain nulls, so don't need to check array[i] == null. if (!array[i].equals(other.get(i))) { @@ -151,7 +151,7 @@ final class ProtobufArrayList extends AbstractProtobufList implements Rand @Override public int hashCode() { - int size = size(); + final int size = size(); int hashCode = 1; for (int i = 0; i < size; i++) { hashCode = (31 * hashCode) + array[i].hashCode(); diff --git a/java/core/src/test/java/com/google/protobuf/ProtobufArrayListTest.java b/java/core/src/test/java/com/google/protobuf/ProtobufArrayListTest.java index 9d43f4f906..8149d65ce5 100644 --- a/java/core/src/test/java/com/google/protobuf/ProtobufArrayListTest.java +++ b/java/core/src/test/java/com/google/protobuf/ProtobufArrayListTest.java @@ -7,8 +7,14 @@ package com.google.protobuf; +import static com.google.common.truth.Truth.assertThat; import static java.util.Arrays.asList; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.ObjectInputStream; +import java.io.ObjectOutputStream; +import java.util.ArrayList; import java.util.Collections; import java.util.ConcurrentModificationException; import java.util.Iterator;