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

@ -12,6 +12,7 @@
* 【core 】 修复NumberUtil.isXXX空判断错误issue#2356@Github
* 【core 】 修复Convert.toSBC空指针问题issue#I5APKK@Gitee
* 【json 】 修复Bean中存在bytes无法转换问题issue#2365@Github
* 【core 】 ArrayUtil.setOrAppend()传入空数组时抛出异常issue#I5APJE@Gitee
-------------------------------------------------------------------------------------------------------------

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);
}
}