Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,24 @@ public void testAppendTwoElements() {
assertThat(result).asList().containsExactly("foo", "bar", "baz").inOrder();
}

public void testPrependIncompatibleType_throwsArrayStoreException() {
try {
Object[] unused = ObjectArrays.concat(0, new String[] {"foo"});
fail("Expected ArrayStoreException");
} catch (ArrayStoreException expected) {
// Expected behavior: cannot store Integer in String[]
}
}

public void testAppendIncompatibleType_throwsArrayStoreException() {
try {
Object[] unused = ObjectArrays.concat(new String[] {"foo"}, 0);
fail("Expected ArrayStoreException");
} catch (ArrayStoreException expected) {
// Expected behavior: cannot store Integer in String[]
}
}

public void testEmptyArrayToEmpty() {
doTestNewArrayEquals(new Object[0], 0);
}
Expand Down
4 changes: 4 additions & 0 deletions android/guava/src/com/google/common/collect/ObjectArrays.java
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@ private ObjectArrays() {}
* @param array the array of elements to append
* @return an array whose size is one larger than {@code array}, with {@code element} occupying
* the first position, and the elements of {@code array} occupying the remaining elements.
* @throws ArrayStoreException if {@code element} is not of a runtime type that can be stored in
* an array of type {@code T[]}
*/
public static <T extends @Nullable Object> T[] concat(@ParametricNullness T element, T[] array) {
T[] result = newArray(array, array.length + 1);
Expand All @@ -100,6 +102,8 @@ private ObjectArrays() {}
* @param element the element to append to the end
* @return an array whose size is one larger than {@code array}, with the same contents as {@code
* array}, plus {@code element} occupying the last position.
* @throws ArrayStoreException if {@code element} is not of a runtime type that can be stored in
* an array of type {@code T[]}
*/
public static <T extends @Nullable Object> T[] concat(T[] array, @ParametricNullness T element) {
T[] result = Arrays.copyOf(array, array.length + 1);
Expand Down
18 changes: 18 additions & 0 deletions guava-tests/test/com/google/common/collect/ObjectArraysTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,24 @@ public void testAppendTwoElements() {
assertThat(result).asList().containsExactly("foo", "bar", "baz").inOrder();
}

public void testPrependIncompatibleType_throwsArrayStoreException() {
try {
Object[] unused = ObjectArrays.concat(0, new String[] {"foo"});
fail("Expected ArrayStoreException");
} catch (ArrayStoreException expected) {
// Expected behavior: cannot store Integer in String[]
}
}

public void testAppendIncompatibleType_throwsArrayStoreException() {
try {
Object[] unused = ObjectArrays.concat(new String[] {"foo"}, 0);
fail("Expected ArrayStoreException");
} catch (ArrayStoreException expected) {
// Expected behavior: cannot store Integer in String[]
}
}

public void testEmptyArrayToEmpty() {
doTestNewArrayEquals(new Object[0], 0);
}
Expand Down
4 changes: 4 additions & 0 deletions guava/src/com/google/common/collect/ObjectArrays.java
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@ private ObjectArrays() {}
* @param array the array of elements to append
* @return an array whose size is one larger than {@code array}, with {@code element} occupying
* the first position, and the elements of {@code array} occupying the remaining elements.
* @throws ArrayStoreException if {@code element} is not of a runtime type that can be stored in
* an array of type {@code T[]}
*/
public static <T extends @Nullable Object> T[] concat(@ParametricNullness T element, T[] array) {
T[] result = newArray(array, array.length + 1);
Expand All @@ -100,6 +102,8 @@ private ObjectArrays() {}
* @param element the element to append to the end
* @return an array whose size is one larger than {@code array}, with the same contents as {@code
* array}, plus {@code element} occupying the last position.
* @throws ArrayStoreException if {@code element} is not of a runtime type that can be stored in
* an array of type {@code T[]}
*/
public static <T extends @Nullable Object> T[] concat(T[] array, @ParametricNullness T element) {
T[] result = Arrays.copyOf(array, array.length + 1);
Expand Down