fix convert to int bug

This commit is contained in:
Looly 2022-06-16 12:49:55 +08:00
parent 64e11c9de8
commit ea4bc023af
4 changed files with 15 additions and 1 deletions

View File

@ -14,6 +14,7 @@
### 🐞Bug修复
* 【extra 】 修复createExtractor中抛出异常后流未关闭问题pr#2384@Github
* 【core 】 修复CsvData.getHeader没有判空导致空指针问题issue#I5CK7Q@Gitee
* 【core 】 修复单字母转换为数字的问题issue#I5C4K1@Gitee
-------------------------------------------------------------------------------------------------------------

View File

@ -68,7 +68,7 @@ public class NumberConverter extends AbstractConverter<Number> {
@Override
protected String convertToStr(Object value) {
String result = StrUtil.trim(super.convertToStr(value));
if (StrUtil.isNotEmpty(result)) {
if (null != result && result.length() > 1) {
final char c = Character.toUpperCase(result.charAt(result.length() - 1));
if (c == 'D' || c == 'L' || c == 'F') {
// 类型标识形式例如123.6D

View File

@ -217,4 +217,11 @@ public class MapUtilTest {
Assert.assertEquals(Integer.valueOf(1), map.get("a"));
Assert.assertEquals(Integer.valueOf(2), map.get("b"));
}
@Test(expected = NumberFormatException.class)
public void getIntTest(){
final HashMap<String, String> map = MapUtil.of("age", "d");
final Integer age = MapUtil.getInt(map, "age");
Assert.assertNotNull(age);
}
}

View File

@ -287,6 +287,12 @@ public class NumberUtilTest {
Assert.assertEquals(1482, v1);
}
@Test(expected = NumberFormatException.class)
public void parseIntTest3() {
int v1 = NumberUtil.parseInt("d");
Assert.assertEquals(0, v1);
}
@Test
public void parseNumberTest() {
// from 5.4.8 issue#I23ORQ@Gitee