mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-07-21 15:09:48 +08:00
fix bug
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
|
@@ -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);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user