This commit is contained in:
Looly
2022-06-06 01:27:16 +08:00
parent bd7d088178
commit 1c6bdf67e0
3 changed files with 15 additions and 0 deletions

View File

@@ -347,6 +347,13 @@ public class ArrayUtil extends PrimitiveArrayUtil {
Array.set(buffer, index, value);
return buffer;
} else {
if(ArrayUtil.isEmpty(buffer)){
// issue#I5APJE
// 可变长类型在buffer为空的情况下类型会被擦除导致报错此处修正
final T[] values = newArray(value.getClass(), 1);
values[0] = value;
return append(buffer, values);
}
return append(buffer, value);
}
}

View File

@@ -527,4 +527,11 @@ public class ArrayUtilTest {
result = ArrayUtil.replace(g, 0, h);
Assert.assertArrayEquals(g, result);
}
@Test
public void setOrAppendTest(){
String[] arr = new String[0];
String[] newArr = ArrayUtil.setOrAppend(arr, 0, "Good");// ClassCastException
Assert.assertArrayEquals(new String[]{"Good"}, newArr);
}
}